Ejemplo n.º 1
0
 def __rich_console__(self, console: Console,
                      options: ConsoleOptions) -> RenderResult:
     for y in range(0, 5):
         for x in range(options.max_width):
             h = x / options.max_width
             l = 0.1 + ((y / 5) * 0.7)
             r1, g1, b1 = colorsys.hls_to_rgb(h, l, 1.0)
             r2, g2, b2 = colorsys.hls_to_rgb(h, l + 0.7 / 10, 1.0)
             bgcolor = Color.from_rgb(r1 * 255, g1 * 255, b1 * 255)
             color = Color.from_rgb(r2 * 255, g2 * 255, b2 * 255)
             yield Segment("▄", Style(color=color, bgcolor=bgcolor))
         yield Segment.line()
Ejemplo n.º 2
0
            elif (code := BASE_COLOR_MAP.get(c, None)):
                setattr(mark, "color", Color.from_ansi(code))
            elif (code := BASE_COLOR_MAP.get(c.lower(), None)):
                setattr(mark, "bgcolor", Color.from_ansi(code))
            else:
                pass  # I dunno what we got passed, but it ain't relevant.

    elif g == BgMode.FG:
        if mode == "numbers":
            setattr(mark, "color", Color.from_ansi(data))
        elif mode == "name":
            if (found := COLORS.get(data)):
                setattr(mark, "color", Color.from_ansi(found["xterm"]))
        elif mode in ("rgb", "hex1", "hex2"):
            setattr(mark, "color",
                    Color.from_rgb(data["red"], data["green"], data["blue"]))
    elif g == BgMode.BG:
        if mode == "numbers":
            setattr(mark, "bgcolor", Color.from_ansi(data))
        elif mode == "name":
            if (found := COLORS.get(data)):
                setattr(mark, "bgcolor", Color.from_ansi(found["xterm"]))
        elif mode in ("rgb", "hex1", "hex2"):
            setattr(
                mark,
                "bgcolor",
                Color.from_rgb(data["red"], data["green"], data["blue"]),
            )


def apply_rules(mark: ProtoStyle, rules: str):
Ejemplo n.º 3
0
def test_from_rgb() -> None:
    assert Color.from_rgb(0x10, 0x20,
                          0x30) == Color("#102030", ColorType.TRUECOLOR, None,
                                         ColorTriplet(0x10, 0x20, 0x30))
Ejemplo n.º 4
0
"""

Use Bar to renderer a sort-of circle.

"""
import math

from mudrich.align import Align
from mudrich.bar import Bar
from mudrich.color import Color
from mudrich import print


SIZE = 40

for row in range(SIZE):
    y = (row / (SIZE - 1)) * 2 - 1
    x = math.sqrt(1 - y * y)
    color = Color.from_rgb((1 + y) * 127.5, 0, 0)
    bar = Bar(2, width=SIZE * 2, begin=1 - x, end=1 + x, color=color)
    print(Align.center(bar))