mirror of
https://github.com/chmln/sd
synced 2024-11-22 11:13:04 +00:00
Fix recursive preview (show file path)
This commit is contained in:
parent
f0e396157b
commit
0b11f3e84a
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) => {
|
(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(())
|
||||||
|
|
|
@ -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()
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in a new issue