Skip to content

fix: flush stdout in CLI help output#41

Open
xiaocang wants to merge 1 commit into
manaflow-ai:mainfrom
xiaocang:fix/cli-stdout-flush
Open

fix: flush stdout in CLI help output#41
xiaocang wants to merge 1 commit into
manaflow-ai:mainfrom
xiaocang:fix/cli-stdout-flush

Conversation

@xiaocang

@xiaocang xiaocang commented Apr 16, 2026

Copy link
Copy Markdown

Summary

  • Added explicit stdout.flush() call before posix.exit(0) in CLI help output path
  • Without this, help text can be silently truncated when using deprecatedWriter

Test plan

  • Run ghostty +help (or any invalid action) and verify full help text is printed
  • Verify no truncation when piping output: ghostty +help | cat

🤖 Generated with Claude Code


Summary by cubic

Ensure CLI help text prints fully by flushing stdout before exit. Prevents truncated output when output is buffered or piped.

  • Bug Fixes
    • Call stdout.flush() before posix.exit(0) in the help path to avoid losing buffered output.

Written for commit 9c5b401. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where help and usage information may not display properly during startup.

The deprecatedWriter may buffer output. Without an explicit flush before
posix.exit(), the help text can be silently truncated.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ee58790-3aff-49b7-9b94-6c1fc51c63a1

📥 Commits

Reviewing files that changed from the base of the PR and between 3b684a0 and 9c5b401.

📒 Files selected for processing (1)
  • src/main_ghostty.zig

📝 Walkthrough

Walkthrough

Added an explicit stdout.flush() call in the early-exit help/usage path of src/main_ghostty.zig before process termination via posix.exit(0). This ensures buffered output is written before exit.

Changes

Cohort / File(s) Summary
Output flushing in early-exit path
src/main_ghostty.zig
Added explicit try stdout.flush() call after printing usage text and help information in the "no app_runtime" early-exit code path.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

Whiskers twitch as we prepare to depart,
A flush to ensure output finds its heart,
No stray bytes left behind in the stream,
Just clean exits and coding dreams,
Before posix.exit we gleam! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: flush stdout in CLI help output' accurately describes the main change: adding a stdout.flush() call in the CLI help output path to ensure output isn't truncated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@greptile-apps

greptile-apps Bot commented Apr 16, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds an explicit stdout.flush() call before posix.exit(0) in the CLI help output path (app_runtime == .none), preventing potential silent truncation when using the deprecatedWriter API with buffered output.

The fix is consistent with the existing pattern elsewhere in this file: the stderr error path at line 53 already calls try stderr.flush() after writing (using the newer File.writer(&buffer) API). The stdout writer here uses the older deprecatedWriter() API, so adding explicit flush before the raw posix.exit(0) — which does not flush application-level buffers — is the right call.

Confidence Score: 5/5

Safe to merge — the single-line fix is correct, low-risk, and consistent with the existing flush pattern in the file.

The only finding is a P2 style suggestion to migrate away from deprecatedWriter(), which does not block merge. The fix itself is minimal, correct, and mirrors the try stderr.flush() pattern already present in this file.

No files require special attention.

Important Files Changed

Filename Overview
src/main_ghostty.zig Adds try stdout.flush() before posix.exit(0) in the help text output path; minimal, correct change consistent with the flush pattern already used for the stderr path in this file.

Sequence Diagram

sequenceDiagram
    participant main as main()
    participant stdout as stdout (deprecatedWriter)
    participant posix as posix.exit(0)

    main->>stdout: print("Usage: ghostty ...")
    main->>stdout: print(help text)
    main->>stdout: flush()   ← added by this PR
    stdout-->>main: ok
    main->>posix: exit(0)
    Note over posix: _exit() — does NOT flush<br/>application buffers
Loading

Comments Outside Diff (1)

  1. src/main_ghostty.zig, line 75-92 (link)

    P2 Consider migrating to the newer buffered writer API

    The stderr error path in this same file (line 33) already uses the newer File.stderr().writer(&buffer) pattern with an explicit stack buffer. The stdout here still uses deprecatedWriter(), which is being phased out. Migrating would make both paths consistent and remove the deprecated API dependency.

    var buf: [4096]u8 = undefined;
    var stdout_writer = std.fs.File{ .handle = std.posix.STDOUT_FILENO }.writer(&buf);
    const stdout = &stdout_writer.interface;

Reviews (1): Last reviewed commit: "fix: flush stdout in CLI help output" | Re-trigger Greptile

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.

1 participant