fix: end quietly when a reader leaves the pipe early
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
use std::fmt::Arguments;
|
||||
use std::io::{self, Write};
|
||||
|
||||
// progress, on stderr and only when it was asked for
|
||||
macro_rules! note {
|
||||
($ctx:expr, $($arg:tt)*) => {
|
||||
@@ -12,4 +15,29 @@ macro_rules! warning {
|
||||
($($arg:tt)*) => { eprintln!("warning: {}", format_args!($($arg)*)) };
|
||||
}
|
||||
|
||||
pub(crate) use {note, warning};
|
||||
// what a command was asked for, on stdout
|
||||
macro_rules! line {
|
||||
($($arg:tt)*) => { $crate::output::write_line(format_args!($($arg)*)) };
|
||||
}
|
||||
|
||||
// the same, for a caller that terminates its own entries
|
||||
macro_rules! text {
|
||||
($($arg:tt)*) => { $crate::output::write_text(format_args!($($arg)*)) };
|
||||
}
|
||||
|
||||
pub(crate) fn write_line(args: Arguments) {
|
||||
finish(writeln!(io::stdout(), "{args}"));
|
||||
}
|
||||
|
||||
pub(crate) fn write_text(args: Arguments) {
|
||||
finish(write!(io::stdout(), "{args}"));
|
||||
}
|
||||
|
||||
// a reader leaving early ends the pipe; println! would panic instead
|
||||
fn finish(written: io::Result<()>) {
|
||||
if written.is_err() {
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) use {line, note, text, warning};
|
||||
|
||||
Reference in New Issue
Block a user