Skip to content

Commit

Permalink
don't duplicate text after prefix when --color is used along --prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowwa committed Oct 11, 2024
1 parent 404c9cb commit 2287501
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/devicon_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl ParsedLine {
format!("{} {}", icon, path_name)
};

if args.flag_substitute || args.flag_prefix.is_some() {
if args.flag_substitute || (args.flag_prefix.is_some() && !args.flag_color) {
s = self.original.replace(self.file.full_path(), &s);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/strip_ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ mod integration {
.stdout(" \x1b[34mtest.rs\x1B[0m\n");
}

#[test]
fn calling_devicon_lookup_with_strip_color_single_file_and_prefix() {
colored::control::set_override(true);

let mut cmd = Command::cargo_bin("devicon-lookup").unwrap();
cmd.arg("--color")
.arg("--prefix")
.arg(":");
cmd.write_stdin("test.rs: someline of the file".blue().to_string())
.assert()
.stdout(" \x1b[34mtest.rs: someline of the file\x1B[0m\n");
}

#[test]
fn calling_devicon_lookup_with_strip_color_multi_file() {
colored::control::set_override(true);
Expand Down

0 comments on commit 2287501

Please sign in to comment.