Skip to content

Commit

Permalink
Added docstring to Cmd.print_to().
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvanbrunt committed Dec 18, 2024
1 parent 5a34460 commit a8431f7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down

0 comments on commit a8431f7

Please sign in to comment.