Skip to content

Commit 80eeaab

Browse files
committed
feat(inquirerer): add readline-style keybindings and multiline input support
- Add comprehensive KEY_CODES for readline-style editing (Ctrl+A/E, Alt+B/F, Ctrl+W/K/U, Home/End) - Implement prompt history navigation (UP/DOWN arrows) - Support multiline input (Shift+Enter for newline, Enter to submit) - Move message scrolling to PageUp/PageDown - Add extensible keybinding system with addBinding/removeBinding methods - Update LineEditorState to support multiple lines - Add kill ring for Ctrl+K/U operations - Show history position in status bar
1 parent 754ec24 commit 80eeaab

2 files changed

Lines changed: 410 additions & 114 deletions

File tree

packages/inquirerer/src/keypress.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,68 @@ const defaultProcessWrapper: ProcessWrapper = {
1111
};
1212

1313
export const KEY_CODES = {
14+
// Arrow keys
1415
UP_ARROW: '\u001b[A',
1516
DOWN_ARROW: '\u001b[B',
1617
RIGHT_ARROW: '\u001b[C',
1718
LEFT_ARROW: '\u001b[D',
19+
20+
// Basic keys
1821
ENTER: '\r',
1922
SPACE: ' ',
20-
CTRL_C: '\u0003',
23+
TAB: '\t',
2124
BACKSPACE: '\x7f', // Commonly used BACKSPACE key in Unix-like systems
22-
BACKSPACE_LEGACY: '\x08' // For compatibility with some systems
25+
BACKSPACE_LEGACY: '\x08', // For compatibility with some systems
26+
DELETE: '\u001b[3~',
27+
28+
// Control keys
29+
CTRL_C: '\u0003',
30+
CTRL_D: '\u0004',
31+
CTRL_A: '\u0001', // Start of line
32+
CTRL_E: '\u0005', // End of line
33+
CTRL_K: '\u000b', // Kill to end of line
34+
CTRL_U: '\u0015', // Kill to start of line
35+
CTRL_W: '\u0017', // Delete previous word
36+
CTRL_L: '\u000c', // Clear screen
37+
CTRL_N: '\u000e', // Next (down)
38+
CTRL_P: '\u0010', // Previous (up)
39+
CTRL_F: '\u0006', // Forward (right)
40+
CTRL_B: '\u0002', // Back (left)
41+
42+
// Alt/Meta key combinations (escape sequences)
43+
// Note: Alt key sends ESC followed by the character
44+
ALT_B: '\u001bb', // Word back
45+
ALT_F: '\u001bf', // Word forward
46+
ALT_D: '\u001bd', // Delete word forward
47+
ALT_BACKSPACE: '\u001b\x7f', // Delete word backward
48+
49+
// Shift+Enter (varies by terminal, common sequences)
50+
SHIFT_ENTER: '\u001b[13;2u', // CSI u encoding
51+
SHIFT_ENTER_ALT: '\u001bOM', // Some terminals
52+
53+
// Home/End keys
54+
HOME: '\u001b[H',
55+
HOME_ALT: '\u001bOH',
56+
HOME_ALT2: '\u001b[1~',
57+
END: '\u001b[F',
58+
END_ALT: '\u001bOF',
59+
END_ALT2: '\u001b[4~',
60+
61+
// Page Up/Down
62+
PAGE_UP: '\u001b[5~',
63+
PAGE_DOWN: '\u001b[6~',
64+
65+
// Ctrl+Arrow (word navigation in some terminals)
66+
CTRL_LEFT: '\u001b[1;5D',
67+
CTRL_RIGHT: '\u001b[1;5C',
68+
CTRL_UP: '\u001b[1;5A',
69+
CTRL_DOWN: '\u001b[1;5B',
70+
71+
// Alt+Arrow (word navigation in some terminals)
72+
ALT_LEFT: '\u001b[1;3D',
73+
ALT_RIGHT: '\u001b[1;3C',
74+
ALT_UP: '\u001b[1;3A',
75+
ALT_DOWN: '\u001b[1;3B',
2376
};
2477

2578
/**

0 commit comments

Comments
 (0)