Files
openidea/src/features/terminal/windowsPty.ts
T
l0ng-ai 4d6a21c695 fix(terminal): keep the active ConPTY prompt when a terminal resizes (#4324)
When a ConPTY terminal got narrower (for example, a split opened and then closed), xterm dropped the end of the active PowerShell prompt. PowerShell then echoed input at absolute columns without printing the prompt again, so it came back garbled. Local terminals and embedded Run consoles now turn on xterm's cursor-line reflow on Windows builds whose ConPTY needs it. Remote and non-Windows sessions are unchanged.

Closes #4155
2026-11-18 23:32:50 +08:00

27 lines
1.3 KiB
TypeScript

import type { ITerminalOptions, Terminal } from "@xterm/xterm";
import { usePlatform } from "@/platform/platformInfo";
import { useRemote } from "@/platform/remote";
export function windowsPtyOptions(): Pick<ITerminalOptions, "windowsPty" | "reflowCursorLine"> {
const { os, windowsBuildNumber } = usePlatform.getState();
// Remote PTYs must not inherit the desktop's Windows build or backend.
if (os !== "windows" || useRemote.getState().session) return { reflowCursorLine: false };
return {
windowsPty: { backend: "conpty", buildNumber: windowsBuildNumber ?? undefined },
// Modern ConPTY can leave the prompt untouched on resize and echo input with absolute cursor moves.
reflowCursorLine: windowsBuildNumber !== null && windowsBuildNumber >= 21376,
};
}
/** Restored terminals can be constructed before appInfo answers. */
export function watchWindowsPty(term: Terminal) {
const unsubscribe = usePlatform.subscribe((next, previous) => {
if (next.os !== previous.os || next.windowsBuildNumber !== previous.windowsBuildNumber) {
const { windowsPty, reflowCursorLine } = windowsPtyOptions();
term.options.windowsPty = windowsPty ?? {};
term.options.reflowCursorLine = reflowCursorLine;
}
});
return { dispose: unsubscribe };
}