Skip to content

fix: keep auto colors when paging is forced#3841

Open
tianrking wants to merge 3 commits into
sharkdp:masterfrom
tianrking:agent/keep-auto-color-for-forced-paging
Open

fix: keep auto colors when paging is forced#3841
tianrking wants to merge 3 commits into
sharkdp:masterfrom
tianrking:agent/keep-auto-color-for-forced-paging

Conversation

@tianrking

Copy link
Copy Markdown

Summary

  • preserve automatic ANSI color output whenever bat is going to launch a pager
  • add a regression test for forced paging when stdout is not detected as a terminal

Root cause

--color=auto only consulted the original stdout handle. On Windows, that handle can be reported as non-interactive before bat replaces 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 -- --exact
  • cargo fmt --check
  • cargo clippy --bin bat --tests -- -D warnings
  • git diff --check

Fixes #3833

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment thread src/bin/bat/app.rs
Comment on lines +445 to +447
!env_no_color()
&& (self.interactive_output || paging_mode != PagingMode::Never)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

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.

pwsh: paging mode colors don't work

1 participant