Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rich markup in Zsh completion help lines #822

Closed
7 tasks done
tiangolo opened this issue May 2, 2024 Discussed in #821 · 2 comments · Fixed by #877
Closed
7 tasks done

Rich markup in Zsh completion help lines #822

tiangolo opened this issue May 2, 2024 Discussed in #821 · 2 comments · Fixed by #877
Labels
bug Something isn't working shell / zsh

Comments

@tiangolo
Copy link
Member

tiangolo commented May 2, 2024

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.

Screenshot from 2024-05-02 15-12-44

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

@tiangolo tiangolo added the bug Something isn't working label May 2, 2024
@svlandeg
Copy link
Member

svlandeg commented Jul 1, 2024

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 #237, so I'm looking into this next 🙂

@svlandeg
Copy link
Member

PR up for review: #877

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working shell / zsh
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants