Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
56 lines
2.2 KiB
TypeScript
56 lines
2.2 KiB
TypeScript
/**
|
|
* Compute the keystrokes to send so the terminal input line becomes exactly
|
|
* `candidate`, given what is currently on the line. Drives the popup
|
|
* autocomplete live-preview (#1005): moving the selection renders the chosen
|
|
* suggestion into the command line, and switching / reverting rewrites it.
|
|
*
|
|
* - Forward prefix (candidate continues the line): append only the new tail.
|
|
* - Otherwise: clear the current input, then write the full candidate. POSIX
|
|
* shells use Ctrl-U (kill-line); Windows (cmd/PowerShell) uses backspaces
|
|
* sized to the current line length.
|
|
*/
|
|
|
|
/**
|
|
* Live-preview rewrites inject Ctrl-U / backspaces into the PTY. Vendor
|
|
* bastion and network-device CLIs treat those bytes as session-kill, so
|
|
* network-device sessions keep the popup but skip the rewrite (#1193).
|
|
*/
|
|
export function shouldWriteAutocompleteLivePreview(
|
|
livePreviewEnabled: boolean,
|
|
isNetworkDevice = false,
|
|
): boolean {
|
|
return livePreviewEnabled && !isNetworkDevice;
|
|
}
|
|
|
|
export function isWindowsShellLineInput(
|
|
os: string,
|
|
promptText?: string | null,
|
|
): boolean {
|
|
if (os === "windows") return true;
|
|
// Hosts default to os:"linux" and the flag is easy to leave wrong. Windows
|
|
// shells do not kill the line on Ctrl-U; PSReadLine renders the raw byte
|
|
// literally (e.g. `tkn^Uuv run ...`), so every highlighted suggestion piles
|
|
// onto the command line (#3184). The detected prompt is authoritative when
|
|
// the flag disagrees: a drive-letter path with a backslash (`PS C:\Users>`,
|
|
// `C:\Windows>`) only occurs in a Windows shell prompt.
|
|
return typeof promptText === "string" && /(?:^|\s)[A-Za-z]:\\/.test(promptText);
|
|
}
|
|
|
|
export function computeLivePreviewWrite(input: {
|
|
currentLine: string;
|
|
candidate: string;
|
|
os: string;
|
|
/** Detected prompt text; lets a mislabeled host OS flag still clear the line (#3184). */
|
|
promptText?: string;
|
|
}): string {
|
|
const { currentLine, candidate, os } = input;
|
|
if (candidate === currentLine) return "";
|
|
if (candidate.startsWith(currentLine)) {
|
|
return candidate.slice(currentLine.length);
|
|
}
|
|
const clear = isWindowsShellLineInput(os, input.promptText)
|
|
? "\b".repeat(currentLine.length)
|
|
: "\x15";
|
|
return clear + candidate;
|
|
}
|