6868 cast ,
6969)
7070
71- import rich .box
7271from prompt_toolkit import (
7372 filters ,
7473 print_formatted_text ,
160159 Cmd2BaseConsole ,
161160 Cmd2ExceptionConsole ,
162161 Cmd2GeneralConsole ,
162+ Cmd2SimpleTable ,
163163 RichPrintKwargs ,
164164)
165165from .styles import Cmd2Style
@@ -517,9 +517,6 @@ def __init__(
517517 # Used to keep track of whether we are redirecting or piping output
518518 self ._redirecting = False
519519
520- # Characters used to draw a horizontal rule. Should not be blank.
521- self .ruler = "─"
522-
523520 # Set text which prints right before all of the help tables are listed.
524521 self .doc_leader = ""
525522
@@ -4185,6 +4182,15 @@ def do_help(self, args: argparse.Namespace) -> None:
41854182 self .perror (err_msg , style = None )
41864183 self .last_result = False
41874184
4185+ def _create_help_grid (self , title : str , * content : RenderableType ) -> Table :
4186+ """Create a titled grid for help headers with a ruler and optional content."""
4187+ grid = Table .grid ()
4188+ grid .add_row (Text (title , style = Cmd2Style .HELP_HEADER ))
4189+ grid .add_row (Rule (style = Cmd2Style .TABLE_BORDER ))
4190+ for item in content :
4191+ grid .add_row (item )
4192+ return grid
4193+
41884194 def print_topics (self , header : str , cmds : Sequence [str ] | None , cmdlen : int , maxcol : int ) -> None : # noqa: ARG002
41894195 """Print groups of commands and topics in columns and an optional header.
41904196
@@ -4198,12 +4204,11 @@ def print_topics(self, header: str, cmds: Sequence[str] | None, cmdlen: int, max
41984204 if not cmds :
41994205 return
42004206
4201- # Print a row that looks like a table header.
42024207 if header :
4203- header_grid = Table . grid ()
4204- header_grid . add_row ( Text ( header , style = Cmd2Style . HELP_HEADER ))
4205- header_grid . add_row ( Rule ( characters = self . ruler , style = Cmd2Style . TABLE_BORDER ))
4206- self . poutput ( header_grid , soft_wrap = False )
4208+ self . poutput (
4209+ self . _create_help_grid ( header ),
4210+ soft_wrap = False ,
4211+ )
42074212
42084213 # Subtract 1 from maxcol to account for a one-space right margin.
42094214 maxcol = min (maxcol , ru .console_width ()) - 1
@@ -4221,17 +4226,9 @@ def _print_documented_command_topics(self, header: str, cmds: Sequence[str], ver
42214226 self .print_topics (header , cmds , 15 , 80 )
42224227 return
42234228
4224- # Create a grid to hold the header and the topics table
4225- category_grid = Table .grid ()
4226- category_grid .add_row (Text (header , style = Cmd2Style .HELP_HEADER ))
4227- category_grid .add_row (Rule (characters = self .ruler , style = Cmd2Style .TABLE_BORDER ))
4228-
4229- topics_table = Table (
4229+ topic_table = Cmd2SimpleTable (
42304230 Column ("Name" , no_wrap = True ),
42314231 Column ("Description" , overflow = "fold" ),
4232- box = rich .box .SIMPLE_HEAD ,
4233- show_edge = False ,
4234- border_style = Cmd2Style .TABLE_BORDER ,
42354232 )
42364233
42374234 # Try to get the documentation string for each command
@@ -4268,10 +4265,12 @@ def _print_documented_command_topics(self, header: str, cmds: Sequence[str], ver
42684265 cmd_desc = strip_doc_annotations (doc ) if doc else ''
42694266
42704267 # Add this command to the table
4271- topics_table .add_row (command , cmd_desc )
4268+ topic_table .add_row (command , cmd_desc )
42724269
4273- category_grid .add_row (topics_table )
4274- self .poutput (category_grid , soft_wrap = False )
4270+ self .poutput (
4271+ self ._create_help_grid (header , topic_table ),
4272+ soft_wrap = False ,
4273+ )
42754274 self .poutput ()
42764275
42774276 def render_columns (self , str_list : Sequence [str ] | None , display_width : int = 80 ) -> str :
@@ -4560,14 +4559,10 @@ def do_set(self, args: argparse.Namespace) -> None:
45604559 # Show all settables
45614560 to_show = list (self .settables .keys ())
45624561
4563- # Define the table structure
4564- settable_table = Table (
4562+ settable_table = Cmd2SimpleTable (
45654563 Column ("Name" , no_wrap = True ),
45664564 Column ("Value" , overflow = "fold" ),
45674565 Column ("Description" , overflow = "fold" ),
4568- box = rich .box .SIMPLE_HEAD ,
4569- show_edge = False ,
4570- border_style = Cmd2Style .TABLE_BORDER ,
45714566 )
45724567
45734568 # Build the table and populate self.last_result
0 commit comments