summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-11-23 18:15:37 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-11-23 18:15:37 -0500
commitc5632b3a703a27ed975667d32fd7ff62097cbed6 (patch)
tree6fa03bbfe2c031d5312861e86f7e8f828d633a09 /cmd2
parent3f1b75df79fb2616d43faaa3c30552953c55488b (diff)
downloadcmd2-git-c5632b3a703a27ed975667d32fd7ff62097cbed6.tar.gz
Added apply_style to pwarning()
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/cmd2.py11
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: