@dungle-scrubs/tallow 0.8.21 → 0.8.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/dist/cli.js +35 -4
  2. package/dist/cli.js.map +1 -1
  3. package/dist/config.d.ts +1 -1
  4. package/dist/config.js +1 -1
  5. package/dist/interactive-mode-patch.d.ts +2 -0
  6. package/dist/interactive-mode-patch.d.ts.map +1 -1
  7. package/dist/interactive-mode-patch.js +82 -0
  8. package/dist/interactive-mode-patch.js.map +1 -1
  9. package/dist/sdk.d.ts +17 -0
  10. package/dist/sdk.d.ts.map +1 -1
  11. package/dist/sdk.js +68 -1
  12. package/dist/sdk.js.map +1 -1
  13. package/dist/workspace-transition-relay.d.ts +40 -7
  14. package/dist/workspace-transition-relay.d.ts.map +1 -1
  15. package/dist/workspace-transition-relay.js +81 -16
  16. package/dist/workspace-transition-relay.js.map +1 -1
  17. package/extensions/__integration__/background-task-widget-ownership.test.ts +216 -0
  18. package/extensions/__integration__/claude-hooks-compat.test.ts +156 -0
  19. package/extensions/__integration__/slash-command-bridge.test.ts +169 -23
  20. package/extensions/_shared/atomic-write.ts +1 -1
  21. package/extensions/_shared/bordered-box.ts +102 -0
  22. package/extensions/_shared/interop-events.ts +5 -0
  23. package/extensions/_shared/pid-registry.ts +1 -1
  24. package/extensions/agent-commands-tool/index.ts +4 -1
  25. package/extensions/background-task-tool/__tests__/lifecycle.test.ts +50 -25
  26. package/extensions/background-task-tool/index.ts +139 -221
  27. package/extensions/bash-tool-enhanced/index.ts +1 -75
  28. package/extensions/cd-tool/index.ts +2 -2
  29. package/extensions/context-fork/spawn.ts +4 -1
  30. package/extensions/health/index.ts +6 -6
  31. package/extensions/hooks/__tests__/claude-compat.test.ts +35 -0
  32. package/extensions/hooks/__tests__/subprocess-hardening.test.ts +73 -0
  33. package/extensions/hooks/index.ts +27 -4
  34. package/extensions/loop/__tests__/loop.test.ts +168 -4
  35. package/extensions/loop/extension.json +6 -5
  36. package/extensions/loop/index.ts +242 -31
  37. package/extensions/plan-mode-tool/__tests__/agent-end-execution.test.ts +373 -0
  38. package/extensions/plan-mode-tool/index.ts +103 -41
  39. package/extensions/prompt-suggestions/__tests__/editor-compatibility.test.ts +42 -0
  40. package/extensions/prompt-suggestions/index.ts +41 -6
  41. package/extensions/slash-command-bridge/__tests__/slash-command-bridge.test.ts +267 -671
  42. package/extensions/slash-command-bridge/extension.json +1 -1
  43. package/extensions/slash-command-bridge/index.ts +230 -116
  44. package/extensions/subagent-tool/index.ts +2 -2
  45. package/extensions/subagent-tool/process.ts +4 -5
  46. package/extensions/tasks/commands/register-tasks-extension.ts +41 -0
  47. package/extensions/teams-tool/__tests__/peer-messaging.test.ts +29 -24
  48. package/extensions/teams-tool/dashboard.ts +3 -5
  49. package/extensions/teams-tool/dispatch/auto-dispatch.ts +18 -1
  50. package/extensions/teams-tool/tools/teammate-tools.ts +9 -6
  51. package/extensions/wezterm-pane-control/__tests__/index.test.ts +88 -4
  52. package/extensions/wezterm-pane-control/index.ts +113 -8
  53. package/package.json +6 -4
  54. package/packages/tallow-tui/README.md +51 -0
  55. package/packages/tallow-tui/dist/autocomplete.d.ts +48 -0
  56. package/packages/tallow-tui/dist/autocomplete.d.ts.map +1 -0
  57. package/packages/tallow-tui/dist/autocomplete.js +564 -0
  58. package/packages/tallow-tui/dist/autocomplete.js.map +1 -0
  59. package/packages/tallow-tui/dist/border-styles.d.ts +32 -0
  60. package/packages/tallow-tui/dist/border-styles.d.ts.map +1 -0
  61. package/packages/tallow-tui/dist/border-styles.js +46 -0
  62. package/packages/tallow-tui/dist/border-styles.js.map +1 -0
  63. package/packages/tallow-tui/dist/components/bordered-box.d.ts +52 -0
  64. package/packages/tallow-tui/dist/components/bordered-box.d.ts.map +1 -0
  65. package/packages/tallow-tui/dist/components/bordered-box.js +89 -0
  66. package/packages/tallow-tui/dist/components/bordered-box.js.map +1 -0
  67. package/packages/tallow-tui/dist/components/box.d.ts +22 -0
  68. package/packages/tallow-tui/dist/components/box.d.ts.map +1 -0
  69. package/packages/tallow-tui/dist/components/box.js +104 -0
  70. package/packages/tallow-tui/dist/components/box.js.map +1 -0
  71. package/packages/tallow-tui/dist/components/cancellable-loader.d.ts +22 -0
  72. package/packages/tallow-tui/dist/components/cancellable-loader.d.ts.map +1 -0
  73. package/packages/tallow-tui/dist/components/cancellable-loader.js +35 -0
  74. package/packages/tallow-tui/dist/components/cancellable-loader.js.map +1 -0
  75. package/packages/tallow-tui/dist/components/editor.d.ts +240 -0
  76. package/packages/tallow-tui/dist/components/editor.d.ts.map +1 -0
  77. package/packages/tallow-tui/dist/components/editor.js +1766 -0
  78. package/packages/tallow-tui/dist/components/editor.js.map +1 -0
  79. package/packages/tallow-tui/dist/components/image.d.ts +126 -0
  80. package/packages/tallow-tui/dist/components/image.d.ts.map +1 -0
  81. package/packages/tallow-tui/dist/components/image.js +245 -0
  82. package/packages/tallow-tui/dist/components/image.js.map +1 -0
  83. package/packages/tallow-tui/dist/components/input.d.ts +37 -0
  84. package/packages/tallow-tui/dist/components/input.d.ts.map +1 -0
  85. package/packages/tallow-tui/dist/components/input.js +439 -0
  86. package/packages/tallow-tui/dist/components/input.js.map +1 -0
  87. package/packages/tallow-tui/dist/components/loader.d.ts +88 -0
  88. package/packages/tallow-tui/dist/components/loader.d.ts.map +1 -0
  89. package/packages/tallow-tui/dist/components/loader.js +146 -0
  90. package/packages/tallow-tui/dist/components/loader.js.map +1 -0
  91. package/packages/tallow-tui/dist/components/markdown.d.ts +95 -0
  92. package/packages/tallow-tui/dist/components/markdown.d.ts.map +1 -0
  93. package/packages/tallow-tui/dist/components/markdown.js +633 -0
  94. package/packages/tallow-tui/dist/components/markdown.js.map +1 -0
  95. package/packages/tallow-tui/dist/components/select-list.d.ts +32 -0
  96. package/packages/tallow-tui/dist/components/select-list.d.ts.map +1 -0
  97. package/packages/tallow-tui/dist/components/select-list.js +156 -0
  98. package/packages/tallow-tui/dist/components/select-list.js.map +1 -0
  99. package/packages/tallow-tui/dist/components/settings-list.d.ts +50 -0
  100. package/packages/tallow-tui/dist/components/settings-list.d.ts.map +1 -0
  101. package/packages/tallow-tui/dist/components/settings-list.js +189 -0
  102. package/packages/tallow-tui/dist/components/settings-list.js.map +1 -0
  103. package/packages/tallow-tui/dist/components/spacer.d.ts +12 -0
  104. package/packages/tallow-tui/dist/components/spacer.d.ts.map +1 -0
  105. package/packages/tallow-tui/dist/components/spacer.js +23 -0
  106. package/packages/tallow-tui/dist/components/spacer.js.map +1 -0
  107. package/packages/tallow-tui/dist/components/text.d.ts +19 -0
  108. package/packages/tallow-tui/dist/components/text.d.ts.map +1 -0
  109. package/packages/tallow-tui/dist/components/text.js +91 -0
  110. package/packages/tallow-tui/dist/components/text.js.map +1 -0
  111. package/packages/tallow-tui/dist/components/truncated-text.d.ts +13 -0
  112. package/packages/tallow-tui/dist/components/truncated-text.d.ts.map +1 -0
  113. package/packages/tallow-tui/dist/components/truncated-text.js +51 -0
  114. package/packages/tallow-tui/dist/components/truncated-text.js.map +1 -0
  115. package/packages/tallow-tui/dist/editor-component.d.ts +50 -0
  116. package/packages/tallow-tui/dist/editor-component.d.ts.map +1 -0
  117. package/packages/tallow-tui/dist/editor-component.js +2 -0
  118. package/packages/tallow-tui/dist/editor-component.js.map +1 -0
  119. package/packages/tallow-tui/dist/fuzzy.d.ts +16 -0
  120. package/packages/tallow-tui/dist/fuzzy.d.ts.map +1 -0
  121. package/packages/tallow-tui/dist/fuzzy.js +107 -0
  122. package/packages/tallow-tui/dist/fuzzy.js.map +1 -0
  123. package/packages/tallow-tui/dist/index.d.ts +25 -0
  124. package/packages/tallow-tui/dist/index.d.ts.map +1 -0
  125. package/packages/tallow-tui/dist/index.js +35 -0
  126. package/packages/tallow-tui/dist/index.js.map +1 -0
  127. package/packages/tallow-tui/dist/keybindings.d.ts +39 -0
  128. package/packages/tallow-tui/dist/keybindings.d.ts.map +1 -0
  129. package/packages/tallow-tui/dist/keybindings.js +114 -0
  130. package/packages/tallow-tui/dist/keybindings.js.map +1 -0
  131. package/packages/tallow-tui/dist/keys.d.ts +168 -0
  132. package/packages/tallow-tui/dist/keys.d.ts.map +1 -0
  133. package/packages/tallow-tui/dist/keys.js +971 -0
  134. package/packages/tallow-tui/dist/keys.js.map +1 -0
  135. package/packages/tallow-tui/dist/kill-ring.d.ts +28 -0
  136. package/packages/tallow-tui/dist/kill-ring.d.ts.map +1 -0
  137. package/packages/tallow-tui/dist/kill-ring.js +44 -0
  138. package/packages/tallow-tui/dist/kill-ring.js.map +1 -0
  139. package/packages/tallow-tui/dist/stdin-buffer.d.ts +48 -0
  140. package/packages/tallow-tui/dist/stdin-buffer.d.ts.map +1 -0
  141. package/packages/tallow-tui/dist/stdin-buffer.js +317 -0
  142. package/packages/tallow-tui/dist/stdin-buffer.js.map +1 -0
  143. package/packages/tallow-tui/dist/terminal-image.d.ts +161 -0
  144. package/packages/tallow-tui/dist/terminal-image.d.ts.map +1 -0
  145. package/packages/tallow-tui/dist/terminal-image.js +460 -0
  146. package/packages/tallow-tui/dist/terminal-image.js.map +1 -0
  147. package/packages/tallow-tui/dist/terminal.d.ts +102 -0
  148. package/packages/tallow-tui/dist/terminal.d.ts.map +1 -0
  149. package/packages/tallow-tui/dist/terminal.js +263 -0
  150. package/packages/tallow-tui/dist/terminal.js.map +1 -0
  151. package/packages/tallow-tui/dist/test-utils/capability-env.d.ts +14 -0
  152. package/packages/tallow-tui/dist/test-utils/capability-env.d.ts.map +1 -0
  153. package/packages/tallow-tui/dist/test-utils/capability-env.js +55 -0
  154. package/packages/tallow-tui/dist/test-utils/capability-env.js.map +1 -0
  155. package/packages/tallow-tui/dist/tui.d.ts +239 -0
  156. package/packages/tallow-tui/dist/tui.d.ts.map +1 -0
  157. package/packages/tallow-tui/dist/tui.js +1058 -0
  158. package/packages/tallow-tui/dist/tui.js.map +1 -0
  159. package/packages/tallow-tui/dist/undo-stack.d.ts +17 -0
  160. package/packages/tallow-tui/dist/undo-stack.d.ts.map +1 -0
  161. package/packages/tallow-tui/dist/undo-stack.js +25 -0
  162. package/packages/tallow-tui/dist/undo-stack.js.map +1 -0
  163. package/packages/tallow-tui/dist/utils.d.ts +96 -0
  164. package/packages/tallow-tui/dist/utils.d.ts.map +1 -0
  165. package/packages/tallow-tui/dist/utils.js +843 -0
  166. package/packages/tallow-tui/dist/utils.js.map +1 -0
  167. package/packages/tallow-tui/package.json +24 -0
  168. package/packages/tallow-tui/src/__tests__/__snapshots__/render.test.ts.snap +121 -0
  169. package/packages/tallow-tui/src/__tests__/editor-border.test.ts +72 -0
  170. package/packages/tallow-tui/src/__tests__/editor-change-listener.test.ts +121 -0
  171. package/packages/tallow-tui/src/__tests__/editor-ghost-text.test.ts +112 -0
  172. package/packages/tallow-tui/src/__tests__/fuzzy.test.ts +91 -0
  173. package/packages/tallow-tui/src/__tests__/image-component.test.ts +113 -0
  174. package/packages/tallow-tui/src/__tests__/keys.test.ts +141 -0
  175. package/packages/tallow-tui/src/__tests__/render.test.ts +179 -0
  176. package/packages/tallow-tui/src/__tests__/stdin-buffer.test.ts +82 -0
  177. package/packages/tallow-tui/src/__tests__/terminal-image.test.ts +363 -0
  178. package/packages/tallow-tui/src/__tests__/tui-diff-regression.test.ts +454 -0
  179. package/packages/tallow-tui/src/__tests__/tui-render-scheduling.test.ts +256 -0
  180. package/packages/tallow-tui/src/__tests__/utils.test.ts +259 -0
  181. package/packages/tallow-tui/src/autocomplete.ts +716 -0
  182. package/packages/tallow-tui/src/border-styles.ts +60 -0
  183. package/packages/tallow-tui/src/components/bordered-box.ts +113 -0
  184. package/packages/tallow-tui/src/components/box.ts +137 -0
  185. package/packages/tallow-tui/src/components/cancellable-loader.ts +40 -0
  186. package/packages/tallow-tui/src/components/editor.ts +2143 -0
  187. package/packages/tallow-tui/src/components/image.ts +315 -0
  188. package/packages/tallow-tui/src/components/input.ts +522 -0
  189. package/packages/tallow-tui/src/components/loader.ts +187 -0
  190. package/packages/tallow-tui/src/components/markdown.ts +780 -0
  191. package/packages/tallow-tui/src/components/select-list.ts +197 -0
  192. package/packages/tallow-tui/src/components/settings-list.ts +264 -0
  193. package/packages/tallow-tui/src/components/spacer.ts +28 -0
  194. package/packages/tallow-tui/src/components/text.ts +113 -0
  195. package/packages/tallow-tui/src/components/truncated-text.ts +65 -0
  196. package/packages/tallow-tui/src/editor-component.ts +92 -0
  197. package/packages/tallow-tui/src/fuzzy.ts +133 -0
  198. package/packages/tallow-tui/src/index.ts +118 -0
  199. package/packages/tallow-tui/src/keybindings.ts +183 -0
  200. package/packages/tallow-tui/src/keys.ts +1189 -0
  201. package/packages/tallow-tui/src/kill-ring.ts +46 -0
  202. package/packages/tallow-tui/src/stdin-buffer.ts +386 -0
  203. package/packages/tallow-tui/src/terminal-image.ts +619 -0
  204. package/packages/tallow-tui/src/terminal.ts +350 -0
  205. package/packages/tallow-tui/src/test-utils/capability-env.ts +56 -0
  206. package/packages/tallow-tui/src/tui.ts +1336 -0
  207. package/packages/tallow-tui/src/undo-stack.ts +28 -0
  208. package/packages/tallow-tui/src/utils.ts +948 -0
  209. package/packages/tallow-tui/tsconfig.build.json +21 -0
  210. package/runtime/agent-runner.ts +20 -0
  211. package/runtime/atomic-write.ts +8 -0
  212. package/runtime/otel.ts +12 -0
  213. package/runtime/resolve-module.ts +23 -0
  214. package/runtime/runtime-path-provider.ts +12 -0
  215. package/runtime/runtime-provenance.ts +17 -0
  216. package/runtime/workspace-transition-relay.ts +21 -0
  217. package/runtime/workspace-transition.ts +29 -0
