Fix recursive preview (show file path)

This commit is contained in:
Linus789 2021-05-07 18:59:29 +02:00
parent f0e396157b
commit 0b11f3e84a
2 changed files with 11 additions and 1 deletions

View file

@ -69,6 +69,7 @@ impl App {
(Source::Files(paths), true) => { (Source::Files(paths), true) => {
let stdout = std::io::stdout(); let stdout = std::io::stdout();
let mut handle = stdout.lock(); let mut handle = stdout.lock();
let print_path = paths.len() > 1;
paths.iter().try_for_each(|path| { paths.iter().try_for_each(|path| {
if let Err(_) = Replacer::check_not_empty(File::open(path)?) if let Err(_) = Replacer::check_not_empty(File::open(path)?)
@ -78,8 +79,17 @@ impl App {
let file = let file =
unsafe { memmap::Mmap::map(&File::open(path)?)? }; unsafe { memmap::Mmap::map(&File::open(path)?)? };
if self.replacer.has_matches(&file) { if self.replacer.has_matches(&file) {
if print_path {
writeln!(
handle,
"----- FILE {} -----",
path.display()
)?;
}
handle handle
.write_all(&self.replacer.replace_preview(&file))?; .write_all(&self.replacer.replace_preview(&file))?;
writeln!(handle)?;
} }
Ok(()) Ok(())

View file

@ -82,7 +82,7 @@ mod cli {
.assert() .assert()
.success() .success()
.stdout(format!( .stdout(format!(
"{}{}def", "{}{}def\n",
ansi_term::Color::Green.prefix().to_string(), ansi_term::Color::Green.prefix().to_string(),
ansi_term::Color::Green.suffix().to_string() ansi_term::Color::Green.suffix().to_string()
)); ));