Skip to content
Myr

✨ Improve column help display, ensure commands column width is the same on all panels (#567)

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

authored by Sorin Sbarnea · committed by GitHub · parent 475359f · Browse files · 1 file+22 added−1 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: svlandeg <sofie.vanlandeghem@gmail.com>
  • Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

Diff stats

1 file+22 added−1 removed

  • other:+22 added−1 removed

1 file+22 added−1 removed

modified:typer/rich_utils.py+22 added-1 removed
464 unmodified lines
465 name: str,466 commands: List[click.Command],467 markup_mode: MarkupMode,468 console: Console,469 cmd_len: int,470) -> None:471 t_styles: Dict[str, Any] = {472 "show_lines": STYLE_COMMANDS_TABLE_SHOW_LINES,473 "leading": STYLE_COMMANDS_TABLE_LEADING,
13 unmodified lines
487 **t_styles,488 )489 # Define formatting in first column, as commands don't match highlighter490 # regex490 commands_table.add_column(style="bold cyan", no_wrap=True)491 commands_table.add_column(492 style="bold cyan",493 no_wrap=True,494 width=cmd_len,495 )496497 # A big ratio makes the description column be greedy and take all the space498 # available instead of allowing the command column to grow and misalign with499 # other panels.500 commands_table.add_column("Description", justify="left", no_wrap=False, ratio=10)501 rows: List[List[Union[RenderableType, None]]] = []502 deprecated_rows: List[Union[RenderableType, None]] = []503 for command in commands:504 helptext = command.short_help or command.help or ""
132 unmodified lines
637 or COMMANDS_PANEL_TITLE638 )639 panel_to_commands[panel_name].append(command)640641 # Identify the longest command name in all panels642 max_cmd_len = max(643 [644 len(command.name or "")645 for commands in panel_to_commands.values()646 for command in commands647 ]648 )649650 # Print each command group panel651 default_commands = panel_to_commands.get(COMMANDS_PANEL_TITLE, [])652 _print_commands_panel(653 name=COMMANDS_PANEL_TITLE,654 commands=default_commands,655 markup_mode=markup_mode,656 console=console,657 cmd_len=max_cmd_len,658 )659 for panel_name, commands in panel_to_commands.items():660 if panel_name == COMMANDS_PANEL_TITLE:661 # Already printed above
2 unmodified lines
664 name=panel_name,665 commands=commands,666 markup_mode=markup_mode,667 console=console,668 cmd_len=max_cmd_len,669 )670671 # Epilogue if we have it672 if obj.epilog:
38 unmodified lines