File size: 860 Bytes
2c3c408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

from rich.console import ConsoleOptions, Console, RenderResult
from rich.segment import Segment
from rich.style import Style

from ..color import Color


class Blank:
    """Draw solid background color."""

    def __init__(self, color: Color | str = "transparent") -> None:
        background = Color.parse(color)
        self._style = Style.from_color(bgcolor=background.rich_color)

    def __rich_console__(
        self, console: Console, options: ConsoleOptions
    ) -> RenderResult:
        width = options.max_width
        height = options.height or options.max_height

        segment = Segment(" " * width, self._style)
        line = Segment.line()
        for _ in range(height):
            yield segment
            yield line


if __name__ == "__main__":
    from rich import print

    print(Blank("red"))