feat: add align_panel_columns to align Rich help panel columns - #1935
Open
spacemonkeyrocks wants to merge 5 commits into
Open
feat: add align_panel_columns to align Rich help panel columns#1935spacemonkeyrocks wants to merge 5 commits into
spacemonkeyrocks wants to merge 5 commits into
Conversation
Add align_option_panels to typer.Typer. When enabled, every Rich help panel is rendered with a shared set of fixed column widths computed from all options in the command, so option columns line up across panels. It defaults to False, preserving existing behaviour. The option-panel row building is reused unchanged; only the table column setup branches on the flag.
Rename align_option_panels to align_panel_columns for clarity (it aligns columns across panels). Public API name changes on the Typer flag; behaviour and tests unchanged.
Windows CI renders Rich panels with ASCII borders (|, +) instead of rounded Unicode (│, ╭). Detect option rows by stripping any leading border char + spaces rather than matching a specific box style, so the new alignment tests pass on Windows too.
Add a ranged option (min/max) and a required-option variant to the align_panel_columns test app so every new code path is covered, keeping the fork at 100% coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add an opt-in
align_panel_columns: bool = Falseoption totyper.Typer.When disabled (the default), behaviour is unchanged: each Rich
--helpoptions panel sizes its own columns independently. When enabled, every panel
is rendered with a shared set of fixed column widths computed from all
options in the command, so the option columns line up across panels.
Motivation
Typer renders each options panel as its own Rich
Tablewith no fixedcolumn widths, so columns drift out of alignment between panels. For a
command with several
rich_help_panelgroups the result is ragged. The twoexamples below are the real
--helpoutput of a CLI with five option panels,at 70 columns.
Off (
align_panel_columns=False):On (
align_panel_columns=True):Notice how
-c,-p,-Y,-f,-H,-Pand-vall start at the samecolumn, and the
<path>/<str>/<int>metavar column lines up, once theflag is enabled.
Implementation
The existing option-row building is reused unchanged; only the table column
setup branches on the flag. When enabled, a shared set of fixed column widths
is derived from every visible option in the command and the same widths are
applied to each panel. No renderer code is duplicated and no existing
behaviour changes unless the option is turned on.
Tests
Added
test_align_panel_columns_true_aligns_columnsandtest_align_panel_columns_false_is_default_unalignedtotests/test_rich_utils.py.