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-09 - Terminal UI Escape and Interrupt Handling

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix the entry date to match this PR’s timeline.

The heading uses 2024-06-09, but this change set is from June 2026. Keeping dates accurate is important for learning-history traceability.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.jules/palette.md at line 1, The entry heading "## 2024-06-09 - Terminal UI
Escape and Interrupt Handling" has the wrong year; update that heading to the
correct PR timeline (e.g., "## 2026-06-09 - Terminal UI Escape and Interrupt
Handling") so the date in the file matches the change set; edit the heading line
exactly (the string starting with "## 2024-06-09 - Terminal UI Escape and
Interrupt Handling") to replace the year and/or date as appropriate.

**Learning:** Raw terminal UI elements map specific standard interrupt bytes (like `\x03` for Ctrl-C and `\x04` for Ctrl-D) natively. For custom raw interaction loops, these must be explicitly handled. Additionally, rich styling uses brackets as markup, so if you inject options manually into a string for `Prompt.ask` (e.g. `title \[{options}]`) to avoid strict case-sensitive choices, you must escape the brackets to avoid styling issues. Furthermore, shortcut hints like "Esc/Ctrl-C to cancel" should be visible to avoid keyboard traps.
**Action:** Next time, ensure keyboard interrupts map correctly to exit actions in raw mode, and include clear shortcut hints to make the interface more accessible.
6 changes: 3 additions & 3 deletions libs/terminal_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ 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.'
footer = help_text or 'Use Up/Down arrows and Enter to select. Esc/Ctrl-C to cancel.'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update the cancel hint to include Ctrl-D.

The selector now cancels on Esc, Ctrl-C, and Ctrl-D (Line 102), but the footer only advertises Esc/Ctrl-C. This leaves one active shortcut undiscoverable.

Suggested fix
-        footer = help_text or 'Use Up/Down arrows and Enter to select. Esc/Ctrl-C to cancel.'
+        footer = help_text or 'Use Up/Down arrows and Enter to select. Esc/Ctrl-C/Ctrl-D to cancel.'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
footer = help_text or 'Use Up/Down arrows and Enter to select. Esc/Ctrl-C to cancel.'
footer = help_text or 'Use Up/Down arrows and Enter to select. Esc/Ctrl-C/Ctrl-D to cancel.'
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/terminal_ui.py` at line 70, Footer text omits the Ctrl-D shortcut;
update the footer assignment (variable footer in libs/terminal_ui.py) to include
"Ctrl-D" so it matches the actual cancel behavior in the selector (the cancel
handling that listens for Esc, Ctrl-C, and Ctrl-D). Replace the current string
'Esc/Ctrl-C to cancel.' with a wording that includes Ctrl-D (e.g.,
'Esc/Ctrl-C/Ctrl-D to cancel.') so the UI help matches the implemented
shortcuts.

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 +76,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 All @@ -99,7 +99,7 @@ def _select_option(self, title, options, default, help_text=None):
selected_index = (selected_index + 1) % len(options)
elif key == 'enter':
return options[selected_index]
elif key == 'escape':
elif key in ('escape', '\x03', '\x04'):
raise KeyboardInterrupt('Selection cancelled by user.')
elif isinstance(key, str) and len(key) == 1:
lowered = key.lower()
Expand Down
Loading