mirror of
https://github.com/sharkdp/bat
synced 2026-08-11 20:11:43 +00:00
feat: implement --unbuffered mode for streaming input (#3555)
Repurpose the existing --unbuffered/-u flag (previously a POSIX no-op) to enable unbuffered input reading using fill_buf()/consume() instead of read_until(b'\n'). This allows partial lines to display immediately when piping streaming input like `tail -f` into bat. - Add unbuffered field to Config and InputReader - Add read_line_unbuffered() using BufRead::fill_buf()/consume() - Add flush() to OutputHandle, called after each line in unbuffered mode - Auto-disable line numbers in unbuffered mode to avoid partial line confusion - Update help text, man page, and shell completions - Add unit tests and integration tests
This commit is contained in:
@@ -462,6 +462,7 @@ impl App {
|
||||
_ => unreachable!("other values for --strip-ansi are not allowed"),
|
||||
},
|
||||
quiet_empty: self.matches.get_flag("quiet-empty"),
|
||||
unbuffered: self.matches.get_flag("unbuffered"),
|
||||
theme: theme(self.theme_options()).to_string(),
|
||||
visible_lines: match self.matches.try_contains_id("diff").unwrap_or_default()
|
||||
&& self.matches.get_flag("diff")
|
||||
@@ -619,6 +620,11 @@ impl App {
|
||||
bat_warning!("Style 'rule' is a subset of style 'grid', 'rule' will not be visible.");
|
||||
}
|
||||
|
||||
// Auto-disable line numbers in unbuffered mode to avoid confusion with partial lines
|
||||
if self.matches.get_flag("unbuffered") {
|
||||
styled_components.0.remove(&StyleComponent::LineNumbers);
|
||||
}
|
||||
|
||||
Ok(styled_components)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user