-
-
Notifications
You must be signed in to change notification settings - Fork 268
Description
Users want environment variables to control color output. Today, colorama.init() ignores NO_COLOR and FORCE_COLOR, so tools cannot globally disable color or force it in CI without code changes. Implement env-aware behavior so NO_COLOR removes ANSI from writes to wrapped standard streams, and FORCE_COLOR enables color even on non-tty outputs. Token strings (Fore/Back/Style) must remain unchanged.
Proposed solution:
Add optional, backward-compatible env handling in init. Accept color_env={"auto","off"} (default "auto") and env (a Mapping; defaults to os.environ). Apply behavior via Colorama's wrapping of standard streams only; do not alter token constants. Precedence: explicit arguments override env-derived behavior. FORCE_COLOR wins over NO_COLOR when both are set. On Windows, FORCE_COLOR must enable wrapping and ANSI-to-Win32 conversion so colors are emitted reliably; on non-Windows, leave convert at its default unless needed. Invalid color_env raises ValueError; a non-mapping env raises TypeError. Keep the public API and formatting unchanged otherwise.