Allow paging coloured terminal output
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 22.2k
- Forks
- 1.9k
- PR merge metrics
- PR metrics pending
Description
Problem
Using this repo as an example,
mdbook test -c 02-initialization/01-initialization.md
produces coloured output on terminals that support it (in my case, the macOS 14.0 terminal). However, if I try to pipe it into a colour-preserving screen reader like so
mdbook test -c 02-initialization/01-initialization.md |& less -R
I get monochrome output. I cannot find any way to change this behaviour.
Proposed Solution
Add some option to mdBook to emit ANSI escape codes even when stdout is not declared as a terminal.
Here are some of the usual ways I can think of other CLI tools do this:
mdbook --color=always test -c 02-initialization/01-initialization.md |& less -R
mdbook test --color=always -c 02-initialization/01-initialization.md |& less -R
mdbook test -- --color=always -c 02-initialization/01-initialization.md |& less -R
mdbook test -- --color=always |& less -R
mdbook test -c 02-initialization/01-initialization.md --color=always |& less -R
mdbook test -c 02-initialization/01-initialization.md -- --color=always |& less -R
CARGO_TERM_COLOR=always mdbook test -c 02-initialization/01-initialization.md |& less -R
TERM_COLOR=1 mdbook test -c 02-initialization/01-initialization.md |& less -R
TERM_COLOR=always mdbook test -c 02-initialization/01-initialization.md |& less -R
TERM=xterm-color mdbook test -c 02-initialization/01-initialization.md |& less -R
TERM=xterm-256color mdbook test -c 02-initialization/01-initialization.md |& less -R
I am not sure which option is best practice (Bash is a mess) but I confirmed that none of these options current do what you would expect.
Notes
I have something similar set up for Cargo (hence my surprise mdBook did not respect it):
# in ~/.cargo/config.toml
[term]
color = "always"
and then running
cargo clippy |& less -R
does not result in monochrome output. This can also be done without changing the configuration file:
cargo --color=always clippy |& less -R
or
CARGO_TERM_COLOR=always cargo clippy |& less -R
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the documented mdbook test ... | less -R command and inspect the CLI and test-output paths responsible for deciding whether ANSI colors are emitted. Done means providing a documented color-forcing option or equivalent behavior that preserves colored output through a pipe, with coverage for the relevant command-line usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100