tiangolo / typer

Typer, build great CLIs. Easy to code. Based on Python type hints.
https://typer.tiangolo.com/
MIT License
14.92k stars 636 forks source link

Rich markup in Zsh completion help lines #822

Open tiangolo opened 2 months ago

tiangolo commented 2 months ago

Discussed in https://github.com/tiangolo/typer/discussions/821

Originally posted by **tiangolo** May 2, 2024 ### First Check - [X] I added a very descriptive title here. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I searched the Typer documentation, with the integrated search. - [X] I already searched in Google "How to X in Typer" and didn't find any information. - [X] I already read and followed all the tutorials in the docs and didn't find an answer. - [X] I already checked if it is not related to Typer but to [Click](https://github.com/pallets/click). ### Commit to Help - [X] I commit to help with one of those options 👆 ### Example Code ```python 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 goodbye -- Say [bold]goodbye[/bold] to the user. hello -- Say [bold]hi[/bold] to the user. ``` ![Screenshot from 2024-05-02 15-12-44](https://github.com/tiangolo/typer/assets/1326112/e0f6ad09-6a2a-496f-b1c5-7184f302b8b1) 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_
svlandeg commented 2 weeks ago

Looking into this! It took me a little while to get started, because I couldn't get autocompletion to work in zsh with Git bash for Windows. It works now thanks to https://github.com/tiangolo/typer/pull/237, so I'm looking into this next 🙂