fix: strip colors when stdout is not a TTY#52
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.