@@ -0,0 +1,971 @@
1
+ /**
2
+ * Keyboard input handling for terminal applications.
3
+ *
4
+ * Supports both legacy terminal sequences and Kitty keyboard protocol.
5
+ * See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
6
+ * Reference: https://github.com/sst/opentui/blob/7da92b4088aebfe27b9f691c04163a48821e49fd/packages/core/src/lib/parse.keypress.ts
7
+ *
8
+ * Symbol keys are also supported, however some ctrl+symbol combos
9
+ * overlap with ASCII codes, e.g. ctrl+[ = ESC.
10
+ * See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#legacy-ctrl-mapping-of-ascii-keys
11
+ * Those can still be * used for ctrl+shift combos
12
+ *
13
+ * API:
14
+ * - matchesKey(data, keyId) - Check if input matches a key identifier
15
+ * - parseKey(data) - Parse input and return the key identifier
16
+ * - Key - Helper object for creating typed key identifiers
17
+ * - setKittyProtocolActive(active) - Set global Kitty protocol state
18
+ * - isKittyProtocolActive() - Query global Kitty protocol state
19
+ */
20
+ // =============================================================================
21
+ // Global Kitty Protocol State
22
+ // =============================================================================
23
+ let _kittyProtocolActive = false;
24
+ /**
25
+ * Set the global Kitty keyboard protocol state.
26
+ * Called by ProcessTerminal after detecting protocol support.
27
+ */
28
+ export function setKittyProtocolActive(active) {
29
+ _kittyProtocolActive = active;
30
+ }
31
+ /**
32
+ * Query whether Kitty keyboard protocol is currently active.
33
+ */
34
+ export function isKittyProtocolActive() {
35
+ return _kittyProtocolActive;
36
+ }
37
+ /**
38
+ * Helper object for creating typed key identifiers with autocomplete.
39
+ *
40
+ * Usage:
41
+ * - Key.escape, Key.enter, Key.tab, etc. for special keys
42
+ * - Key.backtick, Key.comma, Key.period, etc. for symbol keys
43
+ * - Key.ctrl("c"), Key.alt("x") for single modifier
44
+ * - Key.ctrlShift("p"), Key.ctrlAlt("x") for combined modifiers
45
+ */
46
+ export const Key = {
47
+ // Special keys
48
+ escape: "escape",
49
+ esc: "esc",
50
+ enter: "enter",
51
+ return: "return",
52
+ tab: "tab",
53
+ space: "space",
54
+ backspace: "backspace",
55
+ delete: "delete",
56
+ insert: "insert",
57
+ clear: "clear",
58
+ home: "home",
59
+ end: "end",
60
+ pageUp: "pageUp",
61
+ pageDown: "pageDown",
62
+ up: "up",
63
+ down: "down",
64
+ left: "left",
65
+ right: "right",
66
+ f1: "f1",
67
+ f2: "f2",
68
+ f3: "f3",
69
+ f4: "f4",
70
+ f5: "f5",
71
+ f6: "f6",
72
+ f7: "f7",
73
+ f8: "f8",
74
+ f9: "f9",
75
+ f10: "f10",
76
+ f11: "f11",
77
+ f12: "f12",
78
+ // Symbol keys
79
+ backtick: "`",
80
+ hyphen: "-",
81
+ equals: "=",
82
+ leftbracket: "[",
83
+ rightbracket: "]",
84
+ backslash: "\\",
85
+ semicolon: ";",
86
+ quote: "'",
87
+ comma: ",",
88
+ period: ".",
89
+ slash: "/",
90
+ exclamation: "!",
91
+ at: "@",
92
+ hash: "#",
93
+ dollar: "$",
94
+ percent: "%",
95
+ caret: "^",
96
+ ampersand: "&",
97
+ asterisk: "*",
98
+ leftparen: "(",
99
+ rightparen: ")",
100
+ underscore: "_",
101
+ plus: "+",
102
+ pipe: "|",
103
+ tilde: "~",
104
+ leftbrace: "{",
105
+ rightbrace: "}",
106
+ colon: ":",
107
+ lessthan: "<",
108
+ greaterthan: ">",
109
+ question: "?",
110
+ // Single modifiers
111
+ ctrl: (key) => `ctrl+${key}`,
112
+ shift: (key) => `shift+${key}`,
113
+ alt: (key) => `alt+${key}`,
114
+ // Combined modifiers
115
+ ctrlShift: (key) => `ctrl+shift+${key}`,
116
+ shiftCtrl: (key) => `shift+ctrl+${key}`,
117
+ ctrlAlt: (key) => `ctrl+alt+${key}`,
118
+ altCtrl: (key) => `alt+ctrl+${key}`,
119
+ shiftAlt: (key) => `shift+alt+${key}`,
120
+ altShift: (key) => `alt+shift+${key}`,
121
+ // Triple modifiers
122
+ ctrlShiftAlt: (key) => `ctrl+shift+alt+${key}`,
123
+ };
124
+ // =============================================================================
125
+ // Constants
126
+ // =============================================================================
127
+ const SYMBOL_KEYS = new Set([
128
+ "`",
129
+ "-",
130
+ "=",
131
+ "[",
132
+ "]",
133
+ "\\",
134
+ ";",
135
+ "'",
136
+ ",",
137
+ ".",
138
+ "/",
139
+ "!",
140
+ "@",
141
+ "#",
142
+ "$",
143
+ "%",
144
+ "^",
145
+ "&",
146
+ "*",
147
+ "(",
148
+ ")",
149
+ "_",
150
+ "+",
151
+ "|",
152
+ "~",
153
+ "{",
154
+ "}",
155
+ ":",
156
+ "<",
157
+ ">",
158
+ "?",
159
+ ]);
160
+ const MODIFIERS = {
161
+ shift: 1,
162
+ alt: 2,
163
+ ctrl: 4,
164
+ };
165
+ const LOCK_MASK = 64 + 128; // Caps Lock + Num Lock
166
+ const CODEPOINTS = {
167
+ escape: 27,
168
+ tab: 9,
169
+ enter: 13,
170
+ space: 32,
171
+ backspace: 127,
172
+ kpEnter: 57414, // Numpad Enter (Kitty protocol)
173
+ };
174
+ const ARROW_CODEPOINTS = {
175
+ up: -1,
176
+ down: -2,
177
+ right: -3,
178
+ left: -4,
179
+ };
180
+ const FUNCTIONAL_CODEPOINTS = {
181
+ delete: -10,
182
+ insert: -11,
183
+ pageUp: -12,
184
+ pageDown: -13,
185
+ home: -14,
186
+ end: -15,
187
+ };
188
+ const LEGACY_KEY_SEQUENCES = {
189
+ up: ["\x1b[A", "\x1bOA"],
190
+ down: ["\x1b[B", "\x1bOB"],
191
+ right: ["\x1b[C", "\x1bOC"],
192
+ left: ["\x1b[D", "\x1bOD"],
193
+ home: ["\x1b[H", "\x1bOH", "\x1b[1~", "\x1b[7~"],
194
+ end: ["\x1b[F", "\x1bOF", "\x1b[4~", "\x1b[8~"],
195
+ insert: ["\x1b[2~"],
196
+ delete: ["\x1b[3~"],
197
+ pageUp: ["\x1b[5~", "\x1b[[5~"],
198
+ pageDown: ["\x1b[6~", "\x1b[[6~"],
199
+ clear: ["\x1b[E", "\x1bOE"],
200
+ f1: ["\x1bOP", "\x1b[11~", "\x1b[[A"],
201
+ f2: ["\x1bOQ", "\x1b[12~", "\x1b[[B"],
202
+ f3: ["\x1bOR", "\x1b[13~", "\x1b[[C"],
203
+ f4: ["\x1bOS", "\x1b[14~", "\x1b[[D"],
204
+ f5: ["\x1b[15~", "\x1b[[E"],
205
+ f6: ["\x1b[17~"],
206
+ f7: ["\x1b[18~"],
207
+ f8: ["\x1b[19~"],
208
+ f9: ["\x1b[20~"],
209
+ f10: ["\x1b[21~"],
210
+ f11: ["\x1b[23~"],
211
+ f12: ["\x1b[24~"],
212
+ };
213
+ const LEGACY_SHIFT_SEQUENCES = {
214
+ up: ["\x1b[a"],
215
+ down: ["\x1b[b"],
216
+ right: ["\x1b[c"],
217
+ left: ["\x1b[d"],
218
+ clear: ["\x1b[e"],
219
+ insert: ["\x1b[2$"],
220
+ delete: ["\x1b[3$"],
221
+ pageUp: ["\x1b[5$"],
222
+ pageDown: ["\x1b[6$"],
223
+ home: ["\x1b[7$"],
224
+ end: ["\x1b[8$"],
225
+ };
226
+ const LEGACY_CTRL_SEQUENCES = {
227
+ up: ["\x1bOa"],
228
+ down: ["\x1bOb"],
229
+ right: ["\x1bOc"],
230
+ left: ["\x1bOd"],
231
+ clear: ["\x1bOe"],
232
+ insert: ["\x1b[2^"],
233
+ delete: ["\x1b[3^"],
234
+ pageUp: ["\x1b[5^"],
235
+ pageDown: ["\x1b[6^"],
236
+ home: ["\x1b[7^"],
237
+ end: ["\x1b[8^"],
238
+ };
239
+ const LEGACY_SEQUENCE_KEY_IDS = {
240
+ "\x1bOA": "up",
241
+ "\x1bOB": "down",
242
+ "\x1bOC": "right",
243
+ "\x1bOD": "left",
244
+ "\x1bOH": "home",
245
+ "\x1bOF": "end",
246
+ "\x1b[E": "clear",
247
+ "\x1bOE": "clear",
248
+ "\x1bOe": "ctrl+clear",
249
+ "\x1b[e": "shift+clear",
250
+ "\x1b[2~": "insert",
251
+ "\x1b[2$": "shift+insert",
252
+ "\x1b[2^": "ctrl+insert",
253
+ "\x1b[3$": "shift+delete",
254
+ "\x1b[3^": "ctrl+delete",
255
+ "\x1b[[5~": "pageUp",
256
+ "\x1b[[6~": "pageDown",
257
+ "\x1b[a": "shift+up",
258
+ "\x1b[b": "shift+down",
259
+ "\x1b[c": "shift+right",
260
+ "\x1b[d": "shift+left",
261
+ "\x1bOa": "ctrl+up",
262
+ "\x1bOb": "ctrl+down",
263
+ "\x1bOc": "ctrl+right",
264
+ "\x1bOd": "ctrl+left",
265
+ "\x1b[5$": "shift+pageUp",
266
+ "\x1b[6$": "shift+pageDown",
267
+ "\x1b[7$": "shift+home",
268
+ "\x1b[8$": "shift+end",
269
+ "\x1b[5^": "ctrl+pageUp",
270
+ "\x1b[6^": "ctrl+pageDown",
271
+ "\x1b[7^": "ctrl+home",
272
+ "\x1b[8^": "ctrl+end",
273
+ "\x1bOP": "f1",
274
+ "\x1bOQ": "f2",
275
+ "\x1bOR": "f3",
276
+ "\x1bOS": "f4",
277
+ "\x1b[11~": "f1",
278
+ "\x1b[12~": "f2",
279
+ "\x1b[13~": "f3",
280
+ "\x1b[14~": "f4",
281
+ "\x1b[[A": "f1",
282
+ "\x1b[[B": "f2",
283
+ "\x1b[[C": "f3",
284
+ "\x1b[[D": "f4",
285
+ "\x1b[[E": "f5",
286
+ "\x1b[15~": "f5",
287
+ "\x1b[17~": "f6",
288
+ "\x1b[18~": "f7",
289
+ "\x1b[19~": "f8",
290
+ "\x1b[20~": "f9",
291
+ "\x1b[21~": "f10",
292
+ "\x1b[23~": "f11",
293
+ "\x1b[24~": "f12",
294
+ "\x1bb": "alt+left",
295
+ "\x1bf": "alt+right",
296
+ "\x1bp": "alt+up",
297
+ "\x1bn": "alt+down",
298
+ };
299
+ const matchesLegacySequence = (data, sequences) => sequences.includes(data);
300
+ const matchesLegacyModifierSequence = (data, key, modifier) => {
301
+ if (modifier === MODIFIERS.shift) {
302
+ return matchesLegacySequence(data, LEGACY_SHIFT_SEQUENCES[key]);
303
+ }
304
+ if (modifier === MODIFIERS.ctrl) {
305
+ return matchesLegacySequence(data, LEGACY_CTRL_SEQUENCES[key]);
306
+ }
307
+ return false;
308
+ };
309
+ // Tracks the event type from the most recent parseKey() call.
310
+ let _lastEventType = "press";
311
+ /**
312
+ * Check if the given input data represents a key release event.
313
+ * Performs fast pattern matching on raw terminal escape sequences.
314
+ * Only meaningful when Kitty keyboard protocol with flag 2 is active.
315
+ *
316
+ * @param data - Raw terminal input string
317
+ * @returns true if the data contains a key release escape sequence
318
+ */
319
+ export function isKeyRelease(data) {
320
+ // Don't treat bracketed paste content as key release, even if it contains
321
+ // patterns like ":3F" (e.g., bluetooth MAC addresses like "90:62:3F:A5").
322
+ // Terminal.ts re-wraps paste content with bracketed paste markers before
323
+ // passing to TUI, so pasted data will always contain \x1b[200~.
324
+ if (data.includes("\x1b[200~")) {
325
+ return false;
326
+ }
327
+ // Quick check: release events with flag 2 contain ":3"
328
+ // Format: \x1b[<codepoint>;<modifier>:3u
329
+ if (data.includes(":3u") ||
330
+ data.includes(":3~") ||
331
+ data.includes(":3A") ||
332
+ data.includes(":3B") ||
333
+ data.includes(":3C") ||
334
+ data.includes(":3D") ||
335
+ data.includes(":3H") ||
336
+ data.includes(":3F")) {
337
+ return true;
338
+ }
339
+ return false;
340
+ }
341
+ /**
342
+ * Check if the given input data represents a key repeat event.
343
+ * Performs fast pattern matching on raw terminal escape sequences.
344
+ * Only meaningful when Kitty keyboard protocol with flag 2 is active.
345
+ *
346
+ * @param data - Raw terminal input string
347
+ * @returns true if the data contains a key repeat escape sequence
348
+ */
349
+ export function isKeyRepeat(data) {
350
+ // Don't treat bracketed paste content as key repeat, even if it contains
351
+ // patterns like ":2F". See isKeyRelease() for details.
352
+ if (data.includes("\x1b[200~")) {
353
+ return false;
354
+ }
355
+ if (data.includes(":2u") ||
356
+ data.includes(":2~") ||
357
+ data.includes(":2A") ||
358
+ data.includes(":2B") ||
359
+ data.includes(":2C") ||
360
+ data.includes(":2D") ||
361
+ data.includes(":2H") ||
362
+ data.includes(":2F")) {
363
+ return true;
364
+ }
365
+ return false;
366
+ }
367
+ function parseEventType(eventTypeStr) {
368
+ if (!eventTypeStr)
369
+ return "press";
370
+ const eventType = parseInt(eventTypeStr, 10);
371
+ if (eventType === 2)
372
+ return "repeat";
373
+ if (eventType === 3)
374
+ return "release";
375
+ return "press";
376
+ }
377
+ function parseKittySequence(data) {
378
+ // CSI u format with alternate keys (flag 4):
379
+ // \x1b[<codepoint>u
380
+ // \x1b[<codepoint>;<mod>u
381
+ // \x1b[<codepoint>;<mod>:<event>u
382
+ // \x1b[<codepoint>:<shifted>;<mod>u
383
+ // \x1b[<codepoint>:<shifted>:<base>;<mod>u
384
+ // \x1b[<codepoint>::<base>;<mod>u (no shifted key, only base)
385
+ //
386
+ // With flag 2, event type is appended after modifier colon: 1=press, 2=repeat, 3=release
387
+ // With flag 4, alternate keys are appended after codepoint with colons
388
+ const csiUMatch = data.match(/^\x1b\[(\d+)(?::(\d*))?(?::(\d+))?(?:;(\d+))?(?::(\d+))?u$/);
389
+ if (csiUMatch) {
390
+ const codepoint = parseInt(csiUMatch[1], 10);
391
+ const shiftedKey = csiUMatch[2] && csiUMatch[2].length > 0 ? parseInt(csiUMatch[2], 10) : undefined;
392
+ const baseLayoutKey = csiUMatch[3] ? parseInt(csiUMatch[3], 10) : undefined;
393
+ const modValue = csiUMatch[4] ? parseInt(csiUMatch[4], 10) : 1;
394
+ const eventType = parseEventType(csiUMatch[5]);
395
+ _lastEventType = eventType;
396
+ return { codepoint, shiftedKey, baseLayoutKey, modifier: modValue - 1, eventType };
397
+ }
398
+ // Arrow keys with modifier: \x1b[1;<mod>A/B/C/D or \x1b[1;<mod>:<event>A/B/C/D
399
+ const arrowMatch = data.match(/^\x1b\[1;(\d+)(?::(\d+))?([ABCD])$/);
400
+ if (arrowMatch) {
401
+ const modValue = parseInt(arrowMatch[1], 10);
402
+ const eventType = parseEventType(arrowMatch[2]);
403
+ const arrowCodes = { A: -1, B: -2, C: -3, D: -4 };
404
+ _lastEventType = eventType;
405
+ return { codepoint: arrowCodes[arrowMatch[3]], modifier: modValue - 1, eventType };
406
+ }
407
+ // Functional keys: \x1b[<num>~ or \x1b[<num>;<mod>~ or \x1b[<num>;<mod>:<event>~
408
+ const funcMatch = data.match(/^\x1b\[(\d+)(?:;(\d+))?(?::(\d+))?~$/);
409
+ if (funcMatch) {
410
+ const keyNum = parseInt(funcMatch[1], 10);
411
+ const modValue = funcMatch[2] ? parseInt(funcMatch[2], 10) : 1;
412
+ const eventType = parseEventType(funcMatch[3]);
413
+ const funcCodes = {
414
+ 2: FUNCTIONAL_CODEPOINTS.insert,
415
+ 3: FUNCTIONAL_CODEPOINTS.delete,
416
+ 5: FUNCTIONAL_CODEPOINTS.pageUp,
417
+ 6: FUNCTIONAL_CODEPOINTS.pageDown,
418
+ 7: FUNCTIONAL_CODEPOINTS.home,
419
+ 8: FUNCTIONAL_CODEPOINTS.end,
420
+ };
421
+ const codepoint = funcCodes[keyNum];
422
+ if (codepoint !== undefined) {
423
+ _lastEventType = eventType;
424
+ return { codepoint, modifier: modValue - 1, eventType };
425
+ }
426
+ }
427
+ // Home/End with modifier: \x1b[1;<mod>H/F or \x1b[1;<mod>:<event>H/F
428
+ const homeEndMatch = data.match(/^\x1b\[1;(\d+)(?::(\d+))?([HF])$/);
429
+ if (homeEndMatch) {
430
+ const modValue = parseInt(homeEndMatch[1], 10);
431
+ const eventType = parseEventType(homeEndMatch[2]);
432
+ const codepoint = homeEndMatch[3] === "H" ? FUNCTIONAL_CODEPOINTS.home : FUNCTIONAL_CODEPOINTS.end;
433
+ _lastEventType = eventType;
434
+ return { codepoint, modifier: modValue - 1, eventType };
435
+ }
436
+ return null;
437
+ }
438
+ function matchesKittySequence(data, expectedCodepoint, expectedModifier) {
439
+ const parsed = parseKittySequence(data);
440
+ if (!parsed)
441
+ return false;
442
+ const actualMod = parsed.modifier & ~LOCK_MASK;
443
+ const expectedMod = expectedModifier & ~LOCK_MASK;
444
+ // Check if modifiers match
445
+ if (actualMod !== expectedMod)
446
+ return false;
447
+ // Primary match: codepoint matches directly
448
+ if (parsed.codepoint === expectedCodepoint)
449
+ return true;
450
+ // Alternate match: use base layout key for non-Latin keyboard layouts.
451
+ // This allows Ctrl+С (Cyrillic) to match Ctrl+c (Latin) when terminal reports
452
+ // the base layout key (the key in standard PC-101 layout).
453
+ //
454
+ // Only fall back to base layout key when the codepoint is NOT already a
455
+ // recognized Latin letter (a-z) or symbol (e.g., /, -, [, ;, etc.).
456
+ // When the codepoint is a recognized key, it is authoritative regardless
457
+ // of physical key position. This prevents remapped layouts (Dvorak, Colemak,
458
+ // xremap, etc.) from causing false matches: both letters and symbols move
459
+ // to different physical positions, so Ctrl+K could falsely match Ctrl+V
460
+ // (letter remapping) and Ctrl+/ could falsely match Ctrl+[ (symbol remapping)
461
+ // if the base layout key were always considered.
462
+ if (parsed.baseLayoutKey !== undefined && parsed.baseLayoutKey === expectedCodepoint) {
463
+ const cp = parsed.codepoint;
464
+ const isLatinLetter = cp >= 97 && cp <= 122; // a-z
465
+ const isKnownSymbol = SYMBOL_KEYS.has(String.fromCharCode(cp));
466
+ if (!isLatinLetter && !isKnownSymbol)
467
+ return true;
468
+ }
469
+ return false;
470
+ }
471
+ /**
472
+ * Match xterm modifyOtherKeys format: CSI 27 ; modifiers ; keycode ~
473
+ * This is used by terminals when Kitty protocol is not enabled.
474
+ * Modifier values are 1-indexed: 2=shift, 3=alt, 5=ctrl, etc.
475
+ */
476
+ function matchesModifyOtherKeys(data, expectedKeycode, expectedModifier) {
477
+ const match = data.match(/^\x1b\[27;(\d+);(\d+)~$/);
478
+ if (!match)
479
+ return false;
480
+ const modValue = parseInt(match[1], 10);
481
+ const keycode = parseInt(match[2], 10);
482
+ // Convert from 1-indexed xterm format to our 0-indexed format
483
+ const actualMod = modValue - 1;
484
+ return keycode === expectedKeycode && actualMod === expectedModifier;
485
+ }
486
+ // =============================================================================
487
+ // Generic Key Matching
488
+ // =============================================================================
489
+ /**
490
+ * Get the control character for a key.
491
+ * Uses the universal formula: code & 0x1f (mask to lower 5 bits)
492
+ *
493
+ * Works for:
494
+ * - Letters a-z → 1-26
495
+ * - Symbols [\]_ → 27, 28, 29, 31
496
+ * - Also maps - to same as _ (same physical key on US keyboards)
497
+ */
498
+ function rawCtrlChar(key) {
499
+ const char = key.toLowerCase();
500
+ const code = char.charCodeAt(0);
501
+ if ((code >= 97 && code <= 122) ||
502
+ char === "[" ||
503
+ char === "\\" ||
504
+ char === "]" ||
505
+ char === "_") {
506
+ return String.fromCharCode(code & 0x1f);
507
+ }
508
+ // Handle - as _ (same physical key on US keyboards)
509
+ if (char === "-") {
510
+ return String.fromCharCode(31); // Same as Ctrl+_
511
+ }
512
+ return null;
513
+ }
514
+ function parseKeyId(keyId) {
515
+ const parts = keyId.toLowerCase().split("+");
516
+ const key = parts[parts.length - 1];
517
+ if (!key)
518
+ return null;
519
+ return {
520
+ key,
521
+ ctrl: parts.includes("ctrl"),
522
+ shift: parts.includes("shift"),
523
+ alt: parts.includes("alt"),
524
+ };
525
+ }
526
+ /**
527
+ * Match input data against a key identifier string.
528
+ *
529
+ * Supported key identifiers:
530
+ * - Single keys: "escape", "tab", "enter", "backspace", "delete", "home", "end", "space"
531
+ * - Arrow keys: "up", "down", "left", "right"
532
+ * - Ctrl combinations: "ctrl+c", "ctrl+z", etc.
533
+ * - Shift combinations: "shift+tab", "shift+enter"
534
+ * - Alt combinations: "alt+enter", "alt+backspace"
535
+ * - Combined modifiers: "shift+ctrl+p", "ctrl+alt+x"
536
+ *
537
+ * Use the Key helper for autocomplete: Key.ctrl("c"), Key.escape, Key.ctrlShift("p")
538
+ *
539
+ * @param data - Raw input data from terminal
540
+ * @param keyId - Key identifier (e.g., "ctrl+c", "escape", Key.ctrl("c"))
541
+ */
542
+ export function matchesKey(data, keyId) {
543
+ const parsed = parseKeyId(keyId);
544
+ if (!parsed)
545
+ return false;
546
+ const { key, ctrl, shift, alt } = parsed;
547
+ let modifier = 0;
548
+ if (shift)
549
+ modifier |= MODIFIERS.shift;
550
+ if (alt)
551
+ modifier |= MODIFIERS.alt;
552
+ if (ctrl)
553
+ modifier |= MODIFIERS.ctrl;
554
+ switch (key) {
555
+ case "escape":
556
+ case "esc":
557
+ if (modifier !== 0)
558
+ return false;
559
+ return data === "\x1b" || matchesKittySequence(data, CODEPOINTS.escape, 0);
560
+ case "space":
561
+ if (!_kittyProtocolActive) {
562
+ if (ctrl && !alt && !shift && data === "\x00") {
563
+ return true;
564
+ }
565
+ if (alt && !ctrl && !shift && data === "\x1b ") {
566
+ return true;
567
+ }
568
+ }
569
+ if (modifier === 0) {
570
+ return data === " " || matchesKittySequence(data, CODEPOINTS.space, 0);
571
+ }
572
+ return matchesKittySequence(data, CODEPOINTS.space, modifier);
573
+ case "tab":
574
+ if (shift && !ctrl && !alt) {
575
+ return data === "\x1b[Z" || matchesKittySequence(data, CODEPOINTS.tab, MODIFIERS.shift);
576
+ }
577
+ if (modifier === 0) {
578
+ return data === "\t" || matchesKittySequence(data, CODEPOINTS.tab, 0);
579
+ }
580
+ return matchesKittySequence(data, CODEPOINTS.tab, modifier);
581
+ case "enter":
582
+ case "return":
583
+ if (shift && !ctrl && !alt) {
584
+ // CSI u sequences (standard Kitty protocol)
585
+ if (matchesKittySequence(data, CODEPOINTS.enter, MODIFIERS.shift) ||
586
+ matchesKittySequence(data, CODEPOINTS.kpEnter, MODIFIERS.shift)) {
587
+ return true;
588
+ }
589
+ // xterm modifyOtherKeys format (fallback when Kitty protocol not enabled)
590
+ if (matchesModifyOtherKeys(data, CODEPOINTS.enter, MODIFIERS.shift)) {
591
+ return true;
592
+ }
593
+ // When Kitty protocol is active, legacy sequences are custom terminal mappings
594
+ // \x1b\r = Kitty's "map shift+enter send_text all \e\r"
595
+ // \n = Ghostty's "keybind = shift+enter=text:\n"
596
+ if (_kittyProtocolActive) {
597
+ return data === "\x1b\r" || data === "\n";
598
+ }
599
+ return false;
600
+ }
601
+ if (alt && !ctrl && !shift) {
602
+ // CSI u sequences (standard Kitty protocol)
603
+ if (matchesKittySequence(data, CODEPOINTS.enter, MODIFIERS.alt) ||
604
+ matchesKittySequence(data, CODEPOINTS.kpEnter, MODIFIERS.alt)) {
605
+ return true;
606
+ }
607
+ // xterm modifyOtherKeys format (fallback when Kitty protocol not enabled)
608
+ if (matchesModifyOtherKeys(data, CODEPOINTS.enter, MODIFIERS.alt)) {
609
+ return true;
610
+ }
611
+ // \x1b\r is alt+enter only in legacy mode (no Kitty protocol)
612
+ // When Kitty protocol is active, alt+enter comes as CSI u sequence
613
+ if (!_kittyProtocolActive) {
614
+ return data === "\x1b\r";
615
+ }
616
+ return false;
617
+ }
618
+ if (modifier === 0) {
619
+ return (data === "\r" ||
620
+ (!_kittyProtocolActive && data === "\n") ||
621
+ data === "\x1bOM" || // SS3 M (numpad enter in some terminals)
622
+ matchesKittySequence(data, CODEPOINTS.enter, 0) ||
623
+ matchesKittySequence(data, CODEPOINTS.kpEnter, 0));
624
+ }
625
+ return (matchesKittySequence(data, CODEPOINTS.enter, modifier) ||
626
+ matchesKittySequence(data, CODEPOINTS.kpEnter, modifier));
627
+ case "backspace":
628
+ if (alt && !ctrl && !shift) {
629
+ if (data === "\x1b\x7f" || data === "\x1b\b") {
630
+ return true;
631
+ }
632
+ return matchesKittySequence(data, CODEPOINTS.backspace, MODIFIERS.alt);
633
+ }
634
+ if (modifier === 0) {
635
+ return (data === "\x7f" || data === "\x08" || matchesKittySequence(data, CODEPOINTS.backspace, 0));
636
+ }
637
+ return matchesKittySequence(data, CODEPOINTS.backspace, modifier);
638
+ case "insert":
639
+ if (modifier === 0) {
640
+ return (matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.insert) ||
641
+ matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.insert, 0));
642
+ }
643
+ if (matchesLegacyModifierSequence(data, "insert", modifier)) {
644
+ return true;
645
+ }
646
+ return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.insert, modifier);
647
+ case "delete":
648
+ if (modifier === 0) {
649
+ return (matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.delete) ||
650
+ matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.delete, 0));
651
+ }
652
+ if (matchesLegacyModifierSequence(data, "delete", modifier)) {
653
+ return true;
654
+ }
655
+ return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.delete, modifier);
656
+ case "clear":
657
+ if (modifier === 0) {
658
+ return matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.clear);
659
+ }
660
+ return matchesLegacyModifierSequence(data, "clear", modifier);
661
+ case "home":
662
+ if (modifier === 0) {
663
+ return (matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.home) ||
664
+ matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.home, 0));
665
+ }
666
+ if (matchesLegacyModifierSequence(data, "home", modifier)) {
667
+ return true;
668
+ }
669
+ return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.home, modifier);
670
+ case "end":
671
+ if (modifier === 0) {
672
+ return (matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.end) ||
673
+ matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.end, 0));
674
+ }
675
+ if (matchesLegacyModifierSequence(data, "end", modifier)) {
676
+ return true;
677
+ }
678
+ return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.end, modifier);
679
+ case "pageup":
680
+ if (modifier === 0) {
681
+ return (matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.pageUp) ||
682
+ matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.pageUp, 0));
683
+ }
684
+ if (matchesLegacyModifierSequence(data, "pageUp", modifier)) {
685
+ return true;
686
+ }
687
+ return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.pageUp, modifier);
688
+ case "pagedown":
689
+ if (modifier === 0) {
690
+ return (matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.pageDown) ||
691
+ matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.pageDown, 0));
692
+ }
693
+ if (matchesLegacyModifierSequence(data, "pageDown", modifier)) {
694
+ return true;
695
+ }
696
+ return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.pageDown, modifier);
697
+ case "up":
698
+ if (alt && !ctrl && !shift) {
699
+ return data === "\x1bp" || matchesKittySequence(data, ARROW_CODEPOINTS.up, MODIFIERS.alt);
700
+ }
701
+ if (modifier === 0) {
702
+ return (matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.up) ||
703
+ matchesKittySequence(data, ARROW_CODEPOINTS.up, 0));
704
+ }
705
+ if (matchesLegacyModifierSequence(data, "up", modifier)) {
706
+ return true;
707
+ }
708
+ return matchesKittySequence(data, ARROW_CODEPOINTS.up, modifier);
709
+ case "down":
710
+ if (alt && !ctrl && !shift) {
711
+ return data === "\x1bn" || matchesKittySequence(data, ARROW_CODEPOINTS.down, MODIFIERS.alt);
712
+ }
713
+ if (modifier === 0) {
714
+ return (matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.down) ||
715
+ matchesKittySequence(data, ARROW_CODEPOINTS.down, 0));
716
+ }
717
+ if (matchesLegacyModifierSequence(data, "down", modifier)) {
718
+ return true;
719
+ }
720
+ return matchesKittySequence(data, ARROW_CODEPOINTS.down, modifier);
721
+ case "left":
722
+ if (alt && !ctrl && !shift) {
723
+ return (data === "\x1b[1;3D" ||
724
+ (!_kittyProtocolActive && data === "\x1bB") ||
725
+ data === "\x1bb" ||
726
+ matchesKittySequence(data, ARROW_CODEPOINTS.left, MODIFIERS.alt));
727
+ }
728
+ if (ctrl && !alt && !shift) {
729
+ return (data === "\x1b[1;5D" ||
730
+ matchesLegacyModifierSequence(data, "left", MODIFIERS.ctrl) ||
731
+ matchesKittySequence(data, ARROW_CODEPOINTS.left, MODIFIERS.ctrl));
732
+ }
733
+ if (modifier === 0) {
734
+ return (matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.left) ||
735
+ matchesKittySequence(data, ARROW_CODEPOINTS.left, 0));
736
+ }
737
+ if (matchesLegacyModifierSequence(data, "left", modifier)) {
738
+ return true;
739
+ }
740
+ return matchesKittySequence(data, ARROW_CODEPOINTS.left, modifier);
741
+ case "right":
742
+ if (alt && !ctrl && !shift) {
743
+ return (data === "\x1b[1;3C" ||
744
+ (!_kittyProtocolActive && data === "\x1bF") ||
745
+ data === "\x1bf" ||
746
+ matchesKittySequence(data, ARROW_CODEPOINTS.right, MODIFIERS.alt));
747
+ }
748
+ if (ctrl && !alt && !shift) {
749
+ return (data === "\x1b[1;5C" ||
750
+ matchesLegacyModifierSequence(data, "right", MODIFIERS.ctrl) ||
751
+ matchesKittySequence(data, ARROW_CODEPOINTS.right, MODIFIERS.ctrl));
752
+ }
753
+ if (modifier === 0) {
754
+ return (matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.right) ||
755
+ matchesKittySequence(data, ARROW_CODEPOINTS.right, 0));
756
+ }
757
+ if (matchesLegacyModifierSequence(data, "right", modifier)) {
758
+ return true;
759
+ }
760
+ return matchesKittySequence(data, ARROW_CODEPOINTS.right, modifier);
761
+ case "f1":
762
+ case "f2":
763
+ case "f3":
764
+ case "f4":
765
+ case "f5":
766
+ case "f6":
767
+ case "f7":
768
+ case "f8":
769
+ case "f9":
770
+ case "f10":
771
+ case "f11":
772
+ case "f12": {
773
+ if (modifier !== 0) {
774
+ return false;
775
+ }
776
+ const functionKey = key;
777
+ return matchesLegacySequence(data, LEGACY_KEY_SEQUENCES[functionKey]);
778
+ }
779
+ }
780
+ // Handle single letter keys (a-z) and some symbols
781
+ if (key.length === 1 && ((key >= "a" && key <= "z") || SYMBOL_KEYS.has(key))) {
782
+ const codepoint = key.charCodeAt(0);
783
+ const rawCtrl = rawCtrlChar(key);
784
+ if (ctrl && alt && !shift && !_kittyProtocolActive && rawCtrl) {
785
+ // Legacy: ctrl+alt+key is ESC followed by the control character
786
+ return data === `\x1b${rawCtrl}`;
787
+ }
788
+ if (alt && !ctrl && !shift && !_kittyProtocolActive && key >= "a" && key <= "z") {
789
+ // Legacy: alt+letter is ESC followed by the letter
790
+ if (data === `\x1b${key}`)
791
+ return true;
792
+ }
793
+ if (ctrl && !shift && !alt) {
794
+ // Legacy: ctrl+key sends the control character
795
+ if (rawCtrl && data === rawCtrl)
796
+ return true;
797
+ return matchesKittySequence(data, codepoint, MODIFIERS.ctrl);
798
+ }
799
+ if (ctrl && shift && !alt) {
800
+ return matchesKittySequence(data, codepoint, MODIFIERS.shift + MODIFIERS.ctrl);
801
+ }
802
+ if (shift && !ctrl && !alt) {
803
+ // Legacy: shift+letter produces uppercase
804
+ if (data === key.toUpperCase())
805
+ return true;
806
+ return matchesKittySequence(data, codepoint, MODIFIERS.shift);
807
+ }
808
+ if (modifier !== 0) {
809
+ return matchesKittySequence(data, codepoint, modifier);
810
+ }
811
+ // Check both raw char and Kitty sequence (needed for release events)
812
+ return data === key || matchesKittySequence(data, codepoint, 0);
813
+ }
814
+ return false;
815
+ }
816
+ /**
817
+ * Parse input data and return the key identifier if recognized.
818
+ *
819
+ * @param data - Raw input data from terminal
820
+ * @returns Key identifier string (e.g., "ctrl+c") or undefined
821
+ */
822
+ export function parseKey(data) {
823
+ const kitty = parseKittySequence(data);
824
+ if (kitty) {
825
+ const { codepoint, baseLayoutKey, modifier } = kitty;
826
+ const mods = [];
827
+ const effectiveMod = modifier & ~LOCK_MASK;
828
+ if (effectiveMod & MODIFIERS.shift)
829
+ mods.push("shift");
830
+ if (effectiveMod & MODIFIERS.ctrl)
831
+ mods.push("ctrl");
832
+ if (effectiveMod & MODIFIERS.alt)
833
+ mods.push("alt");
834
+ // Use base layout key only when codepoint is not a recognized Latin
835
+ // letter (a-z) or symbol (/, -, [, ;, etc.). For those, the codepoint
836
+ // is authoritative regardless of physical key position. This prevents
837
+ // remapped layouts (Dvorak, Colemak, xremap, etc.) from reporting the
838
+ // wrong key name based on the QWERTY physical position.
839
+ const isLatinLetter = codepoint >= 97 && codepoint <= 122; // a-z
840
+ const isKnownSymbol = SYMBOL_KEYS.has(String.fromCharCode(codepoint));
841
+ const effectiveCodepoint = isLatinLetter || isKnownSymbol ? codepoint : (baseLayoutKey ?? codepoint);
842
+ let keyName;
843
+ if (effectiveCodepoint === CODEPOINTS.escape)
844
+ keyName = "escape";
845
+ else if (effectiveCodepoint === CODEPOINTS.tab)
846
+ keyName = "tab";
847
+ else if (effectiveCodepoint === CODEPOINTS.enter || effectiveCodepoint === CODEPOINTS.kpEnter)
848
+ keyName = "enter";
849
+ else if (effectiveCodepoint === CODEPOINTS.space)
850
+ keyName = "space";
851
+ else if (effectiveCodepoint === CODEPOINTS.backspace)
852
+ keyName = "backspace";
853
+ else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.delete)
854
+ keyName = "delete";
855
+ else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.insert)
856
+ keyName = "insert";
857
+ else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.home)
858
+ keyName = "home";
859
+ else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.end)
860
+ keyName = "end";
861
+ else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.pageUp)
862
+ keyName = "pageUp";
863
+ else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.pageDown)
864
+ keyName = "pageDown";
865
+ else if (effectiveCodepoint === ARROW_CODEPOINTS.up)
866
+ keyName = "up";
867
+ else if (effectiveCodepoint === ARROW_CODEPOINTS.down)
868
+ keyName = "down";
869
+ else if (effectiveCodepoint === ARROW_CODEPOINTS.left)
870
+ keyName = "left";
871
+ else if (effectiveCodepoint === ARROW_CODEPOINTS.right)
872
+ keyName = "right";
873
+ else if (effectiveCodepoint >= 97 && effectiveCodepoint <= 122)
874
+ keyName = String.fromCharCode(effectiveCodepoint);
875
+ else if (SYMBOL_KEYS.has(String.fromCharCode(effectiveCodepoint)))
876
+ keyName = String.fromCharCode(effectiveCodepoint);
877
+ if (keyName) {
878
+ return mods.length > 0 ? `${mods.join("+")}+${keyName}` : keyName;
879
+ }
880
+ }
881
+ // Mode-aware legacy sequences
882
+ // When Kitty protocol is active, ambiguous sequences are interpreted as custom terminal mappings:
883
+ // - \x1b\r = shift+enter (Kitty mapping), not alt+enter
884
+ // - \n = shift+enter (Ghostty mapping)
885
+ if (_kittyProtocolActive) {
886
+ if (data === "\x1b\r" || data === "\n")
887
+ return "shift+enter";
888
+ }
889
+ const legacySequenceKeyId = LEGACY_SEQUENCE_KEY_IDS[data];
890
+ if (legacySequenceKeyId)
891
+ return legacySequenceKeyId;
892
+ // Legacy sequences (used when Kitty protocol is not active, or for unambiguous sequences)
893
+ if (data === "\x1b")
894
+ return "escape";
895
+ if (data === "\x1c")
896
+ return "ctrl+\\";
897
+ if (data === "\x1d")
898
+ return "ctrl+]";
899
+ if (data === "\x1f")
900
+ return "ctrl+-";
901
+ if (data === "\x1b\x1b")
902
+ return "ctrl+alt+[";
903
+ if (data === "\x1b\x1c")
904
+ return "ctrl+alt+\\";
905
+ if (data === "\x1b\x1d")
906
+ return "ctrl+alt+]";
907
+ if (data === "\x1b\x1f")
908
+ return "ctrl+alt+-";
909
+ if (data === "\t")
910
+ return "tab";
911
+ if (data === "\r" || (!_kittyProtocolActive && data === "\n") || data === "\x1bOM")
912
+ return "enter";
913
+ if (data === "\x00")
914
+ return "ctrl+space";
915
+ if (data === " ")
916
+ return "space";
917
+ if (data === "\x7f" || data === "\x08")
918
+ return "backspace";
919
+ if (data === "\x1b[Z")
920
+ return "shift+tab";
921
+ if (!_kittyProtocolActive && data === "\x1b\r")
922
+ return "alt+enter";
923
+ if (!_kittyProtocolActive && data === "\x1b ")
924
+ return "alt+space";
925
+ if (data === "\x1b\x7f" || data === "\x1b\b")
926
+ return "alt+backspace";
927
+ if (!_kittyProtocolActive && data === "\x1bB")
928
+ return "alt+left";
929
+ if (!_kittyProtocolActive && data === "\x1bF")
930
+ return "alt+right";
931
+ if (!_kittyProtocolActive && data.length === 2 && data[0] === "\x1b") {
932
+ const code = data.charCodeAt(1);
933
+ if (code >= 1 && code <= 26) {
934
+ return `ctrl+alt+${String.fromCharCode(code + 96)}`;
935
+ }
936
+ // Legacy alt+letter (ESC followed by letter a-z)
937
+ if (code >= 97 && code <= 122) {
938
+ return `alt+${String.fromCharCode(code)}`;
939
+ }
940
+ }
941
+ if (data === "\x1b[A")
942
+ return "up";
943
+ if (data === "\x1b[B")
944
+ return "down";
945
+ if (data === "\x1b[C")
946
+ return "right";
947
+ if (data === "\x1b[D")
948
+ return "left";
949
+ if (data === "\x1b[H" || data === "\x1bOH")
950
+ return "home";
951
+ if (data === "\x1b[F" || data === "\x1bOF")
952
+ return "end";
953
+ if (data === "\x1b[3~")
954
+ return "delete";
955
+ if (data === "\x1b[5~")
956
+ return "pageUp";
957
+ if (data === "\x1b[6~")
958
+ return "pageDown";
959
+ // Raw Ctrl+letter
960
+ if (data.length === 1) {
961
+ const code = data.charCodeAt(0);
962
+ if (code >= 1 && code <= 26) {
963
+ return `ctrl+${String.fromCharCode(code + 96)}`;
964
+ }
965
+ if (code >= 32 && code <= 126) {
966
+ return data;
967
+ }
968
+ }
969
+ return undefined;
970
+ }
971
+ //# sourceMappingURL=keys.js.map