added new terminal formatters using PYTEST_THEME for style
This commit is contained in:
parent
eea04c2891
commit
98121455e5
1
AUTHORS
1
AUTHORS
|
@ -308,6 +308,7 @@ Omar Kohl
|
|||
Omer Hadari
|
||||
Ondřej Súkup
|
||||
Oscar Benjamin
|
||||
Pandula Gajadeera
|
||||
Parth Patel
|
||||
Patrick Hayes
|
||||
Patrick Lannigan
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
Improved the terminal writer to be able to use Terminal256Formatter and TerminalTrueColorFormatter.
|
||||
|
||||
These are newer versions of TerminalFormmater from the pygments library that is currently in use.
|
||||
|
||||
These style of these formatters are set by the users through the environmental variable PYTEST_THEME.
|
|
@ -218,13 +218,24 @@ class TerminalWriter:
|
|||
return source
|
||||
else:
|
||||
try:
|
||||
# Import new more rich color formatters from the pygments library
|
||||
from pygments.formatters.terminal256 import TerminalTrueColorFormatter
|
||||
from pygments.formatters.terminal256 import Terminal256Formatter
|
||||
|
||||
# Use terminal formatters depending on user environment variables
|
||||
if os.environ.get('COLORTERM','') in ('truecolor', '24bit'):
|
||||
# Style determined by user set environment variable, if none then use default style
|
||||
terminal_formatter = TerminalTrueColorFormatter(style=os.getenv("PYTEST_THEME","default"))
|
||||
elif '256' in os.environ.get('TERM', ''):
|
||||
terminal_formatter = Terminal256Formatter(style=os.getenv("PYTEST_THEME","default"))
|
||||
else:
|
||||
terminal_formatter = TerminalFormatter(
|
||||
bg=os.getenv("PYTEST_THEME_MODE", "dark"),
|
||||
style=os.getenv("PYTEST_THEME"),
|
||||
)
|
||||
highlighted: str = highlight(
|
||||
source,
|
||||
Lexer(),
|
||||
TerminalFormatter(
|
||||
bg=os.getenv("PYTEST_THEME_MODE", "dark"),
|
||||
style=os.getenv("PYTEST_THEME"),
|
||||
),
|
||||
)
|
||||
# pygments terminal formatter may add a newline when there wasn't one.
|
||||
# We don't want this, remove.
|
||||
|
|
Loading…
Reference in New Issue