Skip to content

Commit

Permalink
Merge pull request chmln#126 from Linus789/fix_recursive_preview
Browse files Browse the repository at this point in the history
Fix recursive preview (show file path)
  • Loading branch information
chmln authored May 8, 2021
2 parents f0e3961 + 0b11f3e commit 4ccc522
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl App {
(Source::Files(paths), true) => {
let stdout = std::io::stdout();
let mut handle = stdout.lock();
let print_path = paths.len() > 1;

paths.iter().try_for_each(|path| {
if let Err(_) = Replacer::check_not_empty(File::open(path)?)
Expand All @@ -78,8 +79,17 @@ impl App {
let file =
unsafe { memmap::Mmap::map(&File::open(path)?)? };
if self.replacer.has_matches(&file) {
if print_path {
writeln!(
handle,
"----- FILE {} -----",
path.display()
)?;
}

handle
.write_all(&self.replacer.replace_preview(&file))?;
writeln!(handle)?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod cli {
.assert()
.success()
.stdout(format!(
"{}{}def",
"{}{}def\n",
ansi_term::Color::Green.prefix().to_string(),
ansi_term::Color::Green.suffix().to_string()
));
Expand Down

0 comments on commit 4ccc522

Please sign in to comment.