summaryrefslogtreecommitdiff
path: root/cli/tools/repl/mod.rs
diff options
context:
space:
mode:
authorKayla Washburn <mckayla@hey.com>2022-09-22 02:42:09 -0600
committerGitHub <noreply@github.com>2022-09-22 04:42:09 -0400
commit1ef96343a1fb243fb7e9dc96a060ac35ce87d7c2 (patch)
tree045374510eac2227ab1457b6a382d0d36b5629c8 /cli/tools/repl/mod.rs
parent388e880dd06bd3b3d1bee0ab12665eb0eda98e9e (diff)
feat: allow exiting on two consecutive ctrl+c presses (#15981)
Diffstat (limited to 'cli/tools/repl/mod.rs')
-rw-r--r--cli/tools/repl/mod.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs
index 110a89f14..c8efd3d95 100644
--- a/cli/tools/repl/mod.rs
+++ b/cli/tools/repl/mod.rs
@@ -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) => {