diff options
author | Andrew Gallant <jamslam@gmail.com> | 2016-12-24 12:53:09 -0500 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2016-12-24 12:53:09 -0500 |
commit | de5cb7d22e00c18dfce082a68b0cf45924b56e7f (patch) | |
tree | 74dcc51d61e2b71bea02265d365504f17bcd39e9 /src/main.rs | |
parent | 7a682f465e74d31ade4cb96c8d32110d33deebd7 (diff) |
Remove special ^C handling.
This means that ripgrep will no longer try to reset your colors in your
terminal if you kill it while searching. This could result in messing up
the colors in your terminal, and the fix is to simply run some other
command that resets them for you. For example:
$ echo -ne "\033[0m"
The reason why the ^C handling was removed is because it is irrevocably
broken on Windows and is impossible to do correctly and efficiently in
ANSI terminals.
Fixes #281
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 56 |
1 files changed, 2 insertions, 54 deletions
diff --git a/src/main.rs b/src/main.rs index a26812b1..236c093e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ extern crate bytecount; #[macro_use] extern crate clap; -extern crate ctrlc; extern crate env_logger; extern crate grep; extern crate ignore; @@ -21,16 +20,13 @@ extern crate termcolor; extern crate winapi; use std::error::Error; -use std::io::Write; use std::process; use std::result; use std::sync::Arc; -use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::mpsc; use std::thread; -use termcolor::WriteColor; - use args::Args; use worker::Work; @@ -74,15 +70,6 @@ fn run(args: Arc<Args>) -> Result<u64> { if args.never_match() { return Ok(0); } - { - let args = args.clone(); - ctrlc::set_handler(move || { - let mut writer = args.stdout(); - let _ = writer.reset(); - let _ = writer.flush(); - process::exit(1); - }); - } let threads = args.threads(); if args.files() { if threads == 1 || args.is_one_path() { @@ -101,7 +88,7 @@ fn run(args: Arc<Args>) -> Result<u64> { fn run_parallel(args: Arc<Args>) -> Result<u64> { let bufwtr = Arc::new(args.buffer_writer()); - let quiet_matched = QuietMatched::new(args.quiet()); + let quiet_matched = args.quiet_matched(); let paths_searched = Arc::new(AtomicUsize::new(0)); let match_count = Arc::new(AtomicUsize::new(0)); @@ -281,42 +268,3 @@ fn eprint_nothing_searched() { applied a filter you didn't expect. \ Try running again with --debug."); } - -/// A simple thread safe abstraction for determining whether a search should -/// stop if the user has requested quiet mode. -#[derive(Clone, Debug)] -pub struct QuietMatched(Arc<Option<AtomicBool>>); - -impl QuietMatched { - /// Create a new QuietMatched value. - /// - /// If quiet is true, then set_match and has_match will reflect whether - /// a search should quit or not because it found a match. - /// - /// If quiet is false, then set_match is always a no-op and has_match - /// always returns false. - pub fn new(quiet: bool) -> QuietMatched { - let atomic = if quiet { Some(AtomicBool::new(false)) } else { None }; - QuietMatched(Arc::new(atomic)) - } - - /// Returns true if and only if quiet mode is enabled and a match has - /// occurred. - pub fn has_match(&self) -> bool { - match *self.0 { - None => false, - Some(ref matched) => matched.load(Ordering::SeqCst), - } - } - - /// Sets whether a match has occurred or not. - /// - /// If quiet mode is disabled, then this is a no-op. - pub fn set_match(&self, yes: bool) -> bool { - match *self.0 { - None => false, - Some(_) if !yes => false, - Some(ref m) => { m.store(true, Ordering::SeqCst); true } - } - } -} |