summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/cmd2.py8
-rw-r--r--cmd2/utils.py4
-rw-r--r--tests/test_utils.py4
3 files changed, 7 insertions, 9 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 48390861..eb745da5 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -601,7 +601,7 @@ class Cmd(cmd.Cmd):
"""
if msg is not None and msg != '':
try:
- final_msg = utils.style_message(msg, end=end, fg=fg, bg=bg)
+ final_msg = utils.style_message(msg, fg=fg, bg=bg) + end
self._decolorized_write(self.stdout, final_msg)
except BrokenPipeError:
# This occurs if a command's output is being piped to another
@@ -621,7 +621,7 @@ class Cmd(cmd.Cmd):
:param bg: (optional) Background color. Accepts color names like 'red' or 'blue'
"""
if msg is not None and msg != '':
- err_msg = utils.style_message(msg, end=end, fg=fg, bg=bg)
+ err_msg = utils.style_message(msg, fg=fg, bg=bg) + end
self._decolorized_write(sys.stderr, err_msg)
def pexcept(self, msg: Any, end: str = '\n', fg: str = 'lightred', bg: str = '') -> None:
@@ -641,12 +641,12 @@ class Cmd(cmd.Cmd):
else:
err_msg = msg
- err_msg = utils.style_message(err_msg, end=end, fg=fg, bg=bg)
+ err_msg = utils.style_message(err_msg, fg=fg, bg=bg) + end
self._decolorized_write(sys.stderr, err_msg)
if not self.debug:
warning = "To enable full traceback, run the following command: 'set debug true'"
- warning = utils.style_message(warning, fg="lightyellow")
+ warning = utils.style_message(warning, fg="lightyellow") + end
self._decolorized_write(sys.stderr, warning)
def pfeedback(self, msg: str) -> None:
diff --git a/cmd2/utils.py b/cmd2/utils.py
index 791daba9..8252546c 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -36,12 +36,11 @@ def ansi_safe_wcswidth(text: str) -> int:
return wcswidth(strip_ansi(text))
-def style_message(msg: Any, end: str = '\n', fg: str = '', bg: str = '') -> str:
+def style_message(msg: Any, *, fg: str = '', bg: str = '') -> str:
"""
Styles a message
:param msg: Any object compatible with str.format()
- :param end: (optional) Ending character similar to python's print()
:param fg: (optional) Foreground color. Accepts color names like 'red' or 'blue'
:param bg: (optional) Background color. Accepts color names like 'red' or 'blue'
@@ -63,7 +62,6 @@ def style_message(msg: Any, end: str = '\n', fg: str = '', bg: str = '') -> str:
values.append(constants.FG_COLORS['reset'])
if bg:
values.append(constants.BG_COLORS['reset'])
- values.append(end)
return "".join(values)
diff --git a/tests/test_utils.py b/tests/test_utils.py
index f43aed4e..ada8bc86 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -27,8 +27,8 @@ def test_ansi_safe_wcswidth():
def test_style_message():
base_str = HELLO_WORLD
- ansi_str = Fore.BLUE + Back.GREEN + base_str + Fore.RESET + Back.RESET + '\n\n'
- assert cu.style_message(base_str, end='\n\n', fg='blue', bg='green')
+ ansi_str = Fore.BLUE + Back.GREEN + base_str + Fore.RESET + Back.RESET
+ assert cu.style_message(base_str, fg='blue', bg='green') == ansi_str
def test_style_message_color_not_exist():
base_str = HELLO_WORLD