Skip to content

Setting NO_COLOR=1 still prints without unicode in a non-tty context #430

@TheNeikos

Description

@TheNeikos

Setting NO_COLOR=1 (or 0) does not change the printing behavior in a no-tty situation.

This code seems to be why:

impl Default for GraphicalTheme {
fn default() -> Self {
match std::env::var("NO_COLOR") {
_ if !std::io::stdout().is_terminal() || !std::io::stderr().is_terminal() => {
Self::none()
}
Ok(string) if string != "0" => Self::unicode_nocolor(),
_ => Self::unicode(),
}
}
}

It indiscriminately causes the theme to be set as ascii/no colors, no matter what the env variable says.

This is unfortunate, as I am testing for this output and having different settings in my CI and my CLI causes my tests to mismatch. I was hoping that some form of ENV variable would help me here, but it does not seem to depend on this.

Could this use-case be considered? I am not sure whether NO_COLOR should change whether one uses unicode/ascii. A new (non-standard) env variable is also not suuuper great.


Edit:

I just realized it's actually worse for me, as I cannot influence that match at all right now. Since with NO_COLOR its still UNICODE in my CLI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions