Improved the terminal colour formatting, Issue #11666 #12304
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.
Hello,
This PR resolves #11666.
This is my first time contributing to an open source project so please excuse any beginner mistakes.
I used the pull request #11700 as an initial guide as they started to implement this issue but then stopped.
I also know that there are errors with my pull request. I believe that they are all due to do the testing of the terminal output, which I have now changed. I am not sure how to change these tests properly, so have left it for now.
What I did
My goal was to implement the use of the pygment classes
TerminalTrueColorFormatter
andTerminal256Formatter
to get richer colours in the terminal .To do this I used the same logic as pygments use to get the formatter that is appropriate for the users computer.
https://github.com/pygments/pygments/blob/861fb9131b13241d7ea700fba8f6a38cf6f97285/pygments/cmdline.py#L448-L453C57
I set up the formatter in a way that the users can add their own style by setting the environmental variable
PYTEST_THEME
. I also added in default styles which will be used ifPYTEST_THEME
is not set.Both
TerminalTrueColorFormatter
andTerminal256Formatter
do not have light mode or dark mode options. I therefore created two default styles, one for each. I tried to create the styles as close as I could to the default style ofTerminalFormatter
. The environmental variablePYTEST_THEME_MODE
sets if the light mode or dark mode default style is used. IfPYTEST_THEME_MODE
is not set dark mode is the default style.To create the default styles. I made classes at the end of the terminalwiter.py file. If this is the wrong spot for them I am sorry.
Thanks,
James