fix: end quietly when a reader leaves the pipe early

This commit is contained in:
2026-09-08 14:21:16 +00:00
parent 1ecf7f1ee4
commit 99010cb641
4 changed files with 57 additions and 27 deletions

View File

@@ -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};