-
First Check
Commit to Help
Example Codefrom typing import Annotated
import typer
from rich.markup import escape
app = typer.Typer(no_args_is_help=True, rich_markup_mode="rich")
@app.command(name="example1", help="Just [bold]some[/] help for example1")
def example1(name: Annotated[str, typer.Option(help="test1 name")]) -> None:
pass
@app.command(name="example2", help=f"Just some help for example2 {escape('[I'm just text in brackets]')}")
def example2() -> None:
pass
def main() -> None:
app() Description
What I think happens here is that changes introduced in #877 which make use of To be more precise def _render_remove_markup(text: str) -> str:
try:
import rich
except ImportError: # pragma: no cover
rich = None # type: ignore
if rich:
from rich.console import Console
console = Console()
rendered_text = "".join(
segment.text for segment in console.render(text)
).rstrip("\n")
return rendered_text
return text and then using it directly to format the help text for the completion in the designated def format_completion(self, item: click.shell_completion.CompletionItem) -> str:
# TODO: Explore replicating the new behavior from Click, pay attention to
# the difference with and without formatted help
# if item.help:
# return f"{item.type},{item.value}\t{item.help}"
# return f"{item.type},{item.value}
if item.help:
formatted_help = re.sub(r"\s", " ", item.help)
formatted_help = _render_remove_markup(formatted_help)
return f"{item.value}\t{formatted_help}"
else:
return f"{item.value}" This approach:
# Typer override to print the completion help msg with Rich
if instruction == "complete":
click.echo(comp.complete())
return 0 which preserves the proper output formatting. Final thoughts:
Operating SystemmacOS Operating System DetailsNo response Typer Version0.14.0 Python VersionPython 3.12.7 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I confirm that I see this behavior >=0.13.1. I also started seeing ansi color control sequences come through on some systems. |
Beta Was this translation helpful? Give feedback.
-
The original issue as mentioned by @goraje here, should be fixed by PR #1069. |
Beta Was this translation helpful? Give feedback.
-
Since #1069 has been merged, I think this can be closed, right? |
Beta Was this translation helpful? Give feedback.
The original issue as mentioned by @goraje here, should be fixed by PR #1069.