diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-13 14:06:57 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-13 14:06:57 -0400 |
commit | f659da34769b1721de7888cc2f1b5473eb88df94 (patch) | |
tree | 07d311c6913491624cc8cfc29b1a556d0812fe58 | |
parent | 8e90658aac568ca5948d99a3103a5c8ae08f71a5 (diff) | |
download | cmd2-git-f659da34769b1721de7888cc2f1b5473eb88df94.tar.gz |
Reverted making constant values for colors. This will be done on a future ticket.
-rw-r--r-- | cmd2/argparse_completer.py | 4 | ||||
-rw-r--r-- | cmd2/cmd2.py | 17 | ||||
-rw-r--r-- | cmd2/constants.py | 6 |
3 files changed, 11 insertions, 16 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index 60583ae2..6b3f5298 100644 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -66,7 +66,7 @@ import sys from argparse import ZERO_OR_MORE, ONE_OR_MORE, ArgumentError, _, _get_action_name, SUPPRESS from typing import List, Dict, Tuple, Callable, Union -from . import constants +from colorama import Fore from .rl_utils import rl_force_redisplay from .utils import ansi_safe_wcswidth @@ -996,7 +996,7 @@ class ACArgumentParser(argparse.ArgumentParser): linum += 1 self.print_usage(sys.stderr) - self.exit(2, constants.ERROR_COLOR + '{}\n\n'.format(formatted_message) + constants.RESET_COLOR) + self.exit(2, Fore.LIGHTRED_EX + '{}\n\n'.format(formatted_message) + Fore.RESET) def format_help(self) -> str: """Copy of format_help() from argparse.ArgumentParser with tweaks to separately display required parameters""" 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() diff --git a/cmd2/constants.py b/cmd2/constants.py index e9dc52a9..267028d3 100644 --- a/cmd2/constants.py +++ b/cmd2/constants.py @@ -25,9 +25,3 @@ LINE_FEED = '\n' COLORS_NEVER = 'Never' COLORS_TERMINAL = 'Terminal' COLORS_ALWAYS = 'Always' - -# Text colors -SUCCESS_COLOR = Fore.LIGHTGREEN_EX -WARNING_COLOR = Fore.LIGHTYELLOW_EX -ERROR_COLOR = Fore.LIGHTRED_EX -RESET_COLOR = Fore.RESET |