Files
textual/tests/renderables/test_tint.py
Darren Burns 363c9d4cc8 Map ANSI colours (#4192)
* Begin to map ansi colours

* ANSI theme mapping

* Snapshot test for ansi theme mapping

* Add light/dark mode snapshots for ansi theme mapping

* Update CHANGELOG

* Snapshot update failing command palette tests

* Import default ansi theme from textual instead of rich

* Use a dedicated light theme

* Fix snapshot tests

* Regenerate all snapshots in a single run

* Hardcode a color on the search icon emoji to work around test issues

* Alternative approach

* snapshot update

* Simplify a loop in app.py
2024-02-27 10:23:26 +00:00

49 lines
1.5 KiB
Python

import io
from rich.console import Console
from rich.segment import Segments
from rich.terminal_theme import DIMMED_MONOKAI
from rich.text import Text
from textual._ansi_theme import DEFAULT_TERMINAL_THEME
from textual.color import Color
from textual.renderables.tint import Tint
def test_tint():
console = Console(file=io.StringIO(), force_terminal=True, color_system="truecolor")
renderable = Text.from_markup("[#aabbcc on #112233]foo")
segments = list(console.render(renderable))
console.print(
Segments(
Tint.process_segments(
segments=segments,
color=Color(0, 100, 0, 0.5),
ansi_theme=DEFAULT_TERMINAL_THEME,
)
)
)
output = console.file.getvalue()
print(repr(output))
expected = "\x1b[38;2;85;143;102;48;2;8;67;25mfoo\x1b[0m\n"
assert output == expected
def test_tint_ansi_mapping():
console = Console(file=io.StringIO(), force_terminal=True, color_system="truecolor")
renderable = Text.from_markup("[red on yellow]foo")
segments = list(console.render(renderable))
console.print(
Segments(
Tint.process_segments(
segments=segments,
color=Color(0, 100, 0, 0.5),
ansi_theme=DIMMED_MONOKAI,
)
)
)
output = console.file.getvalue()
print(repr(output))
expected = "\x1b[38;2;95;81;36;48;2;98;133;26mfoo\x1b[0m\n"
assert output == expected