MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / __init__

Method __init__

cmd2/rich_utils.py:372–430  ·  view source on GitHub ↗

Cmd2BaseConsole initializer. :param file: optional file object where the console should write to. Defaults to sys.stdout. :param kwargs: keyword arguments passed to the parent Console class. :raises TypeError: if disallowed keyword argument is passed in.

(
        self,
        *,
        file: IO[str] | None = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

370 """
371
372 def __init__(
373 self,
374 *,
375 file: IO[str] | None = None,
376 **kwargs: Any,
377 ) -> None:
378 """Cmd2BaseConsole initializer.
379
380 :param file: optional file object where the console should write to.
381 Defaults to sys.stdout.
382 :param kwargs: keyword arguments passed to the parent Console class.
383 :raises TypeError: if disallowed keyword argument is passed in.
384 """
385 # These settings are controlled by the ALLOW_STYLE setting and cannot be overridden.
386 if "color_system" in kwargs:
387 raise TypeError("Passing 'color_system' is not allowed. Its behavior is controlled by the 'ALLOW_STYLE' setting.")
388 if "force_terminal" in kwargs:
389 raise TypeError(
390 "Passing 'force_terminal' is not allowed. Its behavior is controlled by the 'ALLOW_STYLE' setting."
391 )
392 if "force_interactive" in kwargs:
393 raise TypeError(
394 "Passing 'force_interactive' is not allowed. Its behavior is controlled by the 'ALLOW_STYLE' setting."
395 )
396
397 # Don't allow a theme to be passed in, as it is controlled by get_theme() and set_theme().
398 # Use cmd2.rich_utils.set_theme() to set the global theme or use a temporary
399 # theme with console.use_theme().
400 if "theme" in kwargs:
401 raise TypeError("Passing 'theme' is not allowed. Its behavior is controlled by get_theme() and set_theme().")
402
403 # Store the configuration key used by cmd2 to cache this console.
404 self._config_key = self._build_config_key(file=file, **kwargs)
405
406 force_terminal: bool | None = None
407 force_interactive: bool | None = None
408 allow_style = False
409
410 if ALLOW_STYLE == AllowStyle.ALWAYS:
411 force_terminal = True
412 allow_style = True
413
414 # Turn off interactive mode if dest is not a terminal which supports it.
415 tmp_console = Console(file=file)
416 force_interactive = tmp_console.is_interactive
417 elif ALLOW_STYLE == AllowStyle.TERMINAL:
418 tmp_console = Console(file=file)
419 allow_style = tmp_console.is_terminal
420 elif ALLOW_STYLE == AllowStyle.NEVER:
421 force_terminal = False
422
423 super().__init__(
424 file=file,
425 color_system="truecolor" if allow_style else None,
426 force_terminal=force_terminal,
427 force_interactive=force_interactive,
428 theme=get_theme(),
429 **kwargs,

Callers

nothing calls this directly

Calls 3

_build_config_keyMethod · 0.95
get_themeFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected