Skip to content

Commit 4da2bd4

Browse files
author
SqlRush
committed
Decode extended CSI-u modifiers
1 parent 41d0cbf commit 4da2bd4

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎docs/cc-100-roadmap.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ M7 补充:terminal input parser 现在接受 xterm modified arrow 序列(如
178178

179179
M7 补充:terminal input parser 现在把 xterm modified navigation modifier 范围扩展到 `2..16`,覆盖 meta/shift+meta/ctrl+meta 组合(如 `CSI 1;10D`、`CSI 1;16C`)以及对应 Home/End/Delete/PageUp/PageDown 序列。
180180

181+
M7 补充:terminal CSI-u/kitty keyboard parser 现在按 modifier bitfield 解码 `9..16` 扩展组合,把 meta/shift+meta 映射到现有 alt key surface,把 ctrl+meta 组合保留为 ctrl key,覆盖 `CSI 98;9u`、`CSI 97;13u` 等序列。
182+
181183
M7 补充:terminal CSI parser 现在把 DA/device attributes (`CSI c`、`CSI >c`、`CSI =c`) 解析成 report action,保留 primary/secondary/tertiary private marker 和 code,避免终端能力查询序列落入 generic unknown。
182184

183185
M7 补充:terminal CSI parser 现在接受 ECMA/xterm cursor alias final bytes:`CSI a` 映射 cursor-forward、`CSI e` 映射 cursor-down、`CSI \`` 映射 cursor-column,避免常见终端输出别名落入 unknown。

‎docs/claude-code-go-rewrite-plan.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ test/parity/ # golden tests against TS/official behavior
268268
- 本轮补充:terminal CSI-u/kitty keyboard parser 接受无 modifier 字段或 modifier `1` 的 base key 序列,覆盖 printable rune、Enter、Tab、Esc 和 Backspace,避免 extended-key 模式下普通键序列被解析成 unknown。
269269
- 本轮补充:terminal input parser 接受 xterm modified arrow 序列(如 `CSI 1;2D`、`CSI 1;6C`、`CSI 1;7D`),把 shift-arrow 降级为方向键、alt-arrow 映射到 word-motion key、ctrl/ctrl+alt-arrow 映射到 ctrl word-motion key,避免 extended navigation 序列落入 unknown。
270270
- 本轮补充:terminal input parser 现在把 xterm modified navigation modifier 范围扩展到 `2..16`,覆盖 meta/shift+meta/ctrl+meta 组合(如 `CSI 1;10D`、`CSI 1;16C`)以及对应 Home/End/Delete/PageUp/PageDown 序列。
271+
- 本轮补充:terminal CSI-u/kitty keyboard parser 现在按 modifier bitfield 解码 `9..16` 扩展组合,把 meta/shift+meta 映射到现有 alt key surface,把 ctrl+meta 组合保留为 ctrl key,覆盖 `CSI 98;9u`、`CSI 97;13u` 等序列。
271272
- 本轮补充:terminal CSI parser 把 DA/device attributes (`CSI c`、`CSI >c`、`CSI =c`) 归入 report action,并在 terminal parser dispatcher 中作为 `TerminalActionReport` 暴露。
272273
- 本轮补充:terminal CSI parser 接受 `CSI a`/`CSI e`/`CSI \`` cursor alias final bytes,并映射到已有 cursor-forward/cursor-down/cursor-column actions。
273274
- 本轮补充:terminal CSI parser 接受 ECMA `CSI Ps j` / `CSI Ps k` HPB/VPB backward cursor final bytes,并映射到已有 cursor-back/cursor-up actions。

‎internal/tui/input.go‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ func parseCSIuKey(seq string) (Key, bool) {
277277
if modifier == 1 {
278278
return baseCSIuKey(codepoint)
279279
}
280-
shift := modifier == 2 || modifier == 4 || modifier == 6 || modifier == 8
281-
alt := modifier == 3 || modifier == 4 || modifier == 7 || modifier == 8
282-
ctrl := modifier >= 5 && modifier <= 8
280+
shift, alt, ctrl := csiModifierState(modifier)
283281

284282
if ctrl {
285283
if key, ok := ctrlCSIuKey(codepoint); ok {
@@ -304,6 +302,14 @@ func parseCSIuKey(seq string) (Key, bool) {
304302
return Key{}, false
305303
}
306304

305+
func csiModifierState(modifier int) (shift bool, alt bool, ctrl bool) {
306+
flags := modifier - 1
307+
shift = flags&1 != 0
308+
alt = flags&2 != 0 || flags&8 != 0
309+
ctrl = flags&4 != 0
310+
return shift, alt, ctrl
311+
}
312+
307313
func baseCSIuKey(codepoint int) (Key, bool) {
308314
switch codepoint {
309315
case 8, 127:

‎internal/tui/tui_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,11 @@ func TestParseCSIuKeySequences(t *testing.T) {
10301030
{seq: "\x1b[98:66;3:1u", want: KeyAltB},
10311031
{seq: "\x1b[68;3u", want: KeyAltD},
10321032
{seq: "\x1b[127;3u", want: KeyAltBS},
1033+
{seq: "\x1b[98;9u", want: KeyAltB},
1034+
{seq: "\x1b[98:66;10:1u", want: KeyAltB},
1035+
{seq: "\x1b[127;9u", want: KeyAltBS},
1036+
{seq: "\x1b[97;13u", want: KeyCtrlA},
1037+
{seq: "\x1b[117;14u", want: KeyCtrlU},
10331038
{seq: "\x1b[13;2u", want: KeyShiftEnter},
10341039
{seq: "\x1b[13;2:1u", want: KeyShiftEnter},
10351040
{seq: "\x1b[9;2u", want: KeyShiftTab},

0 commit comments

Comments
 (0)