@@ -124,6 +124,7 @@ class Cmd2BaseConsole(Console):
124124
125125 def __init__ (
126126 self ,
127+ * ,
127128 file : IO [str ] | None = None ,
128129 ** kwargs : Any ,
129130 ) -> None :
@@ -180,17 +181,19 @@ def on_broken_pipe(self) -> None:
180181
181182
182183class Cmd2GeneralConsole (Cmd2BaseConsole ):
183- """Rich console for general-purpose printing."""
184+ """Rich console for general-purpose printing.
184185
185- def __init__ (self , file : IO [str ] | None = None ) -> None :
186+ It enables soft wrap and disables Rich's automatic detection for markup,
187+ emoji, and highlighting. These defaults can be overridden in calls to the
188+ console's or cmd2's print methods.
189+ """
190+
191+ def __init__ (self , * , file : IO [str ] | None = None ) -> None :
186192 """Cmd2GeneralConsole initializer.
187193
188194 :param file: optional file object where the console should write to.
189195 Defaults to sys.stdout.
190196 """
191- # This console is configured for general-purpose printing. It enables soft wrap
192- # and disables Rich's automatic detection for markup, emoji, and highlighting.
193- # These defaults can be overridden in calls to the console's or cmd2's print methods.
194197 super ().__init__ (
195198 file = file ,
196199 soft_wrap = True ,
@@ -203,35 +206,55 @@ def __init__(self, file: IO[str] | None = None) -> None:
203206class Cmd2RichArgparseConsole (Cmd2BaseConsole ):
204207 """Rich console for rich-argparse output.
205208
206- This class ensures long lines in help text are not truncated by avoiding soft_wrap,
209+ Ensures long lines in help text are not truncated by disabling soft_wrap,
207210 which conflicts with rich-argparse's explicit no_wrap and overflow settings.
211+
212+ Since this console is used to print error messages which may not be intended
213+ for Rich formatting, it disables Rich's automatic detection for markup, emoji,
214+ and highlighting. Because rich-argparse does markup and highlighting without
215+ involving the console, disabling these settings does not affect the library's
216+ internal functionality.
208217 """
209218
210- def __init__ (self , file : IO [str ] | None = None ) -> None :
219+ def __init__ (self , * , file : IO [str ] | None = None ) -> None :
211220 """Cmd2RichArgparseConsole initializer.
212221
213222 :param file: optional file object where the console should write to.
214223 Defaults to sys.stdout.
215224 """
216- # Since this console is used to print error messages which may not have
217- # been pre-formatted by rich-argparse, disable Rich's automatic detection
218- # for markup, emoji, and highlighting. rich-argparse does markup and
219- # highlighting without involving the console so these won't affect its
220- # internal functionality.
221225 super ().__init__ (
222226 file = file ,
227+ soft_wrap = False ,
223228 markup = False ,
224229 emoji = False ,
225230 highlight = False ,
226231 )
227232
228233
229234class Cmd2ExceptionConsole (Cmd2BaseConsole ):
230- """Rich console for printing exceptions.
235+ """Rich console for printing exceptions and Rich Tracebacks .
231236
232- Ensures that long exception messages word wrap for readability by keeping soft_wrap disabled.
237+ Ensures that output is always word-wrapped for readability and disables
238+ Rich's automatic detection for markup, emoji, and highlighting to prevent
239+ interference with raw error data.
233240 """
234241
242+ def __init__ (self , * , file : IO [str ] | None = None ) -> None :
243+ """Cmd2ExceptionConsole initializer.
244+
245+ :param file: optional file object where the console should write to.
246+ If None, output defaults to sys.stderr.
247+ """
248+ # Use stderr=True so that Rich defaults to sys.stderr if file is None.
249+ super ().__init__ (
250+ file = file ,
251+ stderr = True ,
252+ soft_wrap = False ,
253+ markup = False ,
254+ emoji = False ,
255+ highlight = False ,
256+ )
257+
235258
236259def console_width () -> int :
237260 """Return the width of the console."""
0 commit comments