Skip to content

Commit c7fea40

Browse files
committed
Rewrite cli color env variable usage
1 parent 2e9d872 commit c7fea40

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

plain/plain/cli/formatting.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,13 @@ def __init__(self, *args: Any, **kwargs: Any):
7878

7979
super().__init__(*args, **kwargs)
8080

81-
# Force colors in CI environments
82-
if any(
83-
os.getenv(var)
84-
for var in ["CI", "FORCE_COLOR", "GITHUB_ACTIONS", "GITLAB_CI"]
85-
) and not any(os.getenv(var) for var in ["NO_COLOR", "PYTEST_CURRENT_TEST"]):
81+
# Follow CLICOLOR standard (http://bixense.com/clicolors/)
82+
# Priority: NO_COLOR > CLICOLOR_FORCE/FORCE_COLOR > CLICOLOR > isatty
83+
if os.getenv("NO_COLOR") or os.getenv("PYTEST_CURRENT_TEST"):
84+
self.color = False
85+
elif os.getenv("CLICOLOR_FORCE") or os.getenv("FORCE_COLOR"):
8686
self.color = True
87+
elif os.getenv("CLICOLOR"):
88+
# CLICOLOR=1 means use colors only if TTY (Click's default behavior)
89+
pass # Let Click handle it with isatty check
90+
# Otherwise use Click's default behavior (isatty check)

0 commit comments

Comments
 (0)