From 9bd17e46bd0ac7583a09bb30a76c42a532c17bad Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Fri, 20 Mar 2026 12:48:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=98=BE=E7=A4=BA=20PowerShell=20?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E8=B7=AF=E5=BE=84=E5=88=B0=E7=BB=88=E7=AB=AF?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 11 +++++++++-- src/lib/utils.ts | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index dcf6828..a54b2bb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,6 +9,7 @@ import { } from './lib/terminalApi'; import { getDefaultTheme, type TerminalTheme } from './lib/terminalTheme'; import { type TerminalChunk } from './stores/useTerminalStore'; +import { extractPowerShellPromptPath } from './lib/utils'; const DEFAULT_CWD = '/workspace'; const DEFAULT_FONT_SIZE = 14; @@ -22,6 +23,7 @@ function TerminalPanel({ initialCwd, connectDelay = 0, autoFocus = false }: { in const [isConnected, setIsConnected] = useState(false); const [isConnecting, setIsConnecting] = useState(false); const [error, setError] = useState(null); + const [currentPath, setCurrentPath] = useState(initialCwd); const [sessionId, setSessionId] = useState(null); const sessionIdRef = useRef(null); @@ -102,7 +104,11 @@ function TerminalPanel({ initialCwd, connectDelay = 0, autoFocus = false }: { in setIsConnected(true); setIsConnecting(false); } else if (event.type === 'data' && event.data) { - const newChunk: TerminalChunk = { + const osc7Path = extractPowerShellPromptPath(event.data); + if (osc7Path) { + setCurrentPath(osc7Path); + } + const newChunk: TerminalChunk = { id: nextChunkIdRef.current++, data: event.data, }; @@ -151,7 +157,8 @@ function TerminalPanel({ initialCwd, connectDelay = 0, autoFocus = false }: { in return (
{/* Panel header */} -
+
+ {currentPath} {isConnected ? '●' : isConnecting ? '○' : '○'} diff --git a/src/lib/utils.ts b/src/lib/utils.ts index f0187d3..4df0f32 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -57,3 +57,17 @@ export function isMobileDeviceViaCSS(): boolean { return false; } + +const PS_PROMPT_REGEX = /\(([^)]+)\)\s*PS\s+([^\n>]+)>|PS\s+([^\n>]+)>/g; + +export function extractPowerShellPromptPath(data: string): string | null { + let lastMatch: RegExpMatchArray | null = null; + const regex = new RegExp(PS_PROMPT_REGEX); + let match; + while ((match = regex.exec(data)) !== null) { + lastMatch = match; + } + if (!lastMatch) return null; + const path = lastMatch[3] || lastMatch[2]; + return path.trim() || null; +}