Repository: pypa/pip
File: src/pip/_internal/cli/parser.py (Python)

Code before:
        )
        self.console = PipConsole(theme=Theme(self.styles), no_color=no_color)
        self.rich_option_strings: dict[optparse.Option, Text] = {}

    def stringify(self, text: RenderableType) -> str:
        """Render a rich object as a string."""
        with self.console.capture() as capture:
            self.console.print(text, highlight=False, soft_wrap=True, end="")
        help = capture.get()
        return "\n".join(line.rstrip() for line in help.split("\n"))

    def format_heading(self, heading: str) -> str:
        if heading == "Options":
            return ""
        rich_heading = Text().append(heading, "optparse.groups").append(":\n")
        return self.stringify(rich_heading)

    def format_usage(self, usage: str) -> str:
        """
        Ensure there is only one newline between usage and the first heading
        if there is no description.
        """
        rich_usage = (
            Text("\n")
            .append("Usage", "optparse.groups")
            .append(f": {self.indent_lines(textwrap.dedent(usage), '  ')}\n")
        )
        return self.stringify(rich_usage)

    def format_description(self, description: str | None) -> str:
        # leave full control over description to us
        if description:
            if hasattr(self.parser, "main"):
                label = "Commands"
            else:
                label = "Description"
            rich_label = self.stringify(Text(label, "optparse.groups"))
            # some doc strings have initial newlines, some don't
            description = description.lstrip("\n")
            # some doc strings have final newlines and spaces, some don't
            description = description.rstrip()
            # dedent, then reindent
            description = self.indent_lines(textwrap.dedent(description), "  ")
            description = f"{rich_label}:\n{description}\n"
            return description
        else:
            return ""

    def format_epilog(self, epilog: str | None) -> str:
        # leave full control over epilog to us
        if epilog:

Review comment (suggestion):
I suggest using the same colour for the colon:


<img width="190" height="113" alt="image" src="https://github.com/user-attachments/assets/16a78afd-31a8-43f0-acf4-2f7305dbde47" /> -> <img width="196" height="113" alt="image" src="https://github.com/user-attachments/assets/78a9bee4-1e90-49c8-8229-6a40ea3ac617" />



```suggestion
            .append("Usage:", "optparse.groups")
            .append(f" {self.indent_lines(textwrap.dedent(usage), '  ')}\n")
```
(and elsewhere)

Code after:
            opts.insert(1, ", ")

        if option.takes_value():
            assert option.dest is not None
            metavar = option.metavar or option.dest.lower()
            opts.append(f" [optparse.metavar]<{escape(metavar.lower())}>[/]")

        return "".join(opts)

    def format_option(self, option: optparse.Option) -> str:
        """Overridden method with Rich support."""
        # fmt: off
        result = []
        opts = self.option_strings[option]
        opt_width = self.help_position - self.current_indent - 2
        # Remove the rich style tags before calculating width during
        # text wrap calculations. Also store the length removed to adjust
        # the padding in the else branch.
        stripped = re.sub(r"(\[[a-z.]+\])|(\[\/\])", "", opts)
        style_tag_length = len(opts) - len(stripped)
        if len(stripped) > opt_width:
            opts = "%*s%s\n" % (self.current_indent, "", opts)  # noqa: UP031
            indent_first = self.help_position
        else:                       # start help on same line as opts
            opts = "%*s%-*s  " % (self.current_indent, "",      # noqa: UP031
                                  opt_width + style_tag_length, opts)
            indent_first = 0
        result.append(opts)
        if option.help:
            help_text = self.expand_default(option)
            help_lines = textwrap.wrap(help_text, self.help_width)
            result.append("%*s%s\n" % (indent_first, "", help_lines[0]))  # noqa: UP031
            result.extend(["%*s%s\n" % (self.help_position, "", line)     # noqa: UP031
                           for line in help_lines[1:]])
        elif opts[-1] != "\n":
            result.append("\n")
        return "".join(result)
        # fmt: on

    def format_heading(self, heading: str) -> str:
        if heading == "Options":
            return ""
        return "[optparse.groups]" + escape(heading) + ":[/]\n"

    def format_usage(self, usage: str) -> str:
        """
        Ensure there is only one newline between usage and the first heading
        if there is no description.
        """
        contents = self.indent_lines(textwrap.dedent(usage), "  ")
        msg = f"\n[optparse.groups]Usage:[/] {escape(contents)}\n"