Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

anstream println field witdth is not aware of color codes

Open
#167 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
cli

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

A-stream C-bug

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-cli/anstyle

All issues in rust-cli/anstyle

Similar issues

More CLI issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.