Skip to content

fix: skip compact auto-detect when stdout is not a TTY#1111

Open
zcutlip wants to merge 1 commit into
ryoppippi:mainfrom
zcutlip:enable-redirection-without-compact
Open

fix: skip compact auto-detect when stdout is not a TTY#1111
zcutlip wants to merge 1 commit into
ryoppippi:mainfrom
zcutlip:enable-redirection-without-compact

Conversation

@zcutlip
Copy link
Copy Markdown

@zcutlip zcutlip commented May 21, 2026

Addesses #1110

  • Add std::io::stdout().is_terminal() check before compact threshold
  • Show full columns when output is piped or redirected
  • --compact flag still works as explicit override

Summary by cubic

Skip compact auto-detection when stdout is not a TTY so piped/redirected output shows full columns. --compact still forces compact mode. Fixes #1110.

  • Bug Fixes
    • Guard compact logic with stdout().is_terminal(); auto-compact only on TTYs.
    • Applied to all usage tables in adapter/all.rs, adapter/amp.rs, blocks.rs, and output.rs.

Written for commit dd300b2. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced output formatting to intelligently apply compact display mode. The system now correctly determines when to use width-based formatting adjustments by checking whether output is going to an interactive terminal. This ensures consistent and appropriate formatting whether output is displayed in a terminal, piped, or redirected to a file, improving the user experience across all usage scenarios.

Review Change Stack

- Add std::io::stdout().is_terminal() check before compact threshold
- Show full columns when output is piped or redirected
- --compact flag still works as explicit override
@github-actions
Copy link
Copy Markdown

This PR was auto-closed. Only contributors approved with lgtm can open PRs. Open an issue first.

Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply.

If a maintainer replies lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open.

See CONTRIBUTING.md.

@github-actions github-actions Bot closed this May 21, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c880453a-59f9-4fa7-9e6e-475556b90964

📥 Commits

Reviewing files that changed from the base of the PR and between 1e1e9b3 and dd300b2.

📒 Files selected for processing (4)
  • rust/crates/ccusage/src/adapter/all.rs
  • rust/crates/ccusage/src/adapter/amp.rs
  • rust/crates/ccusage/src/blocks.rs
  • rust/crates/ccusage/src/output.rs

📝 Walkthrough

Walkthrough

Four output modules in ccusage are refactored to detect whether stdout is a terminal and only apply the width-based compact-mode threshold when running interactively. Each module imports std::io::IsTerminal and calls io::stdout().is_terminal() to gate compact formatting logic consistently.

Changes

TTY-aware compact mode

Layer / File(s) Summary
TTY-aware compact mode selection across output adapters
rust/crates/ccusage/src/blocks.rs, rust/crates/ccusage/src/output.rs, rust/crates/ccusage/src/adapter/amp.rs, rust/crates/ccusage/src/adapter/all.rs
IsTerminal is imported in all four modules. Compact-mode detection is refactored from a pure width-based check to a TTY-aware check: compact is enabled when shared.compact is set or when stdout is a terminal and terminal width is below the respective compact threshold.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐰 A TTY-aware bunny hops through the code,
detecting terminals along the road,
compact mode now knows when to bloom,
whether in a shell or a piped-out room,
making output dance to the right degree! 🎉

✨ 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.

@zcutlip
Copy link
Copy Markdown
Author

zcutlip commented May 21, 2026

I should add that in edge cases where piping/redirecting prevents automatic compact mode but shouldn't, there's still --compact available to force it.

@zcutlip
Copy link
Copy Markdown
Author

zcutlip commented May 21, 2026

One more note: I have another PR in the pipeline to address a bug with --since. I'll hold off on submitting that until/if this one gets resolved.

@ryoppippi ryoppippi reopened this May 24, 2026
@ryoppippi
Copy link
Copy Markdown
Owner

@zcutlip could you. continue working on it

@ryoppippi
Copy link
Copy Markdown
Owner

when you finish ping me

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.

when redirecting or piping, TTY is not detected and "--compact" is enabled

2 participants