6363 cast ,
6464)
6565
66- from rich .box import SIMPLE_HEAD
66+ import rich .box
6767from rich .console import Group
68+ from rich .padding import Padding
6869from rich .rule import Rule
6970from rich .style import Style , StyleType
7071from rich .table import (
@@ -2125,7 +2126,7 @@ def _display_matches_gnu_readline(
21252126 if self .formatted_completions :
21262127 if not hint_printed :
21272128 sys .stdout .write ('\n ' )
2128- sys .stdout .write (' \n ' + self .formatted_completions + ' \n ' )
2129+ sys .stdout .write (self .formatted_completions )
21292130
21302131 # Otherwise use readline's formatter
21312132 else :
@@ -2182,7 +2183,7 @@ def _display_matches_pyreadline(self, matches: list[str]) -> None: # pragma: no
21822183 if self .formatted_completions :
21832184 if not hint_printed :
21842185 sys .stdout .write ('\n ' )
2185- sys .stdout .write (' \n ' + self .formatted_completions + ' \n ' )
2186+ sys .stdout .write (self .formatted_completions )
21862187
21872188 # Redraw the prompt and input lines
21882189 rl_force_redisplay ()
@@ -4121,8 +4122,13 @@ def do_help(self, args: argparse.Namespace) -> None:
41214122 cmds_cats , cmds_doc , cmds_undoc , help_topics = self ._build_command_info ()
41224123
41234124 if self .doc_leader :
4125+ # Indent doc_leader to align with the help tables.
41244126 self .poutput ()
4125- self .poutput (self .doc_leader , style = Cmd2Style .HELP_LEADER , soft_wrap = False )
4127+ self .poutput (
4128+ Padding .indent (self .doc_leader , 1 ),
4129+ style = Cmd2Style .HELP_LEADER ,
4130+ soft_wrap = False ,
4131+ )
41264132 self .poutput ()
41274133
41284134 if not cmds_cats :
@@ -4167,6 +4173,9 @@ def print_topics(self, header: str, cmds: list[str] | None, cmdlen: int, maxcol:
41674173
41684174 Override of cmd's print_topics() to use Rich.
41694175
4176+ The output for both the header and the commands is indented by one space to align
4177+ with the tables printed by the `help -v` command.
4178+
41704179 :param header: string to print above commands being printed
41714180 :param cmds: list of topics to print
41724181 :param cmdlen: unused, even by cmd's version
@@ -4177,9 +4186,13 @@ def print_topics(self, header: str, cmds: list[str] | None, cmdlen: int, maxcol:
41774186
41784187 header_grid = Table .grid ()
41794188 header_grid .add_row (header , style = Cmd2Style .HELP_HEADER )
4180- header_grid .add_row (Rule (characters = self .ruler ))
4181- self .poutput (header_grid )
4182- self .columnize (cmds , maxcol - 1 )
4189+ header_grid .add_row (Rule (characters = self .ruler , style = Cmd2Style .TABLE_BORDER ))
4190+ self .poutput (Padding .indent (header_grid , 1 ))
4191+
4192+ # Subtract 1 from maxcol to account for indentation.
4193+ maxcol = min (maxcol , ru .console_width ()) - 1
4194+ columnized_cmds = self .render_columns (cmds , maxcol )
4195+ self .poutput (Padding .indent (columnized_cmds , 1 ), soft_wrap = False )
41834196 self .poutput ()
41844197
41854198 def _print_documented_command_topics (self , header : str , cmds : list [str ], verbose : bool ) -> None :
@@ -4193,15 +4206,17 @@ def _print_documented_command_topics(self, header: str, cmds: list[str], verbose
41934206 self .print_topics (header , cmds , 15 , 80 )
41944207 return
41954208
4196- category_grid = Table .grid ()
4197- category_grid .add_row (header , style = Cmd2Style .HELP_HEADER )
4198- category_grid .add_row (Rule (characters = self .ruler ))
4209+ # Indent header to align with the help tables.
4210+ self .poutput (
4211+ Padding .indent (header , 1 ),
4212+ style = Cmd2Style .HELP_HEADER ,
4213+ soft_wrap = False ,
4214+ )
41994215 topics_table = Table (
42004216 Column ("Name" , no_wrap = True ),
42014217 Column ("Description" , overflow = "fold" ),
4202- box = SIMPLE_HEAD ,
4203- border_style = Cmd2Style .RULE_LINE ,
4204- show_edge = False ,
4218+ box = rich .box .HORIZONTALS ,
4219+ border_style = Cmd2Style .TABLE_BORDER ,
42054220 )
42064221
42074222 # Try to get the documentation string for each command
@@ -4240,8 +4255,8 @@ def _print_documented_command_topics(self, header: str, cmds: list[str], verbose
42404255 # Add this command to the table
42414256 topics_table .add_row (command , cmd_desc )
42424257
4243- category_grid . add_row (topics_table )
4244- self .poutput (category_grid , "" )
4258+ self . poutput (topics_table )
4259+ self .poutput ()
42454260
42464261 def render_columns (self , str_list : list [str ] | None , display_width : int = 80 ) -> str :
42474262 """Render a list of single-line strings as a compact set of columns.
@@ -4519,9 +4534,8 @@ def do_set(self, args: argparse.Namespace) -> None:
45194534 Column ("Name" , no_wrap = True ),
45204535 Column ("Value" , overflow = "fold" ),
45214536 Column ("Description" , overflow = "fold" ),
4522- box = SIMPLE_HEAD ,
4523- border_style = Cmd2Style .RULE_LINE ,
4524- show_edge = False ,
4537+ box = rich .box .SIMPLE_HEAD ,
4538+ border_style = Cmd2Style .TABLE_BORDER ,
45254539 )
45264540
45274541 # Build the table and populate self.last_result
@@ -4532,9 +4546,7 @@ def do_set(self, args: argparse.Namespace) -> None:
45324546 settable_table .add_row (param , str (settable .get_value ()), settable .description )
45334547 self .last_result [param ] = settable .get_value ()
45344548
4535- self .poutput ()
45364549 self .poutput (settable_table )
4537- self .poutput ()
45384550
45394551 @classmethod
45404552 def _build_shell_parser (cls ) -> Cmd2ArgumentParser :
0 commit comments