Skip to content

Commit

Permalink
Merge pull request #54 from nevdelap/issue53
Browse files Browse the repository at this point in the history
Issue 53: --colors=always needs to take into account replace.
  • Loading branch information
nevdelap authored Jul 31, 2018
2 parents 0728a9a + 59af694 commit 7f48e62
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ned"
version = "1.2.3"
version = "1.2.4"
authors = ["Nev Delap <[email protected]>"]

[dependencies]
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://gnu.org/licenses/gpl.html>.
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)
Expand Down
4 changes: 2 additions & 2 deletions src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 24 additions & 4 deletions src/tests/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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"];

Expand All @@ -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"];

Expand Down Expand Up @@ -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 \
Expand Down

0 comments on commit 7f48e62

Please sign in to comment.