true color and 256 terminal formatters added and use PYTEST_THEME env variable for style
This commit is contained in:
parent
eea04c2891
commit
a1591f8aaf
1
AUTHORS
1
AUTHORS
|
@ -308,6 +308,7 @@ Omar Kohl
|
||||||
Omer Hadari
|
Omer Hadari
|
||||||
Ondřej Súkup
|
Ondřej Súkup
|
||||||
Oscar Benjamin
|
Oscar Benjamin
|
||||||
|
Pandula Gajadeera
|
||||||
Parth Patel
|
Parth Patel
|
||||||
Patrick Hayes
|
Patrick Hayes
|
||||||
Patrick Lannigan
|
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.
|
|
@ -194,9 +194,9 @@ class TerminalWriter:
|
||||||
for indent, new_line in zip(indents, new_lines):
|
for indent, new_line in zip(indents, new_lines):
|
||||||
self.line(indent + new_line)
|
self.line(indent + new_line)
|
||||||
|
|
||||||
def _highlight(
|
def _highlight(
|
||||||
self, source: str, lexer: Literal["diff", "python"] = "python"
|
self, source: str, lexer: Literal["diff", "python"] = "python"
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Highlight the given source if we have markup support."""
|
"""Highlight the given source if we have markup support."""
|
||||||
from _pytest.config.exceptions import UsageError
|
from _pytest.config.exceptions import UsageError
|
||||||
|
|
||||||
|
@ -212,8 +212,20 @@ class TerminalWriter:
|
||||||
from pygments.lexers.diff import DiffLexer as Lexer
|
from pygments.lexers.diff import DiffLexer as Lexer
|
||||||
else:
|
else:
|
||||||
assert_never(lexer)
|
assert_never(lexer)
|
||||||
|
|
||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
import pygments.util
|
import pygments.util
|
||||||
|
|
||||||
|
if os.getenv("COLORTERM", "") in ("truecolor", "24bit"):
|
||||||
|
from pygments.formatters.terminal256 import TerminalTrueColorFormatter
|
||||||
|
terminal_formatter = TerminalTrueColorFormatter(style=os.getenv("PYTEST_THEME", "default"))
|
||||||
|
elif "256" in os.getenv("TERM", ""):
|
||||||
|
from pygments.formatters.terminal256 import Terminal256Formatter
|
||||||
|
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", "default"))
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return source
|
return source
|
||||||
else:
|
else:
|
||||||
|
@ -221,10 +233,7 @@ class TerminalWriter:
|
||||||
highlighted: str = highlight(
|
highlighted: str = highlight(
|
||||||
source,
|
source,
|
||||||
Lexer(),
|
Lexer(),
|
||||||
TerminalFormatter(
|
terminal_formatter,
|
||||||
bg=os.getenv("PYTEST_THEME_MODE", "dark"),
|
|
||||||
style=os.getenv("PYTEST_THEME"),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
# pygments terminal formatter may add a newline when there wasn't one.
|
# pygments terminal formatter may add a newline when there wasn't one.
|
||||||
# We don't want this, remove.
|
# We don't want this, remove.
|
||||||
|
|
Loading…
Reference in New Issue