mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
feat: allow exiting on two consecutive ctrl+c presses (#15981)
This commit is contained in:
parent
388e880dd0
commit
1ef96343a1
2 changed files with 9 additions and 3 deletions
|
@ -561,7 +561,7 @@ async fn inspector_runtime_evaluate_does_not_crash() {
|
|||
|
||||
assert_eq!(
|
||||
&stdout_lines.next().unwrap(),
|
||||
"exit using ctrl+d or close()"
|
||||
"exit using ctrl+d, ctrl+c, or close()"
|
||||
);
|
||||
|
||||
assert_inspector_messages(
|
||||
|
|
|
@ -81,6 +81,7 @@ pub async fn run(
|
|||
) -> Result<i32, AnyError> {
|
||||
let mut repl_session = ReplSession::initialize(worker).await?;
|
||||
let mut rustyline_channel = rustyline_channel();
|
||||
let mut should_exit_on_interrupt = false;
|
||||
|
||||
let helper = EditorHelper {
|
||||
context_id: repl_session.context_id,
|
||||
|
@ -118,7 +119,7 @@ pub async fn run(
|
|||
}
|
||||
|
||||
println!("Deno {}", crate::version::deno());
|
||||
println!("exit using ctrl+d or close()");
|
||||
println!("exit using ctrl+d, ctrl+c, or close()");
|
||||
|
||||
loop {
|
||||
let line = read_line_and_poll(
|
||||
|
@ -129,6 +130,7 @@ pub async fn run(
|
|||
.await;
|
||||
match line {
|
||||
Ok(line) => {
|
||||
should_exit_on_interrupt = false;
|
||||
let output = repl_session.evaluate_line_and_get_output(&line).await?;
|
||||
|
||||
// We check for close and break here instead of making it a loop condition to get
|
||||
|
@ -142,7 +144,11 @@ pub async fn run(
|
|||
editor.add_history_entry(line);
|
||||
}
|
||||
Err(ReadlineError::Interrupted) => {
|
||||
println!("exit using ctrl+d or close()");
|
||||
if should_exit_on_interrupt {
|
||||
break;
|
||||
}
|
||||
should_exit_on_interrupt = true;
|
||||
println!("press ctrl+c again to exit");
|
||||
continue;
|
||||
}
|
||||
Err(ReadlineError::Eof) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue