mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-26 10:53:56 +00:00
* 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
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
export interface TerminalCommandInjectionReadyOptions {
|
|
/** Keep a typed draft. Sensitive prompts, alt-screen, and non-prompts still block. */
|
|
allowDraft?: boolean;
|
|
}
|
|
|
|
export interface TerminalPromptDraftContext {
|
|
promptText: string;
|
|
userInput: string;
|
|
pendingTypedInput: string;
|
|
}
|
|
|
|
const commandInjectionReadyReaders = new Map<
|
|
string,
|
|
(options?: TerminalCommandInjectionReadyOptions) => boolean
|
|
>();
|
|
|
|
const promptDraftReaders = new Map<
|
|
string,
|
|
() => TerminalPromptDraftContext | null
|
|
>();
|
|
|
|
export function registerTerminalCommandInjectionReadyReader(
|
|
sessionId: string,
|
|
reader: (options?: TerminalCommandInjectionReadyOptions) => boolean,
|
|
draftReader?: () => TerminalPromptDraftContext | null,
|
|
): () => void {
|
|
commandInjectionReadyReaders.set(sessionId, reader);
|
|
if (draftReader) {
|
|
promptDraftReaders.set(sessionId, draftReader);
|
|
} else {
|
|
promptDraftReaders.delete(sessionId);
|
|
}
|
|
return () => {
|
|
if (commandInjectionReadyReaders.get(sessionId) === reader) {
|
|
commandInjectionReadyReaders.delete(sessionId);
|
|
}
|
|
if (draftReader && promptDraftReaders.get(sessionId) === draftReader) {
|
|
promptDraftReaders.delete(sessionId);
|
|
}
|
|
};
|
|
}
|
|
|
|
/** True when the live terminal reports a shell prompt ready for injection. */
|
|
export function isTerminalReadyForCommandInjection(
|
|
sessionId: string,
|
|
options?: TerminalCommandInjectionReadyOptions,
|
|
): boolean {
|
|
return commandInjectionReadyReaders.get(sessionId)?.(options) === true;
|
|
}
|
|
|
|
/** Return the current prompt and draft text up to the cursor for a live terminal. */
|
|
export function getTerminalPromptDraftContext(
|
|
sessionId: string,
|
|
): TerminalPromptDraftContext | null {
|
|
return promptDraftReaders.get(sessionId)?.() ?? null;
|
|
}
|