fix: keep auto colors when paging is forced#3841
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 77f1a42604
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| !env_no_color() | ||
| && (self.interactive_output || paging_mode != PagingMode::Never) | ||
| } |
There was a problem hiding this comment.
Keep forced-pager output out of loop-through mode
When stdout is not a terminal and --paging=always is used with the default --color=auto, this sets colored_output to true, but loop_through just below still remains true because it only considers interactive_output, --color=always, --decorations=always, --force-colorization, or -n. In Controller::print_input, loop_through selects SimplePrinter, which copies bytes without syntax highlighting, so bat --paging=always file.rs from a non-TTY still feeds uncolored text to the pager despite this branch. The same forced-paging predicate needs to participate in the loop-through decision.
Useful? React with 👍 / 👎.
Summary
batis going to launch a pagerRoot cause
--color=autoonly consulted the original stdout handle. On Windows, that handle can be reported as non-interactive beforebatreplaces it with an external or built-in pager, so paging succeeded but syntax highlighting was disabled.Validation
cargo test --bin bat app::tests::auto_color_is_enabled_when_paging_is_forced_without_a_terminal -- --exactcargo fmt --checkcargo clippy --bin bat --tests -- -D warningsgit diff --checkFixes #3833