Skip to content

fix: bail when stdout is not a terminal - #602

Open
Mathjk wants to merge 1 commit into
orf:mainfrom
Mathjk:fix/pipe-stdout-bail
Open

Mathjk wants to merge 1 commit into
orf:mainfrom
Mathjk:fix/pipe-stdout-bail

Conversation

@Mathjk

@Mathjk Mathjk commented Sep 29, 2026

Copy link
Copy Markdown

Fixes #601.

Bug

gping <host> | cat (or any piped/redirected stdout) enters the ratatui render loop anyway and floods the consumer with ANSI frames forever. main() never checks stdout; CrosstermBackend happily renders into a pipe — on Windows, enable_raw_mode() only affects the input console, which is still a tty, so nothing stops it.

Fix (+8/-0)

Bail early when stdout isn't a terminal — right after the no-hosts check, before DNS resolution and thread spawn:

if !io::stdout().is_terminal() {
    bail!("gping requires a terminal to draw its graph, but stdout is piped or redirected");
}

Matches top/htop/bottom behavior — gping has no plain-text mode, so refusing is the correct semantics.

Verified (Windows 11 + Linux)

Case Before After
gping 127.0.0.1 > out.txt file grows ~600B/s with ANSI frames forever clean error on stderr, exit 1, 0 bytes
gping 127.0.0.1 | exit-early cryptic Error: os error 232 clean error, exit 1
TTY launch under ConPTY — renders, q exits cleanly
--help/-V piped works unchanged (clap exits during parse)

cargo fmt --check + clippy --workspace clean; cargo test -p gping 18/18 (one pre-existing IPv6 env failure in pinger unrelated to this diff).

When stdout is piped or redirected (e.g. 'gping 127.0.0.1 | cat' or
'gping host > out.txt'), gping entered its render loop anyway and
flooded the consumer with ANSI drawing frames forever, or died with a
cryptic broken-pipe error (os error 232 on Windows) once the reader
went away.

The UI is the graph itself and there is no plain-text mode to fall
back to, so bail early with a clear error like other full-screen TUI
tools (top/htop/bottom). --help/--version still work piped since clap
handles them during argument parsing.

Fixes orf#601
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Piped/redirected stdout: gping spins forever writing ANSI frames instead of refusing to run

1 participant