TunaCode TUI - Component Relationships and Event Flow
The ESC key handling in TunaCode follows a priority cascade pattern with layered interception. Events flow through the Textual framework's event system, with modal screens having the highest priority, followed by the application-level handler.
Central coordinator for all ESC handling. Defines global binding and priority cascade.
priority=Trueaction_cancel_request()Input widget for user text. Provides clear_input() method called by app.
clear_input()has_paste_buffer propertyManages shell command execution. Provides cancellation interface.
cancel() methodPushed onto screen stack. Each handles its own ESC to dismiss.
Model and Provider picker screens implement a two-phase ESC behavior for better UX:
self._filter_query = "gpt"
on_key(): if escape and _filter_query: clear filter, event.stop()
action_cancel(): self.dismiss(None)
| File | Lines | Component | ESC Behavior |
|---|---|---|---|
ui/app.py |
65 | Binding | Global ESC binding with priority=True |
ui/app.py |
343-356 | Handler | Priority cascade: request > shell > editor |
ui/widgets/editor.py |
110-113 | Method | clear_input() - clears value and paste buffer |
ui/shell_runner.py |
119-137 | Method | cancel() - terminates shell subprocess |
ui/screens/model_picker.py |
94, 160-164 | ProviderPicker | Two-phase: clear filter, then dismiss |
ui/screens/model_picker.py |
212, 289-293 | ModelPicker | Two-phase: clear filter, then dismiss |
ui/screens/session_picker.py |
55, 179-181 | SessionPicker | Direct dismiss with None |
ui/screens/theme_picker.py |
48, 87-90 | ThemePicker | Revert theme, dismiss with None |
ui/screens/update_confirm.py |
46, 68-69 | UpdateConfirm | Dismiss with False |
ui/screens/setup.py |
29, 100-102 | SetupScreen | Skip setup, dismiss with False |
The action_cancel_request() method uses early returns to implement a clear priority order. First matching condition wins.
Modal screens handle their own ESC independently. They intercept the event before it reaches the app layer via event.stop().
The ChatContainer is always visible. ESC never hides the chat - it only cancels operations or clears input.
Pickers with filters require two ESC presses: first clears filter, second dismisses. This prevents accidental closure.
Generated: 2026-02-02 | TunaCode TUI ESC Key Flow Documentation