diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 252848d7..70c915f5 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1211,8 +1211,21 @@ def visible_prompt(self) -> str: return ansi.strip_style(self.prompt) def print_to( - self, dest: Union[TextIO, IO[str]], msg: Any, *, end: str = '\n', style: Optional[Callable[[str], str]] = None + self, + dest: IO[str], + msg: Any, + *, + end: str = '\n', + style: Optional[Callable[[str], str]] = None, ) -> None: + """ + Print message to a given file object. + + :param dest: the file object being written to + :param msg: object to print + :param end: string appended after the end of the message, default a newline + :param style: optional style function to format msg with (e.g. ansi.style_success) + """ final_msg = style(msg) if style is not None else msg try: ansi.style_aware_write(dest, f'{final_msg}{end}')