mirror of
https://github.com/sharkdp/bat
synced 2026-07-28 17:51:44 +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:
@@ -158,6 +158,7 @@ impl Controller<'_> {
|
||||
#[cfg(not(feature = "lessopen"))]
|
||||
input.open(stdin, stdout_identifier)?
|
||||
};
|
||||
opened_input.reader.unbuffered = self.config.unbuffered;
|
||||
#[cfg(feature = "git")]
|
||||
let line_changes = if self.config.visible_lines.diff_mode()
|
||||
|| (!self.config.loop_through && self.config.style_components.changes())
|
||||
@@ -327,6 +328,9 @@ impl Controller<'_> {
|
||||
}
|
||||
|
||||
printer.print_line(false, writer, line_nr, &line, max_buffered_line_number)?;
|
||||
if self.config.unbuffered {
|
||||
writer.flush()?;
|
||||
}
|
||||
}
|
||||
RangeCheckResult::AfterLastRange => {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user