Skip to content

Commit 58537aa

Browse files
feat: dont exit on first ctrl c when at the prompt (#830)
1 parent 9bc2c8b commit 58537aa

File tree

1 file changed

+19
-3
lines changed
  • crates/q_cli/src/cli/chat

1 file changed

+19
-3
lines changed

crates/q_cli/src/cli/chat/mod.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,26 @@ where
473473
style::SetForegroundColor(Color::Reset),
474474
)?;
475475
}
476-
let user_input = match self.input_source.read_line(Some("> "))? {
477-
Some(line) => line,
478-
None => return Ok(ChatState::Exit),
476+
477+
// Require two consecutive sigint's to exit.
478+
let mut ctrl_c = false;
479+
let user_input = loop {
480+
match (self.input_source.read_line(Some("> "))?, ctrl_c) {
481+
(Some(line), _) => break line,
482+
(None, false) => {
483+
execute!(
484+
self.output,
485+
style::Print(format!(
486+
"\n(To exit, press Ctrl+C or Ctrl+D again or type {})\n\n",
487+
"/quit".green()
488+
))
489+
)?;
490+
ctrl_c = true;
491+
},
492+
(None, true) => return Ok(ChatState::Exit),
493+
}
479494
};
495+
480496
Ok(ChatState::HandleInput {
481497
input: user_input,
482498
tool_uses: Some(tool_uses),

0 commit comments

Comments
 (0)