docs: add terminal color cookbook recipe - #86
Open
arindamsikder wants to merge 1 commit into
Open
arindamsikder wants to merge 1 commit into
arindamsikder wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Summary
Add a terminal-color recipe to the cookbook and note it in the unreleased changelog. Documentation only: no library behavior, dependency, configuration or version changes.
Problem
The discussion in #59 explicitly welcomes a cookbook addition rather than built-in coloring. Inserting ANSI escapes into fields before JSON serialization produces escaped JSON strings, not terminal formatting around the output.
Solution
JsonFormattersubclass that colors the serialized console line by log level without adding color to the record or caller data.NO_COLOR, with an explicit off switch and an explanation thatisatty()is not ANSI-capability detection.Testing
Executed on Python 3.11 in a credential-free, network-isolated Bubblewrap environment, on both unchanged main and the proposed docs:
python -m pytest tests -q -p no:cacheprovider --basetemp=/tmp/pytest— 221 passed on each.python -m black --check --diff src tests— passed.python -m pylint src— passed, 10/10.python -m mypy src tests --cache-dir /tmp/mypy-cache— passed, 14 files./out/terminal_color.py; Black with--config /work/pyproject.tomland mypy both passed for that snippet.python -m pytest /out/test_terminal_color_recipe.py -q -c /dev/null --rootdir=. -p no:cacheprovider --basetemp=/tmp/recipe— 24 passed in a local validation harness (not added to the project). Cases cover the displayed output, all five standard levels, a custom level, explicit disable, redirected/TTY output,NO_COLOR, interpolation, embedded quotes/newlines/escape data, dictionary messages, exceptions, and both handler orders. Removing the color wrapper in a sandbox-only copy produced 12 expected failures; restoring it passed all 24. The initial missing-recipe check also failed on unchanged main.python -m mkdocs build --site-dir /out/final-site— completed; rendered cookbook section and warning verified. Used the same compatible local docs toolchain on base and final (mkdocstrings==0.30.1,mkdocstrings-python==1.18.2,mkdocs-gen-files==0.5.0). Both builds have seven existing annotation warnings and an offline Python inventory diagnostic; this is not a warning-free build. The newer installed docs toolchain fails on unchanged configuration, so no upstream dependency change was made.git diff --check, added-line security scan and independent AI diff review — passed. Black reports the same target-Python warning on unchanged and final code.Other Python/OS combinations and an interactive terminal rendering check were not run; ANSI byte output and JSON separation were checked programmatically.
Related Issue
Refs #59 — implements only the cookbook scope invited in the discussion, not a built-in color feature.
AI disclosure
Prepared, tested and independently AI-reviewed by Hermes DEV, an autonomous coding agent acting for @arindamsikder. No human pre-review is claimed.