From d84c16fa9020b11fabd2e71a05e6f3abed16887b Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sun, 13 Sep 2026 14:47:11 +0200 Subject: feat(workstation): add pi --- user/pi/extensions/stash-on-escape.ts | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 user/pi/extensions/stash-on-escape.ts (limited to 'user/pi/extensions/stash-on-escape.ts') diff --git a/user/pi/extensions/stash-on-escape.ts b/user/pi/extensions/stash-on-escape.ts new file mode 100644 index 0000000..aa1cd06 --- /dev/null +++ b/user/pi/extensions/stash-on-escape.ts @@ -0,0 +1,46 @@ +// On Escape clear the editor and store the text in the history instead of doing nothing. +import { + CustomEditor, + type ExtensionAPI, + type ExtensionContext, + type KeybindingsManager, +} from "@earendil-works/pi-coding-agent"; +import type { EditorTheme, TUI } from "@earendil-works/pi-tui"; + +class StashOnEscapeEditor extends CustomEditor { + constructor( + tui: TUI, + theme: EditorTheme, + private readonly keys: KeybindingsManager, + private readonly ctx: ExtensionContext, + ) { + super(tui, theme, keys); + } + + handleInput(data: string): void { + const text = this.getExpandedText?.() ?? this.getText(); + + if ( + this.ctx.isIdle() && + text.trim() && + this.keys.matches(data, "app.interrupt") + ) { + this.addToHistory(text); + this.setText(""); + return; + } + + super.handleInput(data); + } +} + +export default function (pi: ExtensionAPI) { + pi.on("session_start", (_event, ctx) => { + if (ctx.mode !== "tui") return; + + ctx.ui.setEditorComponent( + (tui, theme, keybindings) => + new StashOnEscapeEditor(tui, theme, keybindings, ctx), + ); + }); +} -- cgit v1.3.1