1
0
mirror of https://github.com/sharkdp/bat.git synced 2026-02-08 00:32:08 +00:00

feat: implement quiet_empty behavior in printer

This commit is contained in:
dddffgg
2026-01-31 16:42:28 +08:00
parent 6f0a61cef9
commit 783acbc83d

View File

@@ -454,6 +454,11 @@ impl Printer for InteractivePrinter<'_> {
input: &OpenedInput,
add_header_padding: bool,
) -> Result<()> {
// If input is empty and quiet_empty is enabled, skip all output
if self.content_type.is_none() && self.config.quiet_empty {
return Ok(());
}
if add_header_padding && self.config.style_components.rule() {
self.print_horizontal_line_term(handle, self.colors.rule)?;
}
@@ -556,6 +561,11 @@ impl Printer for InteractivePrinter<'_> {
}
fn print_footer(&mut self, handle: &mut OutputHandle, _input: &OpenedInput) -> Result<()> {
// If input is empty and quiet_empty is enabled, skip footer
if self.content_type.is_none() && self.config.quiet_empty {
return Ok(());
}
if self.config.style_components.grid()
&& (self.content_type.is_some_and(|c| c.is_text())
|| self.config.show_nonprintable