diff --git a/Cargo.lock b/Cargo.lock index 388338c..723739c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,12 +57,27 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "block2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" +dependencies = [ + "objc2", +] + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "clap" version = "4.5.48" @@ -122,6 +137,17 @@ dependencies = [ "windows-sys 0.61.1", ] +[[package]] +name = "ctrlc" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73736a89c4aff73035ba2ed2e565061954da00d4970fc9ac25dcc85a2a20d790" +dependencies = [ + "dispatch2", + "nix", + "windows-sys 0.61.1", +] + [[package]] name = "dialoguer" version = "0.12.0" @@ -134,6 +160,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "dispatch2" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" +dependencies = [ + "bitflags", + "block2", + "libc", + "objc2", +] + [[package]] name = "encode_unicode" version = "1.0.0" @@ -185,6 +223,7 @@ name = "lacy" version = "0.6.0" dependencies = [ "clap", + "ctrlc", "dialoguer", "tempfile", "upon", @@ -202,6 +241,33 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +[[package]] +name = "nix" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "objc2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c2599ce0ec54857b29ce62166b0ed9b4f6f1a70ccc9a71165b6154caca8c05" +dependencies = [ + "objc2-encode", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + [[package]] name = "once_cell" version = "1.20.2" diff --git a/Cargo.toml b/Cargo.toml index 5235168..7cabb02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ keywords = ["cli", "tool", "utility"] [dependencies] clap = { version = "4.5.48", features = ["derive"] } +ctrlc = { version = "3.5.1", features = ["termination"] } dialoguer = "0.12.0" upon = "0.10.0" diff --git a/src/cmd/prompt.rs b/src/cmd/prompt.rs index 9e5ca23..99a1d3b 100644 --- a/src/cmd/prompt.rs +++ b/src/cmd/prompt.rs @@ -62,6 +62,14 @@ impl Run for Prompt { println!("{}", paths.join("\n")); return; } + + // Prevents cursor from being hidden when canceling + // the selection. (See #58) + let _ = ctrlc::set_handler(move || { + let term = dialoguer::console::Term::stderr(); + let _ = term.show_cursor(); + std::process::exit(1); + }); if let Some(selected) = ui::select("Multiple possibilities found!", paths) { println!("{}", selected); } diff --git a/src/ui.rs b/src/ui.rs index c268cba..6cdd4cd 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -6,7 +6,8 @@ pub fn select(title: &str, options: Vec) -> Option { .items(&options) .default(0) .interact_opt() - .unwrap() + .ok() + .flatten() { return Some(options[selection].to_string()); }