0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-04 01:44:26 -05:00

feat: allow exiting on two consecutive ctrl+c presses (#15981)

This commit is contained in:
Kayla Washburn 2022-09-22 02:42:09 -06:00 committed by GitHub
parent 388e880dd0
commit 1ef96343a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View file

@ -561,7 +561,7 @@ async fn inspector_runtime_evaluate_does_not_crash() {
assert_eq!( assert_eq!(
&stdout_lines.next().unwrap(), &stdout_lines.next().unwrap(),
"exit using ctrl+d or close()" "exit using ctrl+d, ctrl+c, or close()"
); );
assert_inspector_messages( assert_inspector_messages(

View file

@ -81,6 +81,7 @@ pub async fn run(
) -> Result<i32, AnyError> { ) -> Result<i32, AnyError> {
let mut repl_session = ReplSession::initialize(worker).await?; let mut repl_session = ReplSession::initialize(worker).await?;
let mut rustyline_channel = rustyline_channel(); let mut rustyline_channel = rustyline_channel();
let mut should_exit_on_interrupt = false;
let helper = EditorHelper { let helper = EditorHelper {
context_id: repl_session.context_id, context_id: repl_session.context_id,
@ -118,7 +119,7 @@ pub async fn run(
} }
println!("Deno {}", crate::version::deno()); println!("Deno {}", crate::version::deno());
println!("exit using ctrl+d or close()"); println!("exit using ctrl+d, ctrl+c, or close()");
loop { loop {
let line = read_line_and_poll( let line = read_line_and_poll(
@ -129,6 +130,7 @@ pub async fn run(
.await; .await;
match line { match line {
Ok(line) => { Ok(line) => {
should_exit_on_interrupt = false;
let output = repl_session.evaluate_line_and_get_output(&line).await?; 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 // 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); editor.add_history_entry(line);
} }
Err(ReadlineError::Interrupted) => { 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; continue;
} }
Err(ReadlineError::Eof) => { Err(ReadlineError::Eof) => {