Files
Netcatty/domain/terminalCommandInjectionReady.ts
T
陈大猫 5a1352aab0 feat(sftp): insert file path or cd into paired terminal from SFTP context menu (#4323)
* feat(sftp): insert file path or cd into paired terminal from SFTP context menu

* fix(sftp): guard terminal path insertion against unclosed quote contexts

* fix(sftp): reject trailing dollar fusion and after-cursor command text

* fix(terminal): detect standard root-directory shell prompts (user@host:/$) for SFTP path injection

* fix(sftp): reject arithmetic insertion contexts and continuation-prompt cd

* fix(terminal): ignore right-aligned prompt decorations in after-cursor readiness check

* fix(sftp): resolve remote shell dialect from prompt/OS and use portable Unix quoting

* fix(terminal): require unwritten xterm gap cells before ignoring right-prompt decorations
2026-11-25 12:02:41 +08:00

34 lines
1.2 KiB
TypeScript

export interface ShellPromptReadiness {
sensitiveInputActive?: boolean;
hasLiveTerminal: boolean;
alternateScreenActive: boolean;
isAtPrompt: boolean;
userInputLength: number;
pendingTypedInputLength?: number;
afterCursorInputLength?: number;
}
/**
* Prompt is showing on the primary screen and is not a password/TUI.
* A typed draft is allowed; archive clicks insert at the cursor.
*/
export function isShellPromptReadyForInsertion(options: ShellPromptReadiness): boolean {
if (options.sensitiveInputActive) return false;
if (!options.hasLiveTerminal) return false;
if (options.alternateScreenActive) return false;
if (!options.isAtPrompt) return false;
return true;
}
/**
* Whether an automated PTY write (e.g. SFTP "open path in terminal") may run
* at a clean interactive shell prompt -- not mid-line, not in an editor/TUI.
*/
export function isIdleShellReadyForCommandInjection(options: ShellPromptReadiness): boolean {
if (!isShellPromptReadyForInsertion(options)) return false;
if (options.userInputLength > 0) return false;
if ((options.pendingTypedInputLength ?? 0) > 0) return false;
if ((options.afterCursorInputLength ?? 0) > 0) return false;
return true;
}