mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-18 01:40:34 +01:00
output: Remove wants_to_quit handling from print_entry()
Since we only check it once per path now, we might as well just check it before printing anything.
This commit is contained in:
parent
a4bb734482
commit
97a8825b00
2 changed files with 14 additions and 19 deletions
|
@ -1,7 +1,6 @@
|
|||
use std::borrow::Cow;
|
||||
use std::io::{self, Write};
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use lscolors::{Indicator, LsColors, Style};
|
||||
|
||||
|
@ -15,12 +14,7 @@ fn replace_path_separator(path: &str, new_path_separator: &str) -> String {
|
|||
}
|
||||
|
||||
// TODO: this function is performance critical and can probably be optimized
|
||||
pub fn print_entry<W: Write>(
|
||||
stdout: &mut W,
|
||||
entry: &Path,
|
||||
config: &Config,
|
||||
wants_to_quit: &AtomicBool,
|
||||
) {
|
||||
pub fn print_entry<W: Write>(stdout: &mut W, entry: &Path, config: &Config) {
|
||||
let path = if config.strip_cwd_prefix {
|
||||
strip_current_dir(entry)
|
||||
} else {
|
||||
|
@ -28,7 +22,7 @@ pub fn print_entry<W: Write>(
|
|||
};
|
||||
|
||||
let r = if let Some(ref ls_colors) = config.ls_colors {
|
||||
print_entry_colorized(stdout, path, config, ls_colors, wants_to_quit)
|
||||
print_entry_colorized(stdout, path, config, ls_colors)
|
||||
} else {
|
||||
print_entry_uncolorized(stdout, path, config)
|
||||
};
|
||||
|
@ -50,7 +44,6 @@ fn print_entry_colorized<W: Write>(
|
|||
path: &Path,
|
||||
config: &Config,
|
||||
ls_colors: &LsColors,
|
||||
wants_to_quit: &AtomicBool,
|
||||
) -> io::Result<()> {
|
||||
// Split the path between the parent and the last component
|
||||
let mut offset = 0;
|
||||
|
@ -92,12 +85,6 @@ fn print_entry_colorized<W: Write>(
|
|||
writeln!(stdout)?;
|
||||
}
|
||||
|
||||
if wants_to_quit.load(Ordering::Relaxed) {
|
||||
// Ignore any errors on flush, because we're about to exit anyway
|
||||
let _ = stdout.flush();
|
||||
ExitCode::KilledBySigint.exit();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
16
src/walk.rs
16
src/walk.rs
|
@ -244,7 +244,7 @@ impl<W: Write> ReceiverBuffer<W> {
|
|||
}
|
||||
}
|
||||
ReceiverMode::Streaming => {
|
||||
self.print(&path);
|
||||
self.print(&path)?;
|
||||
self.flush()?;
|
||||
}
|
||||
}
|
||||
|
@ -273,8 +273,16 @@ impl<W: Write> ReceiverBuffer<W> {
|
|||
}
|
||||
|
||||
/// Output a path.
|
||||
fn print(&mut self, path: &Path) {
|
||||
output::print_entry(&mut self.stdout, path, &self.config, &self.wants_to_quit)
|
||||
fn print(&mut self, path: &Path) -> Result<(), ExitCode> {
|
||||
output::print_entry(&mut self.stdout, path, &self.config);
|
||||
|
||||
if self.wants_to_quit.load(Ordering::Relaxed) {
|
||||
// Ignore any errors on flush, because we're about to exit anyway
|
||||
let _ = self.flush();
|
||||
return Err(ExitCode::KilledBySigint);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Switch ourselves into streaming mode.
|
||||
|
@ -283,7 +291,7 @@ impl<W: Write> ReceiverBuffer<W> {
|
|||
|
||||
let buffer = mem::take(&mut self.buffer);
|
||||
for path in buffer {
|
||||
self.print(&path);
|
||||
self.print(&path)?;
|
||||
}
|
||||
|
||||
self.flush()
|
||||
|
|
Loading…
Reference in a new issue