mirror of
https://github.com/sharkdp/bat
synced 2026-08-06 19:21: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:
@@ -3701,3 +3701,39 @@ fn cache_help_shows_help_message() {
|
||||
.stdout(predicate::str::contains("--build"))
|
||||
.stdout(predicate::str::contains("--clear"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unbuffered_flag_is_accepted() {
|
||||
bat()
|
||||
.arg("--unbuffered")
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("hello world\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unbuffered_mode_disables_line_numbers() {
|
||||
// When --unbuffered is used, line numbers should be auto-disabled even if requested
|
||||
bat()
|
||||
.arg("--unbuffered")
|
||||
.arg("--style=numbers")
|
||||
.arg("--decorations=always")
|
||||
.arg("--color=never")
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::starts_with(" 1").not());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unbuffered_mode_plain_output() {
|
||||
bat()
|
||||
.arg("--unbuffered")
|
||||
.arg("--color=never")
|
||||
.arg("--decorations=never")
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("hello world\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user