feat: rewrite stdin pipeline with input-parser, exitOnCtrlC via \x03

- Replace data event with readable + input-parser state machine
- Intercept \x03 in input pipeline (not process SIGINT)
- useInput now uses parse-keypress for semantic key mapping
- 20ms pending escape flush timer matching Ink
- Esc focus reset in input pipeline
- Delete old key-parser.ts (replaced by input-parser + parse-keypress)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yunfei He
2026-05-26 14:04:39 +08:00
parent 283444e87b
commit f51079a5ea
8 changed files with 229 additions and 164 deletions
@@ -1,5 +1,5 @@
import { defineComponent, shallowRef } from "vue";
import { expect, test } from "vite-plus/test";
import { expect, test, vi } from "vite-plus/test";
import { render } from "@vue-tui/testing";
import { Text, useInput, useStdout, type Key } from "@vue-tui/runtime";
@@ -363,3 +363,18 @@ test("useInput - handle page down", async () => {
await stdin.write("\x1b[6~");
expect(calls[0]?.key.pageDown).toBe(true);
});
// --- exitOnCtrlC ---
test("exitOnCtrlC intercepts \\x03 in raw mode", async () => {
const handler = vi.fn();
const App = defineComponent(() => {
useInput(handler);
return () => <Text>running</Text>;
});
const { stdin, waitUntilExit } = await render(App, { exitOnCtrlC: true });
await stdin.write("\x03");
// Should exit without calling user handler
expect(handler).not.toHaveBeenCalled();
await expect(waitUntilExit()).resolves.toBeUndefined();
});