Commit 15cfd9c
authored
fix(interactive): flush stdout/stderr after streaming command output (#1226)
## Summary
- Fix `clear` (and other commands producing output without trailing
newlines) appearing delayed in interactive mode
- Root cause: `print!()`/`eprint!()` in the streaming callback are
line-buffered on TTY — ANSI escape codes from `clear` (`\x1b[2J\x1b[H`,
no newline) stayed buffered until rustyline's next prompt draw
- Add explicit `stdout().flush()` and `stderr().flush()` after each
`print!()`/`eprint!()` in the streaming callback
## What changed
`crates/bashkit-cli/src/interactive.rs`:
- Added `use std::io::Write` import
- Added `std::io::stdout().flush()` after `print!()` in the
`exec_streaming` callback
- Added `std::io::stderr().flush()` after `eprint!()` in the
`exec_streaming` callback
- Added test `clear_command_streams_ansi_escape_codes` verifying `clear`
produces expected ANSI escape sequences via streaming
## Why
Users reported that typing `clear` in interactive mode didn't clear the
screen immediately — instead the screen cleared only when the *next*
command was executed. This is because Rust's `print!()` macro uses line
buffering when connected to a TTY, and the clear command's output
contains no newline.
## Test plan
- [x] New test: `clear_command_streams_ansi_escape_codes` — verifies
`clear` emits `ESC[2J` and `ESC[H` via `exec_streaming`
- [x] All 86 bashkit-cli tests pass
- [x] All 2363 bashkit lib tests pass
- [x] `cargo fmt --check` clean
- [x] `cargo clippy -- -D warnings` clean
- [x] Smoke test: `echo 'clear' | cargo run` emits correct ANSI codes
- [x] Audited codebase for similar unflushed `print!`/`eprint!` — only
other occurrence is in `main.rs` one-shot mode where `process::exit()`
follows immediately (OS flushes on exit)1 parent f744088 commit 15cfd9c
1 file changed
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
505 | 506 | | |
506 | 507 | | |
507 | 508 | | |
| 509 | + | |
508 | 510 | | |
509 | 511 | | |
510 | 512 | | |
| 513 | + | |
511 | 514 | | |
512 | 515 | | |
513 | 516 | | |
| |||
734 | 737 | | |
735 | 738 | | |
736 | 739 | | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
737 | 770 | | |
738 | 771 | | |
739 | 772 | | |
| |||
0 commit comments