diff options
author | Andrew Gallant <jamslam@gmail.com> | 2016-10-29 21:54:18 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2016-10-29 21:54:18 -0400 |
commit | 811fcc1fe80e32916350888f4e6923cc2488901a (patch) | |
tree | cc92c3ac9335fe55abfcb41f3ce4bbdaa064c9c5 | |
parent | fbf8265cded97bf4743563249181641b1b17188e (diff) | |
parent | 79a8d0ab3f75be2d30a8c55ae97dfd858e583be8 (diff) |
Merge branch 'ctrlc-reset-terminal'
-rw-r--r-- | Cargo.lock | 12 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 14 |
3 files changed, 27 insertions, 0 deletions
@@ -2,6 +2,7 @@ name = "ripgrep" version = "0.2.3" dependencies = [ + "ctrlc 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 0.6.86 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -29,6 +30,16 @@ dependencies = [ ] [[package]] +name = "ctrlc" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "deque" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -251,6 +262,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" +"checksum ctrlc 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77f98bb69e3fefadcc5ca80a1368a55251f70295168203e01165bcaecb270891" "checksum deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1614659040e711785ed8ea24219140654da1729f3ec8a47a9719d041112fe7bf" "checksum docopt 0.6.86 (registry+https://github.com/rust-lang/crates.io-index)" = "4a7ef30445607f6fc8720f0a0a2c7442284b629cf0d049286860fae23e71c4d9" "checksum env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f" @@ -24,6 +24,7 @@ name = "integration" path = "tests/tests.rs" [dependencies] +ctrlc = "2.0" deque = "0.3" docopt = "0.6" env_logger = "0.3" diff --git a/src/main.rs b/src/main.rs index e64ddf9c..71c4da32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +extern crate ctrlc; extern crate deque; extern crate docopt; extern crate env_logger; @@ -22,6 +23,7 @@ extern crate winapi; use std::error::Error; use std::fs::File; use std::io; +use std::io::Write; use std::path::Path; use std::process; use std::result; @@ -82,6 +84,18 @@ fn main() { fn run(args: Args) -> Result<u64> { let args = Arc::new(args); + + let handler_args = args.clone(); + ctrlc::set_handler(move || { + let stdout = io::stdout(); + let mut stdout = stdout.lock(); + + let _ = handler_args.stdout().reset(); + let _ = stdout.flush(); + + process::exit(1); + }); + let paths = args.paths(); let threads = cmp::max(1, args.threads() - 1); let isone = |