Merge pull request #126 from Linus789/fix_recursive_preview

Fix recursive preview (show file path)
This commit is contained in:
Gregory 2021-05-07 20:58:47 -04:00 committed by GitHub
commit 4ccc52203a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -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)?)
@ -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(())

View file

@ -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()
));