154154 Cmd2ExceptionConsole ,
155155 Cmd2GeneralConsole ,
156156 Cmd2SimpleTable ,
157- RichPrintKwargs ,
158157 TextGroup ,
159158)
160159from .styles import Cmd2Style
@@ -474,6 +473,19 @@ def __init__(
474473 self .scripts_add_to_history = True # Scripts and pyscripts add commands to history
475474 self .timing = False # Prints elapsed time for each command
476475
476+ # Default settings for Rich tracebacks created by format_exception().
477+ # This dictionary can contain any parameter accepted by the
478+ # rich.traceback.Traceback class. You can modify it to adjust
479+ # the detail and layout of tracebacks.
480+ self .traceback_kwargs : dict [str , Any ] = {
481+ "width" : 100 ,
482+ "code_width" : None , # Show all code characters
483+ "show_locals" : False ,
484+ "max_frames" : 100 ,
485+ "word_wrap" : True , # Wrap long lines of code instead of truncate
486+ "indent_guides" : True ,
487+ }
488+
477489 # Cached Rich consoles used by core print methods.
478490 self ._console_cache = _ConsoleCache ()
479491
@@ -1339,19 +1351,28 @@ def allow_style_type(value: str) -> ru.AllowStyle:
13391351 self .add_settable (Settable ("quiet" , bool , "Don't print nonessential feedback" , self ))
13401352 self .add_settable (Settable ("scripts_add_to_history" , bool , "Scripts and pyscripts add commands to history" , self ))
13411353 self .add_settable (Settable ("timing" , bool , "Report execution times" , self ))
1342-
1343- # ----- Methods related to presenting output to the user -----
1354+ self .add_settable (Settable ("traceback_show_locals" , bool , "Display local variables in tracebacks" , self ))
13441355
13451356 @property
13461357 def allow_style (self ) -> ru .AllowStyle :
1347- """Read-only property needed to support do_set when it reads allow_style."""
1358+ """Property needed to support do_set when it reads allow_style."""
13481359 return ru .ALLOW_STYLE
13491360
13501361 @allow_style .setter
13511362 def allow_style (self , new_val : ru .AllowStyle ) -> None :
13521363 """Setter property needed to support do_set when it updates allow_style."""
13531364 ru .ALLOW_STYLE = new_val
13541365
1366+ @property
1367+ def traceback_show_locals (self ) -> bool :
1368+ """Property needed to support do_set when it reads traceback_show_locals."""
1369+ return cast (bool , self .traceback_kwargs .get ("show_locals" , False ))
1370+
1371+ @traceback_show_locals .setter
1372+ def traceback_show_locals (self , value : bool ) -> None :
1373+ """Setter property needed to support do_set when it updates traceback_show_locals."""
1374+ self .traceback_kwargs ["show_locals" ] = value
1375+
13551376 @property
13561377 def visible_prompt (self ) -> str :
13571378 """Read-only property to get the visible prompt with any ANSI style sequences stripped.
@@ -1426,7 +1447,7 @@ def print_to(
14261447 emoji : bool = False ,
14271448 markup : bool = False ,
14281449 highlight : bool = False ,
1429- rich_print_kwargs : RichPrintKwargs | None = None ,
1450+ rich_print_kwargs : Mapping [ str , Any ] | None = None ,
14301451 ** kwargs : Any , # noqa: ARG002
14311452 ) -> None :
14321453 """Print objects to a given file stream.
@@ -1442,7 +1463,8 @@ def print_to(
14421463 :param style: optional style to apply to output
14431464 :param soft_wrap: Enable soft wrap mode. Defaults to True.
14441465 If True, text that doesn't fit will run on to the following line,
1445- just like with print(). This is useful for raw text and logs.
1466+ just like the built-in print() function. This is useful for raw text
1467+ and logs.
14461468 If False, Rich wraps text to fit the terminal width.
14471469 Set this to False when printing structured Renderables like
14481470 Tables, Panels, or Columns to ensure they render as expected.
@@ -1457,10 +1479,10 @@ def print_to(
14571479 strings, such as common Python data types like numbers, booleans, or None.
14581480 This is particularly useful when pretty printing objects like lists and
14591481 dictionaries to display them in color. Defaults to False.
1460- :param rich_print_kwargs: optional additional keyword arguments to pass to Rich's Console .print().
1482+ :param rich_print_kwargs: optional additional keyword arguments to pass to console .print().
14611483 :param kwargs: Arbitrary keyword arguments. This allows subclasses to extend the signature of this
14621484 method and still call `super()` without encountering unexpected keyword argument errors.
1463- These arguments are not passed to Rich's Console .print().
1485+ These arguments are not passed to console .print().
14641486
14651487 See the Rich documentation for more details on emoji codes, markup tags, and highlighting.
14661488 """
@@ -1499,7 +1521,7 @@ def poutput(
14991521 emoji : bool = False ,
15001522 markup : bool = False ,
15011523 highlight : bool = False ,
1502- rich_print_kwargs : RichPrintKwargs | None = None ,
1524+ rich_print_kwargs : Mapping [ str , Any ] | None = None ,
15031525 ** kwargs : Any , # noqa: ARG002
15041526 ) -> None :
15051527 """Print objects to self.stdout.
@@ -1531,7 +1553,7 @@ def perror(
15311553 emoji : bool = False ,
15321554 markup : bool = False ,
15331555 highlight : bool = False ,
1534- rich_print_kwargs : RichPrintKwargs | None = None ,
1556+ rich_print_kwargs : Mapping [ str , Any ] | None = None ,
15351557 ** kwargs : Any , # noqa: ARG002
15361558 ) -> None :
15371559 """Print objects to sys.stderr.
@@ -1564,7 +1586,7 @@ def psuccess(
15641586 emoji : bool = False ,
15651587 markup : bool = False ,
15661588 highlight : bool = False ,
1567- rich_print_kwargs : RichPrintKwargs | None = None ,
1589+ rich_print_kwargs : Mapping [ str , Any ] | None = None ,
15681590 ** kwargs : Any , # noqa: ARG002
15691591 ) -> None :
15701592 """Wrap poutput, but apply Cmd2Style.SUCCESS.
@@ -1594,7 +1616,7 @@ def pwarning(
15941616 emoji : bool = False ,
15951617 markup : bool = False ,
15961618 highlight : bool = False ,
1597- rich_print_kwargs : RichPrintKwargs | None = None ,
1619+ rich_print_kwargs : Mapping [ str , Any ] | None = None ,
15981620 ** kwargs : Any , # noqa: ARG002
15991621 ) -> None :
16001622 """Wrap perror, but apply Cmd2Style.WARNING.
@@ -1626,13 +1648,7 @@ def format_exception(self, exception: BaseException) -> str:
16261648 with console .capture () as capture :
16271649 # Only print a traceback if we're in debug mode and one exists.
16281650 if self .debug and sys .exc_info () != (None , None , None ):
1629- traceback = Traceback (
1630- width = None , # Use all available width
1631- code_width = None , # Use all available width
1632- show_locals = True ,
1633- max_frames = 0 , # 0 means full traceback.
1634- word_wrap = True , # Wrap long lines of code instead of truncate
1635- )
1651+ traceback = Traceback (** self .traceback_kwargs )
16361652 console .print (traceback , end = "" )
16371653
16381654 else :
@@ -1690,7 +1706,7 @@ def pfeedback(
16901706 emoji : bool = False ,
16911707 markup : bool = False ,
16921708 highlight : bool = False ,
1693- rich_print_kwargs : RichPrintKwargs | None = None ,
1709+ rich_print_kwargs : Mapping [ str , Any ] | None = None ,
16941710 ** kwargs : Any , # noqa: ARG002
16951711 ) -> None :
16961712 """Print nonessential feedback.
@@ -1740,7 +1756,7 @@ def ppaged(
17401756 emoji : bool = False ,
17411757 markup : bool = False ,
17421758 highlight : bool = False ,
1743- rich_print_kwargs : RichPrintKwargs | None = None ,
1759+ rich_print_kwargs : Mapping [ str , Any ] | None = None ,
17441760 ** kwargs : Any , # noqa: ARG002
17451761 ) -> None :
17461762 """Print output using a pager.
0 commit comments