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
37 changes: 37 additions & 0 deletions src/cortex-tui/src/app/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ impl AppState {

/// Handle Ctrl+C press (double-tap to quit)
pub fn handle_ctrl_c(&mut self) -> bool {
self.reset_esc();

let now = Instant::now();
if let Some(last) = self.last_ctrl_c
&& now.duration_since(last) < Duration::from_millis(500)
Expand All @@ -183,6 +185,8 @@ impl AppState {

/// Handle ESC press (double-tap to quit when idle)
pub fn handle_esc(&mut self) -> bool {
self.reset_ctrl_c();

let now = Instant::now();
if let Some(last) = self.last_esc
&& now.duration_since(last) < Duration::from_millis(500)
Expand All @@ -200,6 +204,39 @@ impl AppState {
}
}

#[cfg(test)]
mod tests {
use super::AppState;

#[test]
fn test_esc_resets_ctrl_c_quit_confirmation() {
let mut app_state = AppState::new();

assert!(!app_state.handle_ctrl_c());
assert!(app_state.last_ctrl_c.is_some());

assert!(!app_state.handle_esc());
assert!(app_state.last_ctrl_c.is_none());

assert!(!app_state.handle_ctrl_c());
assert!(!app_state.should_quit());
}

#[test]
fn test_ctrl_c_resets_esc_quit_confirmation() {
let mut app_state = AppState::new();

assert!(!app_state.handle_esc());
assert!(app_state.last_esc.is_some());

assert!(!app_state.handle_ctrl_c());
assert!(app_state.last_esc.is_none());

assert!(!app_state.handle_esc());
assert!(!app_state.should_quit());
}
}

// ============================================================================
// APPSTATE METHODS - Modals
// ============================================================================
Expand Down
2 changes: 2 additions & 0 deletions src/cortex-tui/src/runner/event_loop/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ impl EventLoop {

/// Handle ESC key with double-tap to quit
fn handle_esc(&mut self, terminal: &mut CortexTerminal) -> Result<()> {
self.app_state.reset_ctrl_c();

// Priority 1: If viewing a subagent conversation, return to main conversation
if self.app_state.is_viewing_subagent() {
self.app_state.return_to_main_conversation();
Expand Down