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 @@
## 2025-01-01 - TUI Shortcuts and Visual Prompts
**Learning:** In headless terminal environments, web-style visual affordances must be explicitly surfaced (e.g., manually formatting options in `rich` prompts without triggering markup parsing). Furthermore, 'Esc' (`\x1b`) should never be advertised as a TUI cancel action in raw mode, as blocking ANSI escape sequence reads can hang the app.
**Action:** Always manually escape choice formatting in `rich` prompts (e.g., `\[a|b]`), use `\x03` (`Ctrl-C`) for TUI cancellation, and append shortcut hints to footer text.
9 changes: 7 additions & 2 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
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
if key == '\x1b':
next_chars = sys.stdin.read(2)
mapping = {'[A': 'up', '[B': 'down', '[D': 'left', '[C': 'right'}
Expand Down Expand Up @@ -67,7 +71,8 @@ def _render_selector(self, title, options, selected_index, help_text, default):
style = 'bold green' if index == selected_index else ''
table.add_row(marker, label, style=style)

footer = help_text or 'Use Up/Down arrows and Enter to select.'
base_footer = help_text or 'Use Up/Down arrows and Enter to select.'
footer = f"{base_footer} (Ctrl-C to cancel)"
self.console.print(Panel.fit(footer, title='Interpreter TUI', border_style='green'))
self.console.print(f"[bold cyan]{title}[/bold cyan]")
self.console.print(table)
Expand All @@ -76,7 +81,7 @@ def _render_selector(self, title, options, selected_index, help_text, default):
def _select_option(self, title, options, default, help_text=None):
if not sys.stdin.isatty():
default_choice = default if default in options else options[0]
answer = Prompt.ask(f"{title}", default=default_choice).strip()
answer = Prompt.ask(f"{title} \\[{'|'.join(options)}]", default=default_choice).strip()
if answer in options:
return answer
for option in options:
Expand Down
Loading