Skip to content

Commit f659da3

Browse files
committed
Reverted making constant values for colors. This will be done on a future ticket.
1 parent 8e90658 commit f659da3

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

cmd2/argparse_completer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def my_completer(text: str, line: str, begidx: int, endidx:int, extra_param: str
6666
from argparse import ZERO_OR_MORE, ONE_OR_MORE, ArgumentError, _, _get_action_name, SUPPRESS
6767
from typing import List, Dict, Tuple, Callable, Union
6868

69-
from . import constants
69+
from colorama import Fore
7070

7171
from .rl_utils import rl_force_redisplay
7272
from .utils import ansi_safe_wcswidth
@@ -996,7 +996,7 @@ def error(self, message: str) -> None:
996996
linum += 1
997997

998998
self.print_usage(sys.stderr)
999-
self.exit(2, constants.ERROR_COLOR + '{}\n\n'.format(formatted_message) + constants.RESET_COLOR)
999+
self.exit(2, Fore.LIGHTRED_EX + '{}\n\n'.format(formatted_message) + Fore.RESET)
10001000

10011001
def format_help(self) -> str:
10021002
"""Copy of format_help() from argparse.ArgumentParser with tweaks to separately display required parameters"""

cmd2/cmd2.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Type, Union, IO
4343

4444
import colorama
45+
from colorama import Fore
4546

4647
from . import constants
4748
from . import plugin
@@ -58,7 +59,7 @@
5859
rl_warning = "Readline features including tab completion have been disabled since no \n" \
5960
"supported version of readline was found. To resolve this, install \n" \
6061
"pyreadline on Windows or gnureadline on Mac.\n\n"
61-
sys.stderr.write(constants.WARNING_COLOR + rl_warning + constants.RESET_COLOR)
62+
sys.stderr.write(Fore.LIGHTYELLOW_EX + rl_warning + Fore.RESET)
6263
else:
6364
from .rl_utils import rl_force_redisplay, readline
6465

@@ -615,7 +616,7 @@ def poutput(self, msg: Any, end: str = '\n', color: str = '') -> None:
615616
if not msg_str.endswith(end):
616617
msg_str += end
617618
if color:
618-
msg_str = color + msg_str + constants.RESET_COLOR
619+
msg_str = color + msg_str + Fore.RESET
619620
self.decolorized_write(self.stdout, msg_str)
620621
except BrokenPipeError:
621622
# This occurs if a command's output is being piped to another
@@ -626,8 +627,8 @@ def poutput(self, msg: Any, end: str = '\n', color: str = '') -> None:
626627
if self.broken_pipe_warning:
627628
sys.stderr.write(self.broken_pipe_warning)
628629

629-
def perror(self, err: Union[str, Exception], traceback_war: bool = True, err_color: str = constants.ERROR_COLOR,
630-
war_color: str = constants.WARNING_COLOR) -> None:
630+
def perror(self, err: Union[str, Exception], traceback_war: bool = True, err_color: str = Fore.LIGHTRED_EX,
631+
war_color: str = Fore.LIGHTYELLOW_EX) -> None:
631632
""" Print error message to sys.stderr and if debug is true, print an exception Traceback if one exists.
632633
633634
:param err: an Exception or error message to print out
@@ -643,12 +644,12 @@ def perror(self, err: Union[str, Exception], traceback_war: bool = True, err_col
643644
err_msg = "EXCEPTION of type '{}' occurred with message: '{}'\n".format(type(err).__name__, err)
644645
else:
645646
err_msg = "{}\n".format(err)
646-
err_msg = err_color + err_msg + constants.RESET_COLOR
647+
err_msg = err_color + err_msg + Fore.RESET
647648
self.decolorized_write(sys.stderr, err_msg)
648649

649650
if traceback_war and not self.debug:
650651
war = "To enable full traceback, run the following command: 'set debug true'\n"
651-
war = war_color + war + constants.RESET_COLOR
652+
war = war_color + war + Fore.RESET
652653
self.decolorized_write(sys.stderr, war)
653654

654655
def pfeedback(self, msg: str) -> None:
@@ -3574,7 +3575,7 @@ def _generate_transcript(self, history: List[Union[HistoryItem, str]], transcrip
35743575
# Check if all commands ran
35753576
if commands_run < len(history):
35763577
warning = "Command {} triggered a stop and ended transcript generation early".format(commands_run)
3577-
self.perror(warning, err_color=constants.WARNING_COLOR, traceback_war=False)
3578+
self.perror(warning, err_color=Fore.LIGHTYELLOW_EX, traceback_war=False)
35783579

35793580
# finally, we can write the transcript out to the file
35803581
try:
@@ -3739,7 +3740,7 @@ class TestMyAppCase(Cmd2TestCase):
37393740
test_results = runner.run(testcase)
37403741
if test_results.wasSuccessful():
37413742
self.decolorized_write(sys.stderr, stream.read())
3742-
self.poutput('Tests passed', color=constants.SUCCESS_COLOR)
3743+
self.poutput('Tests passed', color=Fore.LIGHTGREEN_EX)
37433744
else:
37443745
# Strip off the initial traceback which isn't particularly useful for end users
37453746
error_str = stream.read()

cmd2/constants.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,3 @@
2525
COLORS_NEVER = 'Never'
2626
COLORS_TERMINAL = 'Terminal'
2727
COLORS_ALWAYS = 'Always'
28-
29-
# Text colors
30-
SUCCESS_COLOR = Fore.LIGHTGREEN_EX
31-
WARNING_COLOR = Fore.LIGHTYELLOW_EX
32-
ERROR_COLOR = Fore.LIGHTRED_EX
33-
RESET_COLOR = Fore.RESET

0 commit comments

Comments
 (0)