Skip to content
Myr

✨ Remove Rich tags when showing completion text (#877)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sofie Van Landeghem · committed by GitHub · parent 20d4e5c · Browse files · 3 files+22 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

Diff stats

3 files+22 added−2 removed

  • tests:+1 added−1 removed
  • other:+21 added−1 removed

3 files+22 added−2 removed

modified:tests/test_completion/test_completion_complete.py+1 added-1 removed
77 unmodified lines
78 "_TYPER_COMPLETE_FISH_ACTION": "get-args",79 },80 )81 assert (82 "delete\tDelete a user with USERNAME.\ndelete-all\tDelete ALL users in the database."82 "delete Delete a user with USERNAME.\ndelete-all Delete ALL users in the database."83 in result.stdout84 )8586
74 unmodified lines
modified:typer/completion.py+15 added-1 removed
13 unmodified lines
14 import shellingham15except ImportError: # pragma: no cover16 shellingham = None1718try:19 import rich2021except ImportError: # pragma: no cover22 rich = None # type: ignore232425_click_patched = False262728def get_completion_inspect_parameters() -> Tuple[ParamMeta, ParamMeta]:
115 unmodified lines
144 if instruction == "source":145 click.echo(comp.source())146 return 0147148 # Typer override to print the completion help msg with Rich149 if instruction == "complete":150 if not rich: # pragma: no cover143 click.echo(comp.complete())151 click.echo(comp.complete())152 else:153 from . import rich_utils154155 rich_utils.print_with_rich(comp.complete())156157 return 0158 # Typer override end159160 click.echo(f'Completion instruction "{instruction}" not supported.', err=True)161 return 1
modified:typer/rich_utils.py+6 added
710 unmodified lines
711 console = _get_rich_console(stderr=True)712 console.print(ABORTED_TEXT, style=STYLE_ABORTED)713714715def print_with_rich(text: str) -> None:716 """Print richly formatted message."""717 console = _get_rich_console()718 console.print(text)719720721def rich_to_html(input_text: str) -> str:722 """Print the HTML version of a rich-formatted input string.723724 This function does not provide a full HTML page, but can be used to insert
7 unmodified lines