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

🐛 Fix shell completions for the fish shell #1069

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

goraje
Copy link

@goraje goraje commented Nov 29, 2024

As described in this discussion #1068, recent changes aimed at sanitizing the help text from rich tags during autocompletion generation (#877) have caused problems with proper generation of autocompletions for fish shell, when rich is installed in the environment. The main culprit most likely being the rich.Console.print method that converts the tabs into spaces which results in malformed autocompletes. I propose a different approach to sanitizing the help text, one that allows to perform the removal of tags before the output of format_completion gets returned, thus allowing to generate a rich tag-free help text, while still being able to pass it to a formatting-preserving output via click.echo in typer.completion (basically reverting this part of the source to the way it was before the #877 changes).

An example of the current behaviour while using rich.Console.print invoked in typer.rich_utils.print_with_rich:

testapp example1\ \ \ Just\ some\ help\ for\ example1

with an example app of the following structure:

from 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="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()

@goraje goraje force-pushed the fix-fish-shell-completions branch 2 times, most recently from 5e44213 to eda9ccb Compare November 29, 2024 23:22
@goraje goraje force-pushed the fix-fish-shell-completions branch from eda9ccb to b22f193 Compare November 29, 2024 23:32
@svlandeg svlandeg self-assigned this Dec 2, 2024
@svlandeg svlandeg added the bug Something isn't working label Dec 2, 2024
@svlandeg
Copy link
Member

svlandeg commented Dec 4, 2024

Thanks for the detailed report and PR! I'll look into this 🙏

@svlandeg svlandeg changed the title Fix fish shell completions 🐛 Fix shell completions for the fish shell Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants