1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-03-13 14:18:35 +00:00

return immediately once broken pipe happens

This commit is contained in:
rleungx 2018-05-02 23:19:56 +08:00
parent f4653d9b0d
commit 1455d7d3ad

View File

@ -382,11 +382,23 @@ fn run() -> Result<()> {
let mut exit = false;
for file in files {
let line_changes = get_git_diff(&file.to_string());
print_file(&options, theme, &assets.syntax_set, file, &line_changes)
.unwrap_or_else(|e| {
exit = true;
eprintln!("{}: {}: {}", Red.paint("[bat error]"), file, e);
});
let res = print_file(&options, theme, &assets.syntax_set, file, &line_changes);
if let Err(error) = res {
if match error {
Error(ErrorKind::Io(ref io_error), _)
if io_error.kind() == io::ErrorKind::BrokenPipe =>
{
true
}
_ => {
exit = true;
eprintln!("{}: {}: {}", Red.paint("[bat error]"), file, error);
false
}
} {
return Err(error);
}
}
}
if exit {
process::exit(1);