Reduce verbosity in getting the final color for a stream
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
Start at anstream::AutoStream, where the issue requests a public color(&self) -> bool method. Check the existing stream and color-choice behavior, then confirm the resulting API supports the concise stdout().color() usage shown in the issue.
Written by the indexing model from the issue text.
Description
With the updated crates and API:
// I read the color flag the user specified in the cli arguments and default it for my program
program.color.write_global();
// I get the final result for the `stdout` stream of whether to show color or not
let should_color = match anstream::AutoStream::choice(&std::io::stdout()) {
anstream::ColorChoice::Auto => unreachable!(),
anstream::ColorChoice::AlwaysAnsi => true,
anstream::ColorChoice::Always => true,
anstream::ColorChoice::Never => false,
};
// I tell the logger to show color
tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.with_ansi(should_color)
)
.init();
Before, it used to be:
program.color.write_global();
tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.with_ansi(get(Stream::Stdout).color())
)
.init();
I think we can make it simpler similarly:
program.color.write_global();
tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.with_ansi(stdout().color())
)
.init();
All we have to do is add pub fn color(&self) -> bool to anstream::AutoStream
- Dominant language
- HTML
- Stars
- 171
- Forks
- 44
- Avg merge
- 2h 34m
- Merged PRs (30d)
- 6
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.
More from rust-cli/anstyle
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
A-stream
Difficulty 3/5 1-2 days Newbie friendliness 58/100
-
A-stream C-bug S-triage
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in rust-cli/anstyle
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
BasedHardware/omi#15662 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
alexgorbatchev/dotfiles#107 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
from:qa priority:P2 reliability tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
spec-kitty/spec-kitty#4874 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·