Beispiel #1
0
 def test(foo: float, bar: float) -> None:
     list_of_things = [1, 2, 3, None, 4, True, False, "Hello World"]
     dict_of_things = {
         "version": "1.1",
         "method": "confirmFruitPurchase",
         "params": [["apple", "orange", "mangoes", "pomelo"], 1.123],
         "id": "194521489",
     }
     print(render_scope(locals(), title="[i]locals", sort_keys=False))
Beispiel #2
0
            for line in lines:
                yield left
                yield from line
                yield from right
        else:
            for line in lines:
                yield from line
                yield from right
        if self.bottom:
            blank_line = blank_line or [_Segment(f'{" " * width}\n', style)]
            yield from blank_line * self.bottom

    def __rich_measure__(self, console: "Console",
                         options: "ConsoleOptions") -> "Measurement":
        max_width = options.max_width
        extra_width = self.left + self.right
        if max_width - extra_width < 1:
            return Measurement(max_width, max_width)
        measure_min, measure_max = Measurement.get(console, options,
                                                   self.renderable)
        measurement = Measurement(measure_min + extra_width,
                                  measure_max + extra_width)
        measurement = measurement.with_maximum(max_width)
        return measurement


if __name__ == "__main__":  #  pragma: no cover
    from pipenv.patched.notpip._vendor.rich import print

    print(Padding("Hello, World", (2, 4), style="on blue"))
Beispiel #3
0
                indent_guides=indent_guides,
                max_length=max_length,
                max_string=max_string,
            ),
        )
    return Panel.fit(
        items_table,
        title=title,
        border_style="scope.border",
        padding=(0, 1),
    )


if __name__ == "__main__":  # pragma: no cover
    from pipenv.patched.notpip._vendor.rich import print

    print()

    def test(foo: float, bar: float) -> None:
        list_of_things = [1, 2, 3, None, 4, True, False, "Hello World"]
        dict_of_things = {
            "version": "1.1",
            "method": "confirmFruitPurchase",
            "params": [["apple", "orange", "mangoes", "pomelo"], 1.123],
            "id": "194521489",
        }
        print(render_scope(locals(), title="[i]locals", sort_keys=False))

    test(20.3423, 3.1427)
    print()
Beispiel #4
0
            "Hello World!",
            100.123,
            323.232,
            432324.0,
            {5, 6, 7, (1, 2, 3, 4), 8},
        ],
        "bar":
        frozenset({1, 2, 3}),
        "defaultdict":
        defaultdict(
            list,
            {"crumble": ["apple", "rhubarb", "butter", "sugar", "flour"]}),
        "counter":
        Counter([
            "apple",
            "orange",
            "pear",
            "kumquat",
            "kumquat",
            "durian" * 100,
        ]),
        "atomic": (False, True, None),
        "Broken":
        BrokenRepr(),
    }
    data["foo"].append(data)  # type: ignore

    from pipenv.patched.notpip._vendor.rich import print

    print(Pretty(data, indent_guides=True, max_string=20))
Beispiel #5
0
    text_length = len(text)
    while style_stack:
        start, tag = style_stack.pop()
        style = str(tag)
        if style:
            append_span(_Span(start, text_length, style))

    text.spans = sorted(spans[::-1], key=attrgetter("start"))
    return text


if __name__ == "__main__":  # pragma: no cover

    MARKUP = [
        "[red]Hello World[/red]",
        "[magenta]Hello [b]World[/b]",
        "[bold]Bold[italic] bold and italic [/bold]italic[/italic]",
        "Click [link=https://www.willmcgugan.com]here[/link] to visit my Blog",
        ":warning-emoji: [bold red blink] DANGER![/]",
    ]

    from pipenv.patched.notpip._vendor.rich.table import Table
    from pipenv.patched.notpip._vendor.rich import print

    grid = Table("Markup", "Result", padding=(0, 1))

    for markup in MARKUP:
        grid.add_row(Text(markup), markup)

    print(grid)
Beispiel #6
0
    Args:
        renderable (RenderableType): Any renderable.
        style (StyleType): A style to apply across the entire renderable.
    """

    def __init__(self, renderable: "RenderableType", style: "StyleType") -> None:
        self.renderable = renderable
        self.style = style

    def __rich_console__(
        self, console: "Console", options: "ConsoleOptions"
    ) -> "RenderResult":
        style = console.get_style(self.style)
        rendered_segments = console.render(self.renderable, options)
        segments = Segment.apply_style(rendered_segments, style)
        return segments

    def __rich_measure__(
        self, console: "Console", options: "ConsoleOptions"
    ) -> Measurement:
        return Measurement.get(console, options, self.renderable)


if __name__ == "__main__":  # pragma: no cover
    from pipenv.patched.notpip._vendor.rich import print
    from pipenv.patched.notpip._vendor.rich.panel import Panel

    panel = Styled(Panel("hello"), "on blue")
    print(panel)
Beispiel #7
0
    _GetStdHandle.restype = wintypes.HANDLE

    def get_windows_console_features() -> WindowsConsoleFeatures:
        """Get windows console features.

        Returns:
            WindowsConsoleFeatures: An instance of WindowsConsoleFeatures.
        """
        handle = _GetStdHandle(STDOUT)
        console_mode = wintypes.DWORD()
        result = _GetConsoleMode(handle, console_mode)
        vt = bool(result
                  and console_mode.value & ENABLE_VIRTUAL_TERMINAL_PROCESSING)
        truecolor = False
        if vt:
            win_version = sys.getwindowsversion()
            truecolor = win_version.major > 10 or (win_version.major == 10 and
                                                   win_version.build >= 15063)
        features = WindowsConsoleFeatures(vt=vt, truecolor=truecolor)
        return features


if __name__ == "__main__":
    import platform

    features = get_windows_console_features()
    from pipenv.patched.notpip._vendor.rich import print

    print(f'platform="{platform.system()}"')
    print(repr(features))
Beispiel #8
0
        return value == self.choices[0]


if __name__ == "__main__":  # pragma: no cover

    from pipenv.patched.notpip._vendor.rich import print

    if Confirm.ask("Run [i]prompt[/i] tests?", default=True):
        while True:
            result = IntPrompt.ask(
                ":rocket: Enter a number between [b]1[/b] and [b]10[/b]",
                default=5)
            if result >= 1 and result <= 10:
                break
            print(
                ":pile_of_poo: [prompt.invalid]Number must be between 1 and 10"
            )
        print(f"number={result}")

        while True:
            password = Prompt.ask(
                "Please enter a password [cyan](must be at least 5 characters)",
                password=True,
            )
            if len(password) >= 5:
                break
            print("[prompt.invalid]password too short")
        print(f"password={password!r}")

        fruit = Prompt.ask("Enter a fruit",
                           choices=["apple", "orange", "pear"])