Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-06-22 - TUI Keyboard Trap Fix
**Learning:** When building terminal UIs with explicit raw mode reading (like bypassing `rich` prompt and using `tty.setraw`), standard interrupt combinations like Ctrl-C (`\x03`) do not raise `KeyboardInterrupt` by default. This causes a severe keyboard trap that prevents users from cleanly escaping out of selection states.
**Action:** Always intercept `\x03` explicitly when parsing raw keystrokes in terminal interactions and manually raise `KeyboardInterrupt` to preserve accessible escape hatches.
4 changes: 4 additions & 0 deletions libs/terminal_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def _read_key(self):
if os.name == 'nt':
import msvcrt
key = msvcrt.getwch()
if key == '\x03':
raise KeyboardInterrupt('Selection cancelled by user.')
if key in ('\x00', '\xe0'):
extended = msvcrt.getwch()
mapping = {'H': 'up', 'P': 'down', 'K': 'left', 'M': 'right'}
Expand All @@ -37,6 +39,8 @@ def _read_key(self):
try:
tty.setraw(fd)
key = sys.stdin.read(1)
if key == '\x03':
raise KeyboardInterrupt('Selection cancelled by user.')
if key == '\x1b':
next_chars = sys.stdin.read(2)
mapping = {'[A': 'up', '[B': 'down', '[D': 'left', '[C': 'right'}
Expand Down
Loading