From c5632b3a703a27ed975667d32fd7ff62097cbed6 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Sat, 23 Nov 2019 18:15:37 -0500 Subject: Added apply_style to pwarning() --- cmd2/cmd2.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'cmd2') diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 85841b30..1eeb4212 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -467,13 +467,17 @@ class Cmd(cmd.Cmd): final_msg = "{}".format(msg) ansi.ansi_aware_write(sys.stderr, final_msg + end) - def pwarning(self, msg: Any, *, end: str = '\n') -> None: - """Apply the warning style to a message and print it to sys.stderr + def pwarning(self, msg: Any, *, end: str = '\n', apply_style: bool = True) -> None: + """Like perror, but applies ansi.style_warning by default :param msg: message to print (anything convertible to a str with '{}'.format() is OK) :param end: string appended after the end of the message, default a newline + :param apply_style: If True, then ansi.style_warning will be applied to the message text. Set to False in cases + where the message text already has the desired style. Defaults to True. """ - self.perror(ansi.style_warning(msg), end=end, apply_style=False) + if apply_style: + msg = ansi.style_warning(msg) + self.perror(msg, end=end, apply_style=False) def pexcept(self, msg: Any, *, end: str = '\n', apply_style: bool = True) -> None: """Print Exception message to sys.stderr. If debug is true, print exception traceback if one exists. @@ -499,7 +503,6 @@ class Cmd(cmd.Cmd): warning = "\nTo enable full traceback, run the following command: 'set debug true'" final_msg += ansi.style_warning(warning) - # Set apply_style to False since style has already been applied self.perror(final_msg, end=end, apply_style=False) def pfeedback(self, msg: Any, *, end: str = '\n') -> None: -- cgit v1.2.1