File: test_tint.py

package info (click to toggle)
textual 2.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 55,056 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (48 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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