emrg: TUI — Option/Ctrl+←/→ move cursor by word (macOS CSI modifier sequences) (rant 2026-08-21T11:36:56) - #909
Merged
Conversation
…equences) (rant 2026-08-21T11:36:56) macOS terminals send \x1b[1;3D for Option+← and \x1b[1;3C for Option+→; the ESC-sequence handler only inspected data[2] (the '1' parameter) so these were dropped and the cursor never moved — while Option+Backspace (\x17) worked, making the asymmetry obvious. - emrg/client/app.py: new module-level _csi_modifier_action() parses modifier-prefixed CSI arrows (\x1b[1;3D/3C = Alt, 1;5D/5C = Ctrl, 1;7D/7C = Alt+Ctrl) plus the Kitty protocol form \x1b[68;3u (key 68='D'=Left / 67='C'=Right) and maps them to word movement; wired into handle_key before the plain arrow branches (plain \x1b[D and non-modifier sequences are unaffected). - emrg/client/widgets.py: move_word_left/right were implemented but never reachable — now bound to the modifier arrows. - tests/test_app_widgets.py: +2 tests (modifier mapping matrix incl. no-op negatives; InputWidget word-move behavior incl. edge no-ops). - Agent.md: documented test count 986 -> 988.
argszero
commented
Aug 21, 2026
argszero
left a comment
OwnerAuthor
There was a problem hiding this comment.
✅ LGTM — cycle
Fresh review of the TUI word-movement fix:
- _csi_modifier_action correctly parses \x1b[1;3D/3C (Alt), 1;5D/5C (Ctrl), 1;7D/7C (Alt+Ctrl) and the Kitty \x1b[68;3u / \x1b[67;3u forms, mapping to word_left/word_right; returns None early for non-CSI / non-';' sequences (Delete \x1b[3~, paste markers, plain arrows) so existing branches are unaffected.
- Wired before the plain arrow branches in handle_key with term.render().
- Tests cover the full mapping matrix incl. negative no-ops and InputWidget word-move edges.
- CI test + test-windows PASS; local pytest 987 passed + 1 skipped (988 collected), import + CLI OK.
1/3.
pm25coder
commented
Aug 21, 2026
Collaborator
Independent test report (Contributor, pm25coder): |
argszero
commented
Aug 21, 2026
argszero
left a comment
OwnerAuthor
There was a problem hiding this comment.
✅ LGTM — cycle
Re-review (head a5cb59e unchanged since previous review):
- _csi_modifier_action() parses CSI modifier params (\x1b[1;3/5/7 + D/C) and Kitty CSI-u forms (\x1b[68;3u / \x1b[67;3u) into word_left/word_right; guards: len>=4, ESC+'[', ';' present, final byte in 0x40-0x7E, all-params-numeric, modifier in {3,5,7} — returns None for bare arrows, Shift, Delete, Alt+Up, non-CSI.
- Wired into handle_key before the plain-arrow branch, with term.render().
- Tests: full mapping matrix incl. negatives + InputWidget word-move edge cases (no-op at boundaries).
- Verified locally: pytest 987 passed + 1 skipped (988 collected, matches Agent.md), import + CLI OK. CI test + test-windows PASS.
2/3.
argszero
commented
Aug 21, 2026
argszero
left a comment
OwnerAuthor
There was a problem hiding this comment.
✅ LGTM — cycle
3rd consecutive review (head a5cb59e, MERGEABLE/CLEAN, CI test + test-windows PASS):
- Fresh local verification on the branch: pytest 987 passed + 1 skipped (988 collected, matches Agent.md update), import + CLI OK.
- _csi_modifier_action() parses legacy CSI modifier forms (\x1b[1;3/5/7 + D/C) and Kitty CSI-u (\x1b[68;3u / \x1b[67;3u) into word_left/word_right with strict guards (len>=4, ESC+[, ';' present, final 0x40-0x7E, numeric params, modifier in {3,5,7}); returns None for bare arrows / Shift / Delete / Alt+Up / non-CSI so existing branches are untouched.
- Wired before the plain-arrow branch in handle_key with term.render(); InputWidget.move_word_left/right exist and the new tests cover the full mapping matrix including negative no-ops and boundary behavior.
3/3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
macOS terminals (iTerm2/Ghostty) send
\x1b[1;3Dfor Option+← and\x1b[1;3Cfor Option+→. The TUI's ESC-sequence handler only inspecteddata[2](the'1'parameter), so these sequences were dropped and the cursor never moved — whileOption+Backspace(\x17) worked, making the asymmetry obvious (host rant2026-08-21T11:36:56).Changes
emrg/client/app.py— new module-level_csi_modifier_action()parses modifier-prefixed CSI arrows:\x1b[1;3D/\x1b[1;3C(Alt+←/→),\x1b[1;5D/\x1b[1;5C(Ctrl+←/→),\x1b[1;7D/\x1b[1;7C(Alt+Ctrl)\x1b[68;3u(key code 68 ='D'= Left, 67 ='C'= Right)handle_keybefore the plain-arrow branches; plain\x1b[Dand non-modifier sequences (Shift+←, Delete\x1b[3~, F-keys) are unaffectedemrg/client/widgets.py—move_word_left/move_word_rightwere implemented but never reachable; now bound to the modifier arrows.tests/test_app_widgets.py— +2 tests: modifier-mapping matrix (incl. negative no-ops) andInputWidgetword-move behavior (incl. edge no-ops at start/end).Agent.md— documented test count 986 → 988.Verification
uv run pytest tests/→ 987 passed + 1 skipped (988 collected) (was 985+1)uv run python -c "from emrg.client.app import run_client"→ OKuv run python -m emrg --help→ OK