diff --git a/Cargo.lock b/Cargo.lock index d9a1fab..bcb0ab3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,7 +44,7 @@ dependencies = [ [[package]] name = "ned" -version = "1.2.3" +version = "1.2.4" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index ce1c879..c9000c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ned" -version = "1.2.3" +version = "1.2.4" authors = ["Nev Delap "] [dependencies] diff --git a/README.md b/README.md index 7a9a160..d5bb21b 100644 --- a/README.md +++ b/README.md @@ -95,13 +95,12 @@ Quiet: as many files as needed to find a match. Even without this shortcutting behaviour quiet matches are more performant than non-quiet matches. -ned 1.2.3 Copyright (C) 2016-2018 Nev Delap - https://github.com/nevdelap/ned +ned 1.2.4 Copyright (C) 2016-2018 Nev Delap - https://github.com/nevdelap/ned License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. - ``` # I.A.Q. (Infrequently Asked Questions) diff --git a/src/parameters.rs b/src/parameters.rs index 3378ee1..54d164c 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -88,8 +88,8 @@ pub fn get_parameters(options_with_defaults: &OptionsWithDefaults) -> NedResult< let colors = parse_opt_str(&options_with_defaults, "colors", Some(Colors::Off))? .expect("The default is a Some."); - let colors = (colors == Colors::Always - || colors != Colors::Off && (stdout || replace.is_none()) && isatty) + let colors = (colors == Colors::Always && (replace.is_none() || replace.is_some() && stdout) + || colors == Colors::Auto && (replace.is_none() || stdout) && isatty) && colors != Colors::Never; // -C --context takes precedence over -B --before and -A --after. diff --git a/src/tests/general.rs b/src/tests/general.rs index 60330dc..5311e04 100644 --- a/src/tests/general.rs +++ b/src/tests/general.rs @@ -504,7 +504,12 @@ fn colored_match() { #[test] fn colored_match_whole_files() { - let args = vec!["accidentally.*hand", "test", "--whole-files", "--colors=always"]; + let args = vec![ + "accidentally.*hand", + "test", + "--whole-files", + "--colors=always", + ]; let expected_exit_code = 0; let expected_screen_output = [ "\u{1b}[35mtest/file1.txt:\n\u{1b}[0mThe \u{1b}[1;31maccidentally ghastly hand\u{1b}[0m \ @@ -520,7 +525,12 @@ fn colored_match_whole_files() { #[test] fn colored_match_file_names_only() { - let args = vec!["accidentally.*hand", "test", "--colors=always", "--filenames-only"]; + let args = vec![ + "accidentally.*hand", + "test", + "--colors=always", + "--filenames-only", + ]; let expected_exit_code = 0; let expected_screen_output = ["\u{1b}[35mtest/file1.txt\n\u{1b}[0m"]; @@ -544,7 +554,12 @@ fn colored_match_file_names_only_whole_files() { #[test] fn colored_match_line_numbers_only() { - let args = vec!["rejoices.*hand", "test", "--colors=always", "--line-numbers-only"]; + let args = vec![ + "rejoices.*hand", + "test", + "--colors=always", + "--line-numbers-only", + ]; let expected_exit_code = 0; let expected_screen_output = ["\u{1b}[35m2\n\u{1b}[0m"]; @@ -575,7 +590,12 @@ fn colored_match_no_file_names_whole_files() { #[test] fn colored_match_no_file_names() { - let args = vec!["accidentally.*hand", "test", "--colors=always", "--no-filenames"]; + let args = vec![ + "accidentally.*hand", + "test", + "--colors=always", + "--no-filenames", + ]; let expected_exit_code = 0; let expected_screen_output = ["\u{1b}[35m1:\u{1b}[0mThe \u{1b}[1;31maccidentally ghastly \ hand\u{1b}[0m plans AN ESCAPE from a cream puff the placid \