Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Better implementation of interrupt on Esc (#2111)

pakrym-oai12cf0dd868cc
diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs
index ebce2699e8..cd2b308dcc 100644
--- a/codex-rs/tui/src/app.rs
+++ b/codex-rs/tui/src/app.rs
@@ -235,20 +235,6 @@ impl App<'_> {
self.app_event_tx.send(AppEvent::ExitRequest);
}
},
- KeyEvent {
- code: KeyCode::Esc,
- kind: KeyEventKind::Press,
- ..
- } => match &mut self.app_state {
- AppState::Chat { widget } => {
- if !widget.on_esc() {
- self.dispatch_key_event(key_event);
- }
- }
- AppState::Onboarding { .. } => {
- self.dispatch_key_event(key_event);
- }
- },
KeyEvent {
code: KeyCode::Char('z'),
modifiers: crossterm::event::KeyModifiers::CONTROL,
diff --git a/codex-rs/tui/src/bottom_pane/status_indicator_view.rs b/codex-rs/tui/src/bottom_pane/status_indicator_view.rs
index a944271e45..cad4f0f272 100644
--- a/codex-rs/tui/src/bottom_pane/status_indicator_view.rs
+++ b/codex-rs/tui/src/bottom_pane/status_indicator_view.rs
@@ -1,7 +1,10 @@
+use crossterm::event::KeyCode;
+use crossterm::event::KeyEvent;
use ratatui::buffer::Buffer;
use ratatui::widgets::WidgetRef;
use crate::app_event_sender::AppEventSender;
+use crate::bottom_pane::BottomPane;
use crate::status_indicator_widget::StatusIndicatorWidget;
use super::BottomPaneView;
@@ -40,4 +43,10 @@ impl BottomPaneView<'_> for StatusIndicatorView {
fn render(&self, area: ratatui::layout::Rect, buf: &mut Buffer) {
self.view.render_ref(area, buf);
}
+
+ fn handle_key_event(&mut self, _pane: &mut BottomPane<'_>, key_event: KeyEvent) {
+ if key_event.code == KeyCode::Esc {
+ self.view.interrupt();
+ }
+ }
}
diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs
index 3d312ffce0..2c28446fb0 100644
--- a/codex-rs/tui/src/chatwidget.rs
+++ b/codex-rs/tui/src/chatwidget.rs
@@ -624,14 +624,6 @@ impl ChatWidget<'_> {
self.bottom_pane.on_file_search_result(query, matches);
}
- pub(crate) fn on_esc(&mut self) -> bool {
- if self.bottom_pane.is_task_running() {
- self.interrupt_running_task();
- return true;
- }
- false
- }
-
/// Handle Ctrl-C key press.
/// Returns CancellationEvent::Handled if the event was consumed by the UI, or
/// CancellationEvent::Ignored if the caller should handle it (e.g. exit).
diff --git a/codex-rs/tui/src/status_indicator_widget.rs b/codex-rs/tui/src/status_indicator_widget.rs
index 6ef293208d..b686f45d09 100644
--- a/codex-rs/tui/src/status_indicator_widget.rs
+++ b/codex-rs/tui/src/status_indicator_widget.rs
@@ -9,6 +9,7 @@ use std::thread;
use std::time::Duration;
use std::time::Instant;
+use codex_core::protocol::Op;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Color;
@@ -44,11 +45,7 @@ pub(crate) struct StatusIndicatorWidget {
frame_idx: Arc<AtomicUsize>,
running: Arc<AtomicBool>,
start_time: Instant,
- // Keep one sender alive to prevent the channel from closing while the
- // animation thread is still running. The field itself is currently not
- // accessed anywhere, therefore the leading underscore silences the
- // `dead_code` warning without affecting behavior.
- _app_event_tx: AppEventSender,
+ app_event_tx: AppEventSender,
}
impl StatusIndicatorWidget {
@@ -82,7 +79,7 @@ impl StatusIndicatorWidget {
running,
start_time: Instant::now(),
- _app_event_tx: app_event_tx,
+ app_event_tx,
}
}
@@ -120,6 +117,10 @@ impl StatusIndicatorWidget {
self.reveal_len_at_base = shown_now.min(new_len);
}
+ pub(crate) fn interrupt(&self) {
+ self.app_event_tx.send(AppEvent::CodexOp(Op::Interrupt));
+ }
+
/// Reset the animation and start revealing `text` from the beginning.
#[cfg(test)]
pub(crate) fn restart_with_text(&mut self, text: String) {