diff options
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index d2610cc3..02462d96 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -42,6 +42,7 @@ from collections import namedtuple from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Type, Union, IO import colorama +from colorama import Fore from . import constants from . import plugin @@ -58,7 +59,7 @@ if rl_type == RlType.NONE: # pragma: no cover rl_warning = "Readline features including tab completion have been disabled since no \n" \ "supported version of readline was found. To resolve this, install \n" \ "pyreadline on Windows or gnureadline on Mac.\n\n" - sys.stderr.write(constants.WARNING_COLOR + rl_warning + constants.RESET_COLOR) + sys.stderr.write(Fore.LIGHTYELLOW_EX + rl_warning + Fore.RESET) else: from .rl_utils import rl_force_redisplay, readline @@ -615,7 +616,7 @@ class Cmd(cmd.Cmd): if not msg_str.endswith(end): msg_str += end if color: - msg_str = color + msg_str + constants.RESET_COLOR + msg_str = color + msg_str + Fore.RESET self.decolorized_write(self.stdout, msg_str) except BrokenPipeError: # This occurs if a command's output is being piped to another @@ -626,8 +627,8 @@ class Cmd(cmd.Cmd): if self.broken_pipe_warning: sys.stderr.write(self.broken_pipe_warning) - def perror(self, err: Union[str, Exception], traceback_war: bool = True, err_color: str = constants.ERROR_COLOR, - war_color: str = constants.WARNING_COLOR) -> None: + def perror(self, err: Union[str, Exception], traceback_war: bool = True, err_color: str = Fore.LIGHTRED_EX, + war_color: str = Fore.LIGHTYELLOW_EX) -> None: """ Print error message to sys.stderr and if debug is true, print an exception Traceback if one exists. :param err: an Exception or error message to print out @@ -643,12 +644,12 @@ class Cmd(cmd.Cmd): err_msg = "EXCEPTION of type '{}' occurred with message: '{}'\n".format(type(err).__name__, err) else: err_msg = "{}\n".format(err) - err_msg = err_color + err_msg + constants.RESET_COLOR + err_msg = err_color + err_msg + Fore.RESET self.decolorized_write(sys.stderr, err_msg) if traceback_war and not self.debug: war = "To enable full traceback, run the following command: 'set debug true'\n" - war = war_color + war + constants.RESET_COLOR + war = war_color + war + Fore.RESET self.decolorized_write(sys.stderr, war) def pfeedback(self, msg: str) -> None: @@ -3574,7 +3575,7 @@ class Cmd(cmd.Cmd): # Check if all commands ran if commands_run < len(history): warning = "Command {} triggered a stop and ended transcript generation early".format(commands_run) - self.perror(warning, err_color=constants.WARNING_COLOR, traceback_war=False) + self.perror(warning, err_color=Fore.LIGHTYELLOW_EX, traceback_war=False) # finally, we can write the transcript out to the file try: @@ -3739,7 +3740,7 @@ class Cmd(cmd.Cmd): test_results = runner.run(testcase) if test_results.wasSuccessful(): self.decolorized_write(sys.stderr, stream.read()) - self.poutput('Tests passed', color=constants.SUCCESS_COLOR) + self.poutput('Tests passed', color=Fore.LIGHTGREEN_EX) else: # Strip off the initial traceback which isn't particularly useful for end users error_str = stream.read() |