63
63
cast ,
64
64
)
65
65
66
- from rich .box import SIMPLE_HEAD
66
+ import rich .box
67
67
from rich .console import Group
68
+ from rich .padding import Padding
68
69
from rich .rule import Rule
69
70
from rich .style import Style , StyleType
70
71
from rich .table import (
@@ -2125,7 +2126,7 @@ def _display_matches_gnu_readline(
2125
2126
if self .formatted_completions :
2126
2127
if not hint_printed :
2127
2128
sys .stdout .write ('\n ' )
2128
- sys .stdout .write (' \n ' + self .formatted_completions + ' \n ' )
2129
+ sys .stdout .write (self .formatted_completions )
2129
2130
2130
2131
# Otherwise use readline's formatter
2131
2132
else :
@@ -2182,7 +2183,7 @@ def _display_matches_pyreadline(self, matches: list[str]) -> None: # pragma: no
2182
2183
if self .formatted_completions :
2183
2184
if not hint_printed :
2184
2185
sys .stdout .write ('\n ' )
2185
- sys .stdout .write (' \n ' + self .formatted_completions + ' \n ' )
2186
+ sys .stdout .write (self .formatted_completions )
2186
2187
2187
2188
# Redraw the prompt and input lines
2188
2189
rl_force_redisplay ()
@@ -4121,8 +4122,13 @@ def do_help(self, args: argparse.Namespace) -> None:
4121
4122
cmds_cats , cmds_doc , cmds_undoc , help_topics = self ._build_command_info ()
4122
4123
4123
4124
if self .doc_leader :
4125
+ # Indent doc_leader to align with the help tables.
4124
4126
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
+ )
4126
4132
self .poutput ()
4127
4133
4128
4134
if not cmds_cats :
@@ -4167,6 +4173,9 @@ def print_topics(self, header: str, cmds: list[str] | None, cmdlen: int, maxcol:
4167
4173
4168
4174
Override of cmd's print_topics() to use Rich.
4169
4175
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
+
4170
4179
:param header: string to print above commands being printed
4171
4180
:param cmds: list of topics to print
4172
4181
: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:
4177
4186
4178
4187
header_grid = Table .grid ()
4179
4188
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 )
4183
4196
self .poutput ()
4184
4197
4185
4198
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
4193
4206
self .print_topics (header , cmds , 15 , 80 )
4194
4207
return
4195
4208
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
+ )
4199
4215
topics_table = Table (
4200
4216
Column ("Name" , no_wrap = True ),
4201
4217
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 ,
4205
4220
)
4206
4221
4207
4222
# 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
4240
4255
# Add this command to the table
4241
4256
topics_table .add_row (command , cmd_desc )
4242
4257
4243
- category_grid . add_row (topics_table )
4244
- self .poutput (category_grid , "" )
4258
+ self . poutput (topics_table )
4259
+ self .poutput ()
4245
4260
4246
4261
def render_columns (self , str_list : list [str ] | None , display_width : int = 80 ) -> str :
4247
4262
"""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:
4519
4534
Column ("Name" , no_wrap = True ),
4520
4535
Column ("Value" , overflow = "fold" ),
4521
4536
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 ,
4525
4539
)
4526
4540
4527
4541
# Build the table and populate self.last_result
@@ -4532,9 +4546,7 @@ def do_set(self, args: argparse.Namespace) -> None:
4532
4546
settable_table .add_row (param , str (settable .get_value ()), settable .description )
4533
4547
self .last_result [param ] = settable .get_value ()
4534
4548
4535
- self .poutput ()
4536
4549
self .poutput (settable_table )
4537
- self .poutput ()
4538
4550
4539
4551
@classmethod
4540
4552
def _build_shell_parser (cls ) -> Cmd2ArgumentParser :
0 commit comments