Skip to content

Support NO_COLOR / FORCE_COLOR in Colorama #415

@dhruvjain1512

Description

@dhruvjain1512

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.

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