Skip to content

fix: strip colors when stdout is not a TTY#52

Merged
benner merged 3 commits into
mainfrom
fix/strip-colors-when-not-tty
Apr 26, 2026
Merged

fix: strip colors when stdout is not a TTY#52
benner merged 3 commits into
mainfrom
fix/strip-colors-when-not-tty

Conversation

@benner
Copy link
Copy Markdown
Owner

@benner benner commented Apr 26, 2026

  • fix: strip colors when stdout is not a TTY
  • refactor: extract color decoration into _prefix helper
  • refactor: add Level.OK to unify success marker with prefix system

benner added 3 commits April 26, 2026 06:09
The ✓ success marker was hardcoded inline in _report_text as a raw ANSI
string, separate from the PREFIXES lookup used for all other levels.
Adding Level.OK brings it into the same system so all display symbols
live in one place, making the upcoming color refactor cleaner.

Signed-off-by: Nerijus Bendžiūnas <nerijus.bendziunas@gmail.com>
PREFIXES held both the symbol and the ANSI escape codes mixed together,
making it impossible to render the same symbols without color. Separating
symbols (PREFIXES) from color codes (COLORS) into a _prefix(level, color)
helper prepares the ground for TTY-aware color suppression.

Signed-off-by: Nerijus Bendžiūnas <nerijus.bendziunas@gmail.com>
Piping or redirecting output produced ANSI escape codes in the stream
because color was always applied unconditionally. Check sys.stdout.isatty()
and pass the result through _prefix so colors are only emitted when
writing to a terminal.

Signed-off-by: Nerijus Bendžiūnas <nerijus.bendziunas@gmail.com>
@benner benner marked this pull request as ready for review April 26, 2026 03:20
@benner benner merged commit 84ed36e into main Apr 26, 2026
4 checks passed
@benner benner deleted the fix/strip-colors-when-not-tty branch April 26, 2026 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant