Rich markup in Zsh completion help lines
tiangolo opened this issue · comments
Discussed in #821
Originally posted by tiangolo May 2, 2024
First Check
- I added a very descriptive title here.
- I used the GitHub search to find a similar question and didn't find it.
- I searched the Typer documentation, with the integrated search.
- I already searched in Google "How to X in Typer" and didn't find any information.
- I already read and followed all the tutorials in the docs and didn't find an answer.
- I already checked if it is not related to Typer but to Click.
Commit to Help
- I commit to help with one of those options 👆
Example Code
import typer
from typing_extensions import Annotated
app = typer.Typer(rich_markup_mode="rich")
@app.command()
def hello(
name: Annotated[
str, typer.Option(help="The [bold]cool[/bold] name of the [green]user[/green]")
],
):
"""
Say [bold]hi[/bold] to the user.
"""
print(f"Hello {name}")
@app.command()
def goodbye(
name: Annotated[
str, typer.Option(help="The [bold]cool[/bold] name of the [green]user[/green]")
],
):
"""
Say [bold]goodbye[/bold] to the user.
"""
print(f"Goodbye {name}")
if __name__ == "__main__":
app()
Description
-
Create this script in
main.py
-
In Zsh, start running it with the
typer
command, start typing:typer main.py run
, then hit tab to trigger autocompletion, it shows the two commands, which is correct: -
goodbye
-
hello
But their Zsh help string includes the Rich markup content:
$ typer main.py run <tab>
goodbye -- Say [bold]goodbye[/bold] to the user.
hello -- Say [bold]hi[/bold] to the user.
It should show plaintext without [bold]
markup parts... or better, it should render those parts and show them in actual green color (using the terminal color codes, etc, the stuff Rich does).
Operating System
Linux, macOS
Operating System Details
This applies mainly to Zsh, the behavior might be similar or different in PowerShell. It only applies in shells that can show autocompletion of commands with help sections.
Typer Version
Typer version: 0.12.3
Python Version
any
Additional Context
No response