From 57476671edcef6254240a1474cb58531ac48341b Mon Sep 17 00:00:00 2001 From: Justine Date: Mon, 20 Feb 2023 14:41:54 +0100 Subject: [PATCH] Now handling CtrlC properly --- Cargo.toml | 1 + src/lib.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7e78106..219c32b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ unicode-segmentation = "1.6.0" which = { version = "4.4.0", features = ["regex"] } regex = "1.7.1" yaml-rust = "0.4.5" +ctrlc = "3.2.5" diff --git a/src/lib.rs b/src/lib.rs index 7a43095..c3be450 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,6 +30,8 @@ pub mod shell { //used for home directory extern crate dirs; + extern crate ctrlc; + fn process_line(input: &str) -> String { @@ -112,7 +114,7 @@ pub mod shell { .expect("Failed to wait on child"); let status = output.status .code() - .expect("Could not get retcode") + .unwrap_or(255) .to_string(); previous_command = None; let format_res = format!("{}", @@ -290,6 +292,11 @@ pub mod shell { let mut current_pos: usize = 0; let mut max_pos: usize = 0; + //Handle Ctrl+C + ctrlc::set_handler(|| { + (); + }).unwrap(); + let mut conf = match SqishConf::from_sqishrc() { Ok(c) => c, Err(e) => {