anstream println field witdth is not aware of color codes
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the Rust example from the issue and trace how anstream's println formatting handles width when a Display implementation emits ANSI color codes. Identify the relevant formatting path and add coverage for the example; done means colored values align with their uncolored equivalents.
Written by the indexing model from the issue text.
Description
I would expect the following (rather silly minimal case) to align columns properly:
use anstream::println;
use anstyle::AnsiColor;
use anstyle::Reset;
enum MyLogLevel {
Ok,
Warn,
Error,
}
impl std::fmt::Display for MyLogLevel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
MyLogLevel::Ok => write!(f, "{}Ok{}", AnsiColor::Green.render_fg(), Reset.render()),
MyLogLevel::Warn => write!(
f,
"{}Warning{}",
AnsiColor::Yellow.render_fg(),
Reset.render()
),
MyLogLevel::Error => write!(f, "{}Error{}", AnsiColor::Red.render_fg(), Reset.render()),
}
}
}
fn main() {
println!("{:<10} Everything is fine", "Ok");
println!("{:<10} Be careful", "Warning");
println!("{:<10} BAD BAD BAD", "Error");
println!("{:<10} Everything is fine", MyLogLevel::Ok);
println!("{:<10} Be careful", MyLogLevel::Warn);
println!("{:<10} BAD BAD BAD", MyLogLevel::Error);
}
It prints:
Ok Everything is fine
Warning Be careful
Error BAD BAD BAD
Ok Everything is fine
Warning Be careful
Error BAD BAD BAD
This is unexpected. So it seems the anstream println is not properly aware of how wide colour codes are.
- Dominant language
- HTML
- Stars
- 171
- Forks
- 44
- Avg merge
- 3h 4m
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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
-
discover: `sudo RTK_DISABLED=$VAR …` is not detected as a bypass when `sudo` is a transparent prefixOpenarea:cli bug good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
filamentphp/filament#20630 ·
Maintainers usually reply within 1 day
-
component:ktuner
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
agentic-os-org/ANOLISA#4109 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
lawndoc/stack-back#121 ·
-
type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day