diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-11-23 18:35:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-23 18:35:08 -0500 |
commit | aeb517d7249b6f17cbb0d09a1a22f2d689be1d57 (patch) | |
tree | 6fa03bbfe2c031d5312861e86f7e8f828d633a09 /cmd2/cmd2.py | |
parent | 3f1b75df79fb2616d43faaa3c30552953c55488b (diff) | |
parent | c5632b3a703a27ed975667d32fd7ff62097cbed6 (diff) | |
download | cmd2-git-aeb517d7249b6f17cbb0d09a1a22f2d689be1d57.tar.gz |
Merge pull request #817 from python-cmd2/pwarning
Added apply_style to pwarning()
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 11 |
1 files changed, 7 insertions, 4 deletions
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: |