fix(tui/auto-drive): align Esc edit/stop behavior · nirbo/code@5777f19 · GitHub
Skip to content

Commit 5777f19

Browse files
committed
fix(tui/auto-drive): align Esc edit/stop behavior
1 parent 8aba6b6 commit 5777f19

3 files changed

Lines changed: 55 additions & 30 deletions

File tree

‎code-rs/code-auto-drive-core/src/controller.rs‎

Lines changed: 1 addition & 1 deletion

‎code-rs/tui/src/chatwidget.rs‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ use crate::history::compat::{
219219
};
220220

221221
pub(crate) const DOUBLE_ESC_HINT: &str = "undo timeline";
222-
const AUTO_ESC_EXIT_HINT: &str = "Press Esc again to exit Auto Drive";
222+
const AUTO_ESC_EXIT_HINT: &str = "Press Esc to exit Auto Drive";
223+
const AUTO_ESC_EXIT_HINT_DOUBLE: &str = "Press Esc again to exit Auto Drive";
223224
const AUTO_COMPLETION_CELEBRATION_DURATION: Duration = Duration::from_secs(5);
224225
const HISTORY_ANIMATION_FRAME_INTERVAL: Duration = Duration::from_millis(120);
225226
const AUTO_BOOTSTRAP_GOAL_PLACEHOLDER: &str = "Deriving goal from recent conversation";
@@ -3730,7 +3731,7 @@ impl ChatWidget<'_> {
37303731
} else if self
37313732
.bottom_pane
37323733
.standard_terminal_hint()
3733-
.is_some_and(|hint| hint == AUTO_ESC_EXIT_HINT)
3734+
.is_some_and(|hint| hint == AUTO_ESC_EXIT_HINT || hint == AUTO_ESC_EXIT_HINT_DOUBLE)
37343735
{
37353736
self.bottom_pane.set_standard_terminal_hint(None);
37363737
}
@@ -18653,7 +18654,7 @@ Have we met every part of this goal and is there no further work to do?"#
1865318654
self.bottom_pane
1865418655
.update_status_text("Auto Drive paused".to_string());
1865518656
self.bottom_pane.set_standard_terminal_hint(Some(
18656-
"Press Esc again to exit Auto Drive".to_string(),
18657+
AUTO_ESC_EXIT_HINT.to_string(),
1865718658
));
1865818659
let message = format!(
1865918660
"Auto Drive will retry automatically in {human_delay} (attempt {attempt}). Last error: {reason}"
@@ -19740,6 +19741,7 @@ Have we met every part of this goal and is there no further work to do?"#
1974019741
.clone()
1974119742
.filter(|value| !value.trim().is_empty())
1974219743
};
19744+
let has_cli_prompt = cli_prompt.is_some();
1974319745

1974419746
let bootstrap_pending = self.auto_pending_goal_request;
1974519747
let continue_cta_active = self.auto_should_show_continue_cta();
@@ -19758,7 +19760,6 @@ Have we met every part of this goal and is there no further work to do?"#
1975819760
};
1975919761

1976019762
let button = if self.auto_state.awaiting_coordinator_submit() {
19761-
let has_cli_prompt = cli_prompt.is_some();
1976219763
let base_label = if bootstrap_pending {
1976319764
"Complete Current Task"
1976419765
} else if has_cli_prompt {
@@ -19786,23 +19787,28 @@ Have we met every part of this goal and is there no further work to do?"#
1978619787
Some("Edit the prompt, then press Enter to continue.".to_string())
1978719788
} else if bootstrap_pending {
1978819789
None
19790+
} else if has_cli_prompt {
19791+
if countdown_active {
19792+
Some("Enter to send now • Esc to edit".to_string())
19793+
} else {
19794+
Some("Enter to send • Esc to edit".to_string())
19795+
}
1978919796
} else if continue_cta_active {
1979019797
if countdown_active {
1979119798
Some("Enter to continue now • Esc to stop".to_string())
1979219799
} else {
1979319800
Some("Enter to continue • Esc to stop".to_string())
1979419801
}
1979519802
} else if countdown_active {
19796-
Some("Enter to send now • Esc to edit".to_string())
19803+
Some("Enter to send now • Esc to stop".to_string())
1979719804
} else {
19798-
Some("Enter to send • Esc to edit".to_string())
19805+
Some("Enter to send • Esc to stop".to_string())
1979919806
}
1980019807
} else {
1980119808
None
1980219809
};
1980319810

1980419811
let ctrl_switch_hint = if self.auto_state.awaiting_coordinator_submit() {
19805-
let has_cli_prompt = cli_prompt.is_some();
1980619812
if self.auto_state.is_paused_manual() {
1980719813
"Esc to cancel".to_string()
1980819814
} else if bootstrap_pending {
@@ -19812,7 +19818,7 @@ Have we met every part of this goal and is there no further work to do?"#
1981219818
} else if continue_cta_active {
1981319819
"Esc to stop".to_string()
1981419820
} else {
19815-
"Esc to edit".to_string()
19821+
"Esc to stop".to_string()
1981619822
}
1981719823
} else if self.auto_state.is_waiting_for_response() {
1981819824
String::new()
@@ -30083,6 +30089,19 @@ use code_core::protocol::OrderMeta;
3008330089
assert!(!route.allows_double_esc);
3008430090
}
3008530091

30092+
#[test]
30093+
fn esc_router_stops_auto_drive_while_waiting_for_response() {
30094+
let mut harness = ChatWidgetHarness::new();
30095+
let chat = harness.chat();
30096+
30097+
chat.auto_state.set_phase(AutoRunPhase::Active);
30098+
chat.auto_state.set_coordinator_waiting(true);
30099+
30100+
let route = chat.describe_esc_context();
30101+
assert_eq!(route.intent, EscIntent::AutoStopActive);
30102+
assert!(!route.allows_double_esc);
30103+
}
30104+
3008630105
#[test]
3008730106
fn esc_router_prioritizes_cli_interrupt_before_agent_cancel() {
3008830107
let mut harness = ChatWidgetHarness::new();

‎code-rs/tui/src/chatwidget/esc.rs‎

Lines changed: 27 additions & 21 deletions

0 commit comments

Comments
 (0)