rust-cli / anstyle

ANSI text styling
https://docs.rs/anstyle
Other
119 stars 19 forks source link

NO_COLOR precedence #178

Closed bluss closed 8 months ago

bluss commented 8 months ago

This document https://bixense.com/clicolors/ says that NO_COLOR has precedence over CLICOLOR_FORCE, but the AutoStream implementation is the other way around.

epage commented 8 months ago

The implementation was made before those specs were merged so I had to take a guess.

epage commented 8 months ago

Hmm, they've made breaking changes to the spec, changing from value checks to presence checks. I strongly disagree with what they've changed it to but not really much to be done.

epage commented 8 months ago

Compare

def has_colors():
    if ((os.getenv("CLICOLOR", "1") != "0" and sys.stdout.isatty()) or
        os.getenv("CLICOLOR_FORCE", "0") != "0"):
        return True
    else:
        return False

with

def has_colors():
    if "NO_COLOR" in os.environ:
        return False
    if "CLICOLOR_FORCE" in os.environ:
        return True
    return sys.stdout.isatty()
bluss commented 8 months ago

I don't have much of an opinion here, and I didn't know those specs 30 minutes ago - so no need to listen to me. I looked at them because they are linked in rustdoc. Now we know that there is this discrepancy.