mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 23:01:32 +00:00
Update all selector/list components to use EditorKeybindingsManager: - model-selector, session-selector, oauth-selector, user-message-selector - hook-selector, hook-input, hook-editor, tree-selector - select-list, settings-list, cancellable-loader This allows users to configure selectUp, selectDown, selectConfirm, selectCancel actions in keybindings.json
40 lines
1,007 B
TypeScript
40 lines
1,007 B
TypeScript
import { getEditorKeybindings } from "../keybindings.js";
|
|
import { Loader } from "./loader.js";
|
|
|
|
/**
|
|
* Loader that can be cancelled with Escape.
|
|
* Extends Loader with an AbortSignal for cancelling async operations.
|
|
*
|
|
* @example
|
|
* const loader = new CancellableLoader(tui, cyan, dim, "Working...");
|
|
* loader.onAbort = () => done(null);
|
|
* doWork(loader.signal).then(done);
|
|
*/
|
|
export class CancellableLoader extends Loader {
|
|
private abortController = new AbortController();
|
|
|
|
/** Called when user presses Escape */
|
|
onAbort?: () => void;
|
|
|
|
/** AbortSignal that is aborted when user presses Escape */
|
|
get signal(): AbortSignal {
|
|
return this.abortController.signal;
|
|
}
|
|
|
|
/** Whether the loader was aborted */
|
|
get aborted(): boolean {
|
|
return this.abortController.signal.aborted;
|
|
}
|
|
|
|
handleInput(data: string): void {
|
|
const kb = getEditorKeybindings();
|
|
if (kb.matches(data, "selectCancel")) {
|
|
this.abortController.abort();
|
|
this.onAbort?.();
|
|
}
|
|
}
|
|
|
|
dispose(): void {
|
|
this.stop();
|
|
}
|
|
}
|