示例#1
0
文件: logging.py 项目: DiddiLeija/pip
    def emit(self, record: logging.LogRecord) -> None:
        style: Optional[Style] = None

        # If we are given a diagnostic error to present, present it with indentation.
        assert isinstance(record.args, tuple)
        if record.msg == "[present-diagnostic] %s" and len(record.args) == 1:
            diagnostic_error = record.args[0]
            assert isinstance(diagnostic_error, DiagnosticPipError)

            renderable: ConsoleRenderable = IndentedRenderable(
                diagnostic_error, indent=get_indentation()
            )
        else:
            message = self.format(record)
            renderable = self.render_message(record, message)
            if record.levelno is not None:
                if record.levelno >= logging.ERROR:
                    style = Style(color="red")
                elif record.levelno >= logging.WARNING:
                    style = Style(color="yellow")

        try:
            self.console.print(renderable, overflow="ignore", crop=False, style=style)
        except Exception:
            self.handleError(record)
示例#2
0
文件: __main__.py 项目: ZekriSara/pfe
 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()
示例#3
0
 def __rich_console__(self, console: Console,
                      options: ConsoleOptions) -> Iterable[Segment]:
     height = console.size.height - 3
     for y in range(0, height):
         for x in range(options.max_width):
             h = x / options.max_width
             l = y / (height + 1)
             r1, g1, b1 = colorsys.hls_to_rgb(h, l, 1.0)
             r2, g2, b2 = colorsys.hls_to_rgb(h, l + (1 / height / 2),
                                              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()
示例#4
0
    def __rich__(self) -> "Table":
        from pip._vendor.rich.color import Color
        from pip._vendor.rich.style import Style
        from pip._vendor.rich.text import Text
        from pip._vendor.rich.table import Table

        table = Table(
            "index",
            "RGB",
            "Color",
            title="Palette",
            caption=f"{len(self._colors)} colors",
            highlight=True,
            caption_justify="right",
        )
        for index, color in enumerate(self._colors):
            table.add_row(
                str(index),
                repr(color),
                Text(" " * 16, style=Style(bgcolor=Color.from_rgb(*color))),
            )
        return table
示例#5
0
        cursor_info = CONSOLE_CURSOR_INFO()
        GetConsoleCursorInfo(self._handle, cursor_info=cursor_info)
        return int(cursor_info.dwSize)


if __name__ == "__main__":
    handle = GetStdHandle()

    from pip._vendor.rich.console import Console

    console = Console()

    term = LegacyWindowsTerm(sys.stdout)
    term.set_title("Win32 Console Examples")

    style = Style(color="black", bgcolor="red")

    heading = Style.parse("black on green")

    # Check colour output
    console.rule("Checking colour output")
    console.print("[on red]on red!")
    console.print("[blue]blue!")
    console.print("[yellow]yellow!")
    console.print("[bold yellow]bold yellow!")
    console.print("[bright_yellow]bright_yellow!")
    console.print("[dim bright_yellow]dim bright_yellow!")
    console.print("[italic cyan]italic cyan!")
    console.print("[bold white on blue]bold white on blue!")
    console.print("[reverse bold white on blue]reverse bold white on blue!")
    console.print("[bold black on cyan]bold black on cyan!")