xonecas.io
64875
Mc

mini-coder / commit f8e150e

Merge pull request #6 from software-trizzey/feature/add-support-for-vim-quit-command

Add support for :q quit command

xonecas2026-04-09 f8e150e606e18d3bbf77bf4e3a4e747322da9a2c parent 907e679parent d022466

4 files changed

README.md+2−0
@@ -83,6 +83,8 @@ Plugins can add more tools, but the core stays intentionally small.
8383 | `Tab` | File path autocomplete (or command filter on `/`) |
8484 | `Ctrl+R` | Search global raw input history |
8585 | `Ctrl+C` | Graceful exit |
86+| `Ctrl+D` | Graceful exit (EOF, when input is empty) |
87+| `:q` | Graceful exit |
8688
8789 ## Headless one-shot mode
8890
spec.md+1−0
@@ -718,6 +718,7 @@ add tests for undo_
718718 | `Ctrl+R` | Input focused | Search global raw input history |
719719 | `Ctrl+C` | Any | Graceful exit |
720720 | `Ctrl+D` | Input empty | Graceful exit (EOF) |
721+| `:q` | Input focused | Graceful exit |
721722 | `Ctrl+Z` | Any | Suspend/background process |
722723 | Mouse wheel | Log area | Scroll conversation history |
723724
src/ui.test.ts+33−0
@@ -36,6 +36,8 @@ import {
3636 createInputController,
3737 handleInput,
3838 type InputController,
39+ isQuitInput,
40+ isQuitKey,
3941 renderActiveOverlay,
4042 renderBaseLayout,
4143 renderInputArea,
@@ -229,6 +231,37 @@ describe("ui rendering", () => {
229231 expect(DEFAULT_VERBOSE).toBe(false);
230232 });
231233
234+ test("isQuitInput matches :q with surrounding whitespace", () => {
235+ expect(isQuitInput(":q")).toBe(true);
236+ expect(isQuitInput(" :q")).toBe(true);
237+ expect(isQuitInput(":q ")).toBe(true);
238+ expect(isQuitInput(" :q ")).toBe(true);
239+ });
240+
241+ test("isQuitInput does not match other inputs", () => {
242+ expect(isQuitInput("")).toBe(false);
243+ expect(isQuitInput("q")).toBe(false);
244+ expect(isQuitInput(":q!")).toBe(false);
245+ expect(isQuitInput(":quit")).toBe(false);
246+ expect(isQuitInput(":q and something")).toBe(false);
247+ });
248+
249+ test("isQuitKey matches always-on quit keys", () => {
250+ expect(isQuitKey("ctrl+c", "")).toBe(true);
251+ expect(isQuitKey("ctrl+c", "draft text")).toBe(true);
252+ });
253+
254+ test("isQuitKey matches empty-input quit keys only when input is empty", () => {
255+ expect(isQuitKey("ctrl+d", "")).toBe(true);
256+ expect(isQuitKey("ctrl+d", " ")).toBe(false);
257+ expect(isQuitKey("ctrl+d", "draft text")).toBe(false);
258+ });
259+
260+ test("isQuitKey ignores non-quit keys", () => {
261+ expect(isQuitKey("enter", "")).toBe(false);
262+ expect(isQuitKey("escape", "")).toBe(false);
263+ });
264+
232265 test("committing a streamed response preserves hidden reasoning placeholder order", async () => {
233266 const api = "ui-hidden-reasoning-order-test";
234267 const sourceId = "ui-hidden-reasoning-order-test-source";
src/ui.ts+46−6
@@ -57,6 +57,20 @@ const PULSE_WIDTH = 5;
5757 /** Maximum number of committed messages rendered before older history is chunked. */
5858 const CONVERSATION_CHUNK_MESSAGES = 50;
5959
60+/** Centralized interactive quit rules for keypresses and submitted input. */
61+const QUIT_RULES: Readonly<{
62+ /** Submitted raw inputs that trigger graceful quit. */
63+ inputs: ReadonlySet<string>;
64+ /** Keypresses that always trigger graceful quit. */
65+ keysAlways: ReadonlySet<string>;
66+ /** Keypresses that trigger graceful quit only when input is empty. */
67+ keysWhenEmptyInput: ReadonlySet<string>;
68+}> = {
69+ inputs: new Set([":q"]),
70+ keysAlways: new Set(["ctrl+c"]),
71+ keysWhenEmptyInput: new Set(["ctrl+d"]),
72+};
73+
6074 // ---------------------------------------------------------------------------
6175 // UI state (module-scoped, not in AppState)
6276 // ---------------------------------------------------------------------------
@@ -92,6 +106,23 @@ let stdinWasRaw = false;
92106 /** Active overlay for interactive commands (/model, /effort, etc.). */
93107 let activeOverlay: ActiveOverlay | null = null;
94108
109+/** Determine whether a raw input line should trigger a graceful quit. */
110+export function isQuitInput(raw: string): boolean {
111+ const trimmed = raw.trim();
112+ return QUIT_RULES.inputs.has(trimmed);
113+}
114+
115+/** Determine whether a keypress should trigger a graceful quit. */
116+export function isQuitKey(key: string, input: string): boolean {
117+ if (QUIT_RULES.keysAlways.has(key)) {
118+ return true;
119+ }
120+ if (input === "" && QUIT_RULES.keysWhenEmptyInput.has(key)) {
121+ return true;
122+ }
123+ return false;
124+}
125+
95126 /**
96127 * Reset all module-scoped UI state.
97128 *
@@ -299,6 +330,14 @@ export function createInputController(state: AppState): InputController {
299330 onKeyPress: (key) => {
300331 if (key === "enter") {
301332 const raw = inputValue;
333+
334+ if (isQuitInput(raw)) {
335+ inputValue = "";
336+ cel.render();
337+ requestGracefulExit(state);
338+ return false;
339+ }
340+
302341 inputValue = "";
303342 cel.render();
304343 handleInput(raw, state);
@@ -418,6 +457,11 @@ async function gracefulExit(state: AppState): Promise<void> {
418457 process.exit(0);
419458 }
420459
460+/** Request a graceful exit and hard-fail if shutdown errors. */
461+function requestGracefulExit(state: AppState): void {
462+ gracefulExit(state).catch(() => process.exit(1));
463+}
464+
421465 /** Restore the terminal to the shell before suspending. */
422466 function suspendTerminalUi(): void {
423467 stopDividerAnimation();
@@ -539,12 +583,8 @@ export function renderBaseLayout(
539583 commandController.showInputHistoryOverlay(state);
540584 return;
541585 }
542- if (key === "ctrl+c") {
543- gracefulExit(state).catch(() => process.exit(1));
544- return;
545- }
546- if (key === "ctrl+d" && inputValue === "") {
547- gracefulExit(state).catch(() => process.exit(1));
586+ if (isQuitKey(key, inputValue)) {
587+ requestGracefulExit(state);
548588 return;
549589 }
550590 if (key === "ctrl+z") {