You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
zsh completion: Rich emoji shortcodes in help text aren't rendered (escape runs before Rich rendering)
#1996
I used the GitHub search to find a similar question and didn't find it.
I searched the documentation, with the integrated search.
I already searched in Google "How to X" and didn't find any information.
I already read and followed all the tutorials in the docs and didn't find an answer.
Example Code
from typer._click.shell_completion import CompletionItem
from typer._completion_classes import ZshComplete
zsh = ZshComplete(None, {}, "prog", "_PROG_COMPLETE") # type: ignore[arg-type]
item = CompletionItem("up", help=":warning: Spin up [bold]now[/bold]")
print(zsh.format_completion(item))
Description
Describe the bug
In zsh completion, help text containing a Rich emoji shortcode such as ⚠️ isn't rendered. The raw shortcode is shown, with backslashes in it.
Cause
ZshComplete.format_completion in typer/_completion_classes.py calls _sanitize_help_text(escape(item.help)). escape() backslash-escapes : for zsh's _describe before Rich renders the text. Rich then no longer matches ⚠️. Bash and fish don't hit this, because bash doesn't escape and fish calls _sanitize_help_text on the raw text.
Possible fix
Render with Rich first, then escape for zsh:
escape(_sanitize_help_text(item.help))
I have a branch with this change and a test that checks both the emoji rendering and that a literal : in the output is still escaped. It's in #1988.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
First Check
Example Code
Description
Describe the bug
In zsh completion, help text containing a Rich emoji shortcode such as⚠️ isn't rendered. The raw shortcode is shown, with backslashes in it.
Cause
ZshComplete.format_completion in typer/_completion_classes.py calls _sanitize_help_text(escape(item.help)). escape() backslash-escapes : for zsh's _describe before Rich renders the text. Rich then no longer matches⚠️ . Bash and fish don't hit this, because bash doesn't escape and fish calls _sanitize_help_text on the raw text.
Possible fix
Render with Rich first, then escape for zsh:
I have a branch with this change and a test that checks both the emoji rendering and that a literal : in the output is still escaped. It's in #1988.
Operating System
Linux, macOS
Operating System Details
No response
Project Version
0.27.3.
Python Version
3.13.17
Additional Context
No response
All reactions