Context bar: match panes by live cwd via OSC 7 (was keyed on unset leaf.cwd)
The context indicator never showed because it matched on leaf.cwd, which is almost always undefined (newLeaf sets none; the shell picker never supplies one) — so the cwd<->transcript match never hit. Fix: report each WSL pane's real working directory. - pty.rs: inject PROMPT_COMMAND (forwarded via WSLENV) so the WSL shell emits OSC 7 (file://host/path) on every prompt. Default Ubuntu bash inherits an env-provided PROMPT_COMMAND; a shell that hard-assigns it, or a non-bash login shell, just won't report (indicator stays hidden, no breakage). - XtermPane: register an OSC 7 handler, decode the path, emit onCwd. - LeafPane: track liveCwd from onCwd and match the session on (liveCwd ?? leaf.cwd). OSC 7 fires at the bash prompt right before 'claude' launches, so liveCwd is exactly claude's launch cwd; it also follows 'cd'. tsc clean. Rust builds on the Windows host; needs runtime verification. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
24ab7f067f
commit
d776f962da
3 changed files with 56 additions and 1 deletions
|
|
@ -82,6 +82,10 @@ interface XtermPaneProps {
|
|||
* Defined as an optional callback so single-pane windows don't require
|
||||
* wiring it up. */
|
||||
onNavigate?: (intent: NavigateIntent) => void;
|
||||
/** Fired with the shell's reported working directory (from an OSC 7 escape,
|
||||
* which WSL panes emit via an injected PROMPT_COMMAND — see pty.rs). Used to
|
||||
* map the pane to the claude session running in it. */
|
||||
onCwd?: (cwd: string) => void;
|
||||
}
|
||||
|
||||
const DEFAULT_XTERM_FONT_SIZE = 13;
|
||||
|
|
@ -101,6 +105,7 @@ export default function XtermPane({
|
|||
focusTrigger = 0,
|
||||
fontSize,
|
||||
onNavigate,
|
||||
onCwd,
|
||||
}: XtermPaneProps) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const termRef = useRef<Terminal | null>(null);
|
||||
|
|
@ -121,6 +126,7 @@ export default function XtermPane({
|
|||
const onDataReceivedRef = useRef(onDataReceived);
|
||||
const onFocusRef = useRef(onFocus);
|
||||
const onNavigateRef = useRef(onNavigate);
|
||||
const onCwdRef = useRef(onCwd);
|
||||
// Stable ref for setSearchOpen so it can be called from inside the
|
||||
// attachCustomKeyEventHandler closure without the closure going stale.
|
||||
const setSearchOpenRef = useRef<(v: boolean) => void>(setSearchOpen);
|
||||
|
|
@ -131,6 +137,7 @@ export default function XtermPane({
|
|||
useEffect(() => { onDataReceivedRef.current = onDataReceived; }, [onDataReceived]);
|
||||
useEffect(() => { onFocusRef.current = onFocus; }, [onFocus]);
|
||||
useEffect(() => { onNavigateRef.current = onNavigate; }, [onNavigate]);
|
||||
useEffect(() => { onCwdRef.current = onCwd; }, [onCwd]);
|
||||
useEffect(() => { setSearchOpenRef.current = setSearchOpen; }, [setSearchOpen]);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
|
@ -204,6 +211,24 @@ export default function XtermPane({
|
|||
searchAddonRef.current = search;
|
||||
term.loadAddon(search);
|
||||
|
||||
// OSC 7 (cwd reporting): WSL panes emit `\e]7;file://<host><path>\e\\` on
|
||||
// every prompt (via the PROMPT_COMMAND we inject at spawn). Capture the
|
||||
// path and report it up so the pane can be matched to its claude session.
|
||||
// Registered before data flows so the first prompt's cwd is caught.
|
||||
term.parser.registerOscHandler(7, (data) => {
|
||||
const m = /^file:\/\/[^/]*(\/.*)$/.exec(data);
|
||||
if (m) {
|
||||
let path = m[1];
|
||||
try {
|
||||
path = decodeURIComponent(path);
|
||||
} catch {
|
||||
/* leave raw if it isn't valid percent-encoding */
|
||||
}
|
||||
onCwdRef.current?.(path);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// Initial size — fit before asking the PTY for its dimensions.
|
||||
fit.fit();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue