mirror of
https://github.com/chmln/sd
synced 2024-11-29 14:30:20 +00:00
Merge pull request #126 from Linus789/fix_recursive_preview
Fix recursive preview (show file path)
This commit is contained in:
commit
4ccc52203a
2 changed files with 11 additions and 1 deletions
10
src/input.rs
10
src/input.rs
|
@ -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(())
|
||||
|
|
|
@ -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()
|
||||
));
|
||||
|
|
Loading…
Reference in a new issue