Skip to content

Commit 329f01b

Browse files
authored
feat: allow esc to interrupt session (openai#2054)
## Summary - allow Esc to interrupt the current session when a task is running - document Esc as an interrupt key in status indicator ## Testing - `just fmt` - `just fix` *(fails: E0658 `let` expressions in this position are unstable)* - `cargo test --all-features` *(fails: E0658 `let` expressions in this position are unstable)* ------ https://chatgpt.com/codex/tasks/task_i_689698cf605883208f57b0317ff6a303
1 parent 4a916ba commit 329f01b

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

codex-rs/tui/src/app.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ impl App<'_> {
236236
self.app_event_tx.send(AppEvent::ExitRequest);
237237
}
238238
},
239+
KeyEvent {
240+
code: KeyCode::Esc,
241+
kind: KeyEventKind::Press,
242+
..
243+
} => match &mut self.app_state {
244+
AppState::Chat { widget } => {
245+
if !widget.on_esc() {
246+
self.dispatch_key_event(key_event);
247+
}
248+
}
249+
AppState::Onboarding { .. } => {
250+
self.dispatch_key_event(key_event);
251+
}
252+
},
239253
KeyEvent {
240254
code: KeyCode::Char('z'),
241255
modifiers: crossterm::event::KeyModifiers::CONTROL,

codex-rs/tui/src/chatwidget.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,14 @@ impl ChatWidget<'_> {
571571
self.bottom_pane.on_file_search_result(query, matches);
572572
}
573573

574+
pub(crate) fn on_esc(&mut self) -> bool {
575+
if self.bottom_pane.is_task_running() {
576+
self.interrupt_running_task();
577+
return true;
578+
}
579+
false
580+
}
581+
574582
/// Handle Ctrl-C key press.
575583
/// Returns CancellationEvent::Handled if the event was consumed by the UI, or
576584
/// CancellationEvent::Ignored if the caller should handle it (e.g. exit).

codex-rs/tui/src/status_indicator_widget.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,14 @@ impl WidgetRef for StatusIndicatorWidget {
231231
spans.extend(animated_spans);
232232
// Space between header and bracket block
233233
spans.push(Span::raw(" "));
234-
// Non-animated, dim bracket content, with only "Ctrl c" bold
234+
// Non-animated, dim bracket content, with keys bold
235235
let bracket_prefix = format!("({elapsed}s • ");
236236
spans.push(Span::styled(
237237
bracket_prefix,
238238
Style::default().fg(Color::Gray).add_modifier(Modifier::DIM),
239239
));
240240
spans.push(Span::styled(
241-
"Ctrl C",
241+
"Esc",
242242
Style::default()
243243
.fg(Color::Gray)
244244
.add_modifier(Modifier::DIM | Modifier::BOLD),

0 commit comments

Comments
 (0)