The Open Framework for Building Agents
[cli] feat: enable emacs-style terminal navigation (#82)
Florentin / 珞辰056fa6a22212
diff --git a/packages/eve/src/cli/dev/tui/setup-selection-input.test.ts b/packages/eve/src/cli/dev/tui/setup-selection-input.test.tsindex f909803cd..772f7c508 100644--- a/packages/eve/src/cli/dev/tui/setup-selection-input.test.ts+++ b/packages/eve/src/cli/dev/tui/setup-selection-input.test.ts@@ -10,6 +10,8 @@ describe("setupSelectionIntent", () => {expect(setupSelectionIntent({ type: "ctrl-c" })).toEqual({ kind: "cancel" });expect(setupSelectionIntent({ type: "up" })).toEqual({ kind: "move", direction: "up" });expect(setupSelectionIntent({ type: "down" })).toEqual({ kind: "move", direction: "down" });+ expect(setupSelectionIntent({ type: "ctrl-p" })).toEqual({ kind: "move", direction: "up" });+ expect(setupSelectionIntent({ type: "ctrl-n" })).toEqual({ kind: "move", direction: "down" });expect(setupSelectionIntent({ type: "ctrl-r" })).toEqual({ kind: "repaint" });expect(setupSelectionIntent({ type: "enter" })).toEqual({ kind: "submit" });});diff --git a/packages/eve/src/cli/dev/tui/setup-selection-input.ts b/packages/eve/src/cli/dev/tui/setup-selection-input.tsindex e01877ba9..e0b7f1c55 100644--- a/packages/eve/src/cli/dev/tui/setup-selection-input.ts+++ b/packages/eve/src/cli/dev/tui/setup-selection-input.ts@@ -25,8 +25,10 @@ export function setupSelectionIntent(key: TerminalKey): SetupSelectionIntent | ucase "escape":return { kind: "cancel" };case "up":+ case "ctrl-p":return { kind: "move", direction: "up" };case "down":+ case "ctrl-n":return { kind: "move", direction: "down" };case "ctrl-r":return { kind: "repaint" };diff --git a/packages/eve/src/cli/dev/tui/stream-format.test.ts b/packages/eve/src/cli/dev/tui/stream-format.test.tsindex 91ab320e0..9722d4fd2 100644--- a/packages/eve/src/cli/dev/tui/stream-format.test.ts+++ b/packages/eve/src/cli/dev/tui/stream-format.test.ts@@ -156,6 +156,11 @@ describe("parseKey", () => {});expect(parseKey(Buffer.from("\r"))).toEqual({ type: "enter" });});++ it("decodes ctrl-n and ctrl-p for emacs-style navigation", () => {+ expect(parseKey(Buffer.from("\u000e"))).toEqual({ type: "ctrl-n" });+ expect(parseKey(Buffer.from("\u0010"))).toEqual({ type: "ctrl-p" });+ });});describe("stripPromptControlCharacters", () => {diff --git a/packages/eve/src/cli/dev/tui/stream-format.ts b/packages/eve/src/cli/dev/tui/stream-format.tsindex 1e5a71023..8853d180e 100644--- a/packages/eve/src/cli/dev/tui/stream-format.ts+++ b/packages/eve/src/cli/dev/tui/stream-format.ts@@ -29,6 +29,8 @@ export type TerminalKey =| { type: "ctrl-e" }| { type: "ctrl-d" }| { type: "ctrl-k" }+ | { type: "ctrl-n" }+ | { type: "ctrl-p" }| { type: "ctrl-u" }| { type: "ctrl-w" }| { type: "ctrl-l" }@@ -172,6 +174,10 @@ export function parseKey(chunk: Buffer): TerminalKey {return { type: "ctrl-d" };case "\u000b":return { type: "ctrl-k" };+ case "\u000e":+ return { type: "ctrl-n" };+ case "\u0010":+ return { type: "ctrl-p" };case "\u000c":return { type: "ctrl-l" };case "\u0012":diff --git a/packages/eve/src/cli/dev/tui/terminal-renderer.ts b/packages/eve/src/cli/dev/tui/terminal-renderer.tsindex 9c4edf5e9..9126f354f 100644--- a/packages/eve/src/cli/dev/tui/terminal-renderer.ts+++ b/packages/eve/src/cli/dev/tui/terminal-renderer.ts@@ -524,7 +524,8 @@ export class TerminalRenderer implements AgentTUIRenderer {return;}switch (key.type) {- case "up": {+ case "up":+ case "ctrl-p": {const open = suggestions();if (open !== undefined) {this.#typeahead = moveTypeaheadSelection(open, -1);@@ -538,7 +539,8 @@ export class TerminalRenderer implements AgentTUIRenderer {else recall(this.#promptHistory.previous(editor.text));break;}- case "down": {+ case "down":+ case "ctrl-n": {const open = suggestions();if (open !== undefined) {this.#typeahead = moveTypeaheadSelection(open, 1);@@ -853,6 +855,7 @@ export class TerminalRenderer implements AgentTUIRenderer {if (mode === "select") {switch (key.type) {case "up":+ case "ctrl-p":if (totalRows > 0) {cursorIndex = (cursorIndex - 1 + totalRows) % totalRows;renderSection();@@ -860,6 +863,7 @@ export class TerminalRenderer implements AgentTUIRenderer {}break;case "down":+ case "ctrl-n":if (totalRows > 0) {cursorIndex = (cursorIndex + 1) % totalRows;renderSection();diff --git a/packages/eve/src/cli/dev/tui/test/mock-terminal.ts b/packages/eve/src/cli/dev/tui/test/mock-terminal.tsindex 5720fe4a5..0bd14e1a9 100644--- a/packages/eve/src/cli/dev/tui/test/mock-terminal.ts+++ b/packages/eve/src/cli/dev/tui/test/mock-terminal.ts@@ -62,6 +62,14 @@ export class MockUserInput extends EventEmitter implements TerminalInput {ctrlC() {this.send("\u0003");}++ ctrlN() {+ this.send("\u000e");+ }++ ctrlP() {+ this.send("\u0010");+ }}export class MockScreen extends EventEmitter implements TerminalOutput {