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

Method print_to

cmd2/cmd2.py:1442–1515  ·  view source on GitHub ↗

Print objects to a given file stream. This method is configured for general-purpose printing. By default, it enables soft wrap and disables Rich's automatic detection for markup, emoji, and highlighting. These defaults can be overridden by passing explicit keyword arguments.

(
        self,
        file: IO[str],
        *objects: Any,
        sep: str = " ",
        end: str = "\n",
        style: StyleType | None = None,
        soft_wrap: bool = True,
        justify: JustifyMethod | None = None,
        emoji: bool = False,
        markup: bool = False,
        highlight: bool = False,
        rich_print_kwargs: Mapping[str, Any] | None = None,
        **kwargs: Any,  # noqa: ARG002
    )

Source from the content-addressed store, hash-verified

1440 return Cmd2BaseConsole(file=file, **kwargs)
1441
1442 def print_to(
1443 self,
1444 file: IO[str],
1445 *objects: Any,
1446 sep: str = " ",
1447 end: str = "\n",
1448 style: StyleType | None = None,
1449 soft_wrap: bool = True,
1450 justify: JustifyMethod | None = None,
1451 emoji: bool = False,
1452 markup: bool = False,
1453 highlight: bool = False,
1454 rich_print_kwargs: Mapping[str, Any] | None = None,
1455 **kwargs: Any, # noqa: ARG002
1456 ) -> None:
1457 """Print objects to a given file stream.
1458
1459 This method is configured for general-purpose printing. By default, it enables
1460 soft wrap and disables Rich's automatic detection for markup, emoji, and highlighting.
1461 These defaults can be overridden by passing explicit keyword arguments.
1462
1463 :param file: file stream being written to
1464 :param objects: objects to print
1465 :param sep: string to write between printed text. Defaults to " ".
1466 :param end: string to write at end of printed text. Defaults to a newline.
1467 :param style: optional style to apply to output
1468 :param soft_wrap: Enable soft wrap mode. Defaults to True.
1469 If True, text that doesn't fit will run on to the following line,
1470 just like the built-in print() function. This is useful for raw text
1471 and logs.
1472 If False, Rich wraps text to fit the terminal width.
1473 Set this to False when printing structured Renderables like
1474 Tables, Panels, or Columns to ensure they render as expected.
1475 For example, when soft_wrap is True Panels truncate text
1476 which is wider than the terminal.
1477 :param justify: justify method ("left", "center", "right", "full"). Defaults to None.
1478 :param emoji: If True, Rich will replace emoji codes (e.g., :smiley:) with their
1479 corresponding Unicode characters. Defaults to False.
1480 :param markup: If True, Rich will interpret strings with tags (e.g., [bold]hello[/bold])
1481 as styled output. Defaults to False.
1482 :param highlight: If True, Rich will automatically apply highlighting to elements within
1483 strings, such as common Python data types like numbers, booleans, or None.
1484 This is particularly useful when pretty printing objects like lists and
1485 dictionaries to display them in color. Defaults to False.
1486 :param rich_print_kwargs: optional additional keyword arguments to pass to console.print().
1487 :param kwargs: Arbitrary keyword arguments. This allows subclasses to extend the signature of this
1488 method and still call `super()` without encountering unexpected keyword argument errors.
1489 These arguments are not passed to console.print().
1490
1491 See the Rich documentation for more details on emoji codes, markup tags, and highlighting.
1492 """
1493 try:
1494 self._get_core_print_console(
1495 file=file,
1496 emoji=emoji,
1497 markup=markup,
1498 highlight=highlight,
1499 ).print(

Callers 5

poutputMethod · 0.95
perrorMethod · 0.95
pexceptMethod · 0.95
pprettyMethod · 0.95
py_printMethod · 0.95

Calls 3

Cmd2GeneralConsoleClass · 0.85
printMethod · 0.80

Tested by

no test coverage detected