Skip to content

Commit

Permalink
Avoid accidental program exits (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Mar 10, 2023
1 parent 9aea2e7 commit 89f83e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ata"
version = "2.0.0"
version = "2.0.1"
edition = "2021"
authors = ["Rik Huijzer <t.h.huijzer@rug.nl>", "Fredrick R. Brennan <copypaste@kittens.ph>"]
license = "MIT"
Expand Down
14 changes: 13 additions & 1 deletion ata/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ impl ConditionalEventHandler for ClearEventHandler {
}
}

static HAD_FIRST_INTERRUPT: AtomicBool = AtomicBool::new(false);

fn main() -> prompt::TokioResult<()> {
let args: Vec<String> = env::args().collect();
let flags: Flags = Flags::parse();
Expand Down Expand Up @@ -174,12 +176,22 @@ fn main() -> prompt::TokioResult<()> {
}
rl.add_history_entry(line.as_str());
tx.send(line).unwrap();
HAD_FIRST_INTERRUPT.store(false, Ordering::Relaxed);
}
Err(ReadlineError::Interrupted) => {
if is_running_clone.load(Ordering::SeqCst) {
abort.store(true, Ordering::SeqCst);
} else {
break;
if !HAD_FIRST_INTERRUPT.load(Ordering::Relaxed) {
HAD_FIRST_INTERRUPT.store(true, Ordering::Relaxed);
println!("\nPress Ctrl-C again to exit.");
thread::sleep(Duration::from_millis(100));
println!();
prompt::print_prompt();
continue;
} else {
break;
}
}
}
Err(ReadlineError::Eof) => break,
Expand Down

1 comment on commit 89f83e5

@ctrlcctrlv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have been configurable. consider backporting c38ccf2

Please sign in to comment.