fix(tui): submit prompts with Kitty keypad Enter

This commit is contained in:
dajiaohuang authored and chengyongru committed 2026-10-23 14:14:10 +08:00
1 parent d045285ced
commit c20a0dad70
2 files changed
+33

No files matched your search

+29
View File
@@ -52,6 +52,35 @@ describe("NanobotTui composer", () => {
expect(composer.plainText).toBe("next")
})
test("submits with keypad Enter and keeps its modified forms as newlines", async () => {
const sent: string[] = []
setup = await createRenderer({
width: 72,
height: 20,
screenMode: "alternate-screen",
kittyKeyboard: true,
})
const app = mount(setup, sent)
app.accept({ event: "attached", chat_id: "chat" })
await waitUntil(() => (app as unknown as { ready: boolean }).ready)
const composer = (app as unknown as { composer: TextareaRenderable }).composer
await setup.mockInput.typeText("11111")
await setup.mockInput.pressKeys(["\u001b[57414u"])
await waitUntil(() => sent.length === 1)
expect(sent).toEqual(["11111"])
app.accept({ event: "turn_end", chat_id: "chat" })
for (const modifier of [2, 3, 5]) {
composer.setText("first")
composer.cursorOffset = 5
await setup.mockInput.pressKeys([`\u001b[57414;${modifier}u`])
await setup.mockInput.typeText("second")
expect(composer.plainText).toBe("first\nsecond")
expect(sent).toEqual(["11111"])
}
})
test("inserts newlines with Shift+Enter and the universal Ctrl+J fallback", async () => {
const sent: string[] = []
setup = await createRenderer({
+4
View File
@@ -138,9 +138,13 @@ export function createAppLayout(
{ name: "return", shift: true, action: "newline" },
{ name: "return", meta: true, action: "newline" },
{ name: "return", ctrl: true, action: "newline" },
{ name: "kpenter", shift: true, action: "newline" },
{ name: "kpenter", meta: true, action: "newline" },
{ name: "kpenter", ctrl: true, action: "newline" },
{ name: "j", ctrl: true, action: "newline" },
{ name: "linefeed", action: "newline" },
{ name: "return", action: "submit" },
{ name: "kpenter", action: "submit" },
],
onCursorChange: handlers.onComposerCursorChange,
onContentChange: handlers.onComposerContentChange,