Exemple #1
0
def output_rich(data: Dataset, formatter, cache_disabled):
    console.record = True
    table = Table(
        show_header=True,
        header_style="bold blue",
        row_styles=[Style(), Style(color=Color.from_ansi(252))],
        show_footer=True,
        footer_style="bold blue",
    )
    table.box = box.MINIMAL

    rows = list(data.get_rows_list(formatter))

    for col in data.output_columns:
        table.add_column(col, footer="" if len(rows) < 15 else col)

    for row in rows:
        table.add_row(*row)

    console.print(table)
    console.rule("Information")

    if len(data.output_columns) < len(data.available_columns):
        console.print(
            "[green]More columns available:[/green]",
            ", ".join(sorted(data.available_columns -
                             set(data.output_columns))),
        )
    console.print("[green]Sorted by:[/green]", ", ".join(data.sort))
    if data.where is None:
        console.print(
            f"[green]All available rows ({table.row_count}) are shown.[/green]"
        )
    else:
        console.print(
            "[green]Filter active:[/green]",
            f"`[blue]{data.where}[/blue]`",
            f"→ {table.row_count} rows of {data.original_row_count} available rows shown.",
        )
    if not cache_disabled:
        console.print(
            "[green]Caching enabled. To disable, use[/green] --no-cache")
Exemple #2
0
import re
from rich.text import Text
from ..patches.style import MudStyle, ProtoStyle
from rich.color import Color
from typing import Union, List, Tuple

LETTERS = {
    "x": Color.from_ansi(0),
    "r": Color.from_ansi(1),
    "g": Color.from_ansi(2),
    "y": Color.from_ansi(3),
    "b": Color.from_ansi(4),
    "m": Color.from_ansi(5),
    "c": Color.from_ansi(6),
    "w": Color.from_ansi(7),
}

EV_REGEX = {
    "fg_ansi_bold": re.compile(r"^(r|g|y|b|m|c|x|w)"),
    "fg_ansi_normal": re.compile(r"^(R|G|Y|B|M|C|X|W)"),
    "bg_ansi_bold": re.compile(r"^\[(r|g|y|b|m|c|x|w)"),
    "bg_ansi_normal": re.compile(r"^\[(R|G|Y|B|M|C|X|W)"),
    "fg_xterm": re.compile(r"^[0-5]{3}"),
    "bg_xterm": re.compile(r"^\[([0-5]{3})"),
}


def apply_fg_ansi_bold(proto: ProtoStyle, code):
    proto.bold = True
    proto.color = LETTERS[code.group(0)]
Exemple #3
0
def apply_color_rule(mark: ProtoStyle, rule_tuple):
    mode, g, data, original = rule_tuple
    if mode == "letters":
        for c in data:
            if c == "n":
                # ANSI reset
                mark.do_reset()
                continue

            if (bit := CHAR_MAP.get(c, None)):
                setattr(mark, bit, True)
            elif (bit := CHAR_MAP.get(c.lower(), None)):
                setattr(mark, bit, False)
            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:
Exemple #4
0
def test_from_ansi() -> None:
    assert Color.from_ansi(1) == Color("color(1)", ColorType.STANDARD, 1)
Exemple #5
0
def apply_color_rule(mark: ProtoStyle, rule_tuple):
    mode, g, data, original = rule_tuple
    if mode == "letters":
        for c in data:
            if c == 'n':
                # ANSI reset
                mark.do_reset()
                continue

            if (bit := CHAR_MAP.get(c, None)):
                setattr(mark, bit, True)
            elif (bit := CHAR_MAP.get(c.lower(), None)):
                setattr(mark, bit, False)
            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 == "fg":
        if mode == "numbers":
            mark.set_xterm_fg(data)
        elif mode == "name":
            if (found := COLORS.get(data)):
                mark.set_xterm_fg(found["xterm"])
        elif mode in ("rgb", "hex1", "hex2"):
            mark.set_xterm_fg(int(HEX(data)))
    elif g == "bg":
        if mode == "numbers":
Exemple #6
0
import re
from rich.text import Text
from ..patches.style import MudStyle, ProtoStyle
from rich.color import Color
from typing import Union, List, Tuple

LETTERS = {
    'x': Color.from_ansi(0),
    'r': Color.from_ansi(1),
    'g': Color.from_ansi(2),
    'y': Color.from_ansi(3),
    'b': Color.from_ansi(4),
    'm': Color.from_ansi(5),
    'c': Color.from_ansi(6),
    'w': Color.from_ansi(7)
}

EV_REGEX = {
    "fg_ansi_bold": re.compile(r"^(r|g|y|b|m|c|x|w)"),
    "fg_ansi_normal": re.compile(r"^(R|G|Y|B|M|C|X|W)"),
    "bg_ansi_bold": re.compile(r"^\[(r|g|y|b|m|c|x|w)"),
    "bg_ansi_normal": re.compile(r"^\[(R|G|Y|B|M|C|X|W)"),
    "fg_xterm": re.compile(r"^[0-5]{3}"),
    "bg_xterm": re.compile(r"^\[([0-5]{3})")
}


def apply_fg_ansi_bold(proto: ProtoStyle, code):
    proto.bold = True
    proto.color = LETTERS[code.group(0)]