diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-26 00:07:52 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-26 00:07:52 -0400 |
commit | 61698b2fc28daad462da9e459318e3208e0d7920 (patch) | |
tree | fbed2371272ea5246931b8ed53ea1860f0529b8d | |
parent | f08b0ce5a4ae5fec19ecd9d66416c32fe89a3a4e (diff) | |
download | cmd2-git-61698b2fc28daad462da9e459318e3208e0d7920.tar.gz |
Renamed style_message to style
-rw-r--r-- | cmd2/cmd2.py | 16 | ||||
-rw-r--r-- | cmd2/utils.py | 10 | ||||
-rwxr-xr-x | examples/pirate.py | 2 | ||||
-rw-r--r-- | tests/test_cmd2.py | 4 | ||||
-rw-r--r-- | tests/test_utils.py | 10 |
5 files changed, 21 insertions, 21 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 6b2cfcc2..69b55d80 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -617,7 +617,7 @@ class Cmd(cmd.Cmd): the message text already has the desired style. Defaults to True. """ if add_color: - final_msg = utils.style_message(msg, fg='lightred') + final_msg = utils.style(msg, fg='lightred') else: final_msg = "{}".format(msg) self._decolorized_write(sys.stderr, final_msg + end) @@ -640,11 +640,11 @@ class Cmd(cmd.Cmd): final_msg = "{}".format(msg) if add_color: - final_msg = utils.style_message(final_msg, fg='lightred') + final_msg = utils.style(final_msg, fg='lightred') if not self.debug: warning = "\nTo enable full traceback, run the following command: 'set debug true'" - final_msg += utils.style_message(warning, fg="lightyellow") + final_msg += utils.style(warning, fg="lightyellow") # Set add_color to False since style has already been applied self.perror(final_msg, end=end, add_color=False) @@ -3247,7 +3247,7 @@ class Cmd(cmd.Cmd): if args.__statement__.command == "pyscript": warning = ("pyscript has been renamed and will be removed in the next release, " "please use run_pyscript instead\n") - self.perror(utils.style_message(warning, fg="lightyellow")) + self.perror(utils.style(warning, fg="lightyellow")) return py_return @@ -3556,7 +3556,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(utils.style_message(warning, fg="lightyellow")) + self.perror(utils.style(warning, fg="lightyellow")) # finally, we can write the transcript out to the file try: @@ -3676,7 +3676,7 @@ class Cmd(cmd.Cmd): if args.__statement__.command == "load": warning = ("load has been renamed and will be removed in the next release, " "please use run_script instead\n") - self.perror(utils.style_message(warning, fg="lightyellow")) + self.perror(utils.style(warning, fg="lightyellow")) # load has been deprecated do_load = do_run_script @@ -3703,7 +3703,7 @@ class Cmd(cmd.Cmd): if args.__statement__.command == "_relative_load": warning = ("_relative_load has been renamed and will be removed in the next release, " "please use _relative_run_script instead\n") - self.perror(utils.style_message(warning, fg="lightyellow")) + self.perror(utils.style(warning, fg="lightyellow")) file_path = args.file_path # NOTE: Relative path is an absolute path, it is just relative to the current script directory @@ -3758,7 +3758,7 @@ class Cmd(cmd.Cmd): if test_results.wasSuccessful(): self._decolorized_write(sys.stderr, stream.read()) finish_msg = '{0} transcript{1} passed in {2:.3f} seconds'.format(num_transcripts, plural, execution_time) - finish_msg = utils.style_message(utils.center_text(finish_msg, pad='='), fg="green") + finish_msg = utils.style(utils.center_text(finish_msg, pad='='), fg="green") self.poutput(Style.BRIGHT + finish_msg + Style.NORMAL) else: # Strip off the initial traceback which isn't particularly useful for end users diff --git a/cmd2/utils.py b/cmd2/utils.py index 8252546c..92261c62 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -36,17 +36,17 @@ def ansi_safe_wcswidth(text: str) -> int: return wcswidth(strip_ansi(text)) -def style_message(msg: Any, *, fg: str = '', bg: str = '') -> str: +def style(text: Any, *, fg: str = '', bg: str = '') -> str: """ - Styles a message + Applies style to text - :param msg: Any object compatible with str.format() + :param text: Any object compatible with str.format() :param fg: (optional) Foreground color. Accepts color names like 'red' or 'blue' :param bg: (optional) Background color. Accepts color names like 'red' or 'blue' """ values = [] - msg = "{}".format(msg) + text = "{}".format(text) if fg: try: values.append(constants.FG_COLORS[fg.lower()]) @@ -57,7 +57,7 @@ def style_message(msg: Any, *, fg: str = '', bg: str = '') -> str: values.append(constants.BG_COLORS[bg.lower()]) except KeyError: raise ValueError('Color {} does not exist.'.format(bg)) - values.append(msg) + values.append(text) if fg: values.append(constants.FG_COLORS['reset']) if bg: diff --git a/examples/pirate.py b/examples/pirate.py index 6802edb6..41d7d3f4 100755 --- a/examples/pirate.py +++ b/examples/pirate.py @@ -70,7 +70,7 @@ class Pirate(cmd2.Cmd): def do_sing(self, arg): """Sing a colorful song.""" - self.poutput(utils.style_message(arg, fg=self.songcolor)) + self.poutput(utils.style(arg, fg=self.songcolor)) yo_parser = argparse.ArgumentParser() yo_parser.add_argument('--ho', type=int, default=2, help="How often to chant 'ho'") diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 2c6a4eb0..5ff8513f 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -1460,7 +1460,7 @@ def test_poutput_none(outsim_app): def test_poutput_color_always(outsim_app): msg = 'Hello World' outsim_app.colors = 'Always' - outsim_app.poutput(utils.style_message(msg, fg='cyan')) + outsim_app.poutput(utils.style(msg, fg='cyan')) out = outsim_app.stdout.getvalue() expected = Fore.CYAN + msg + Fore.RESET + '\n' assert out == expected @@ -1468,7 +1468,7 @@ def test_poutput_color_always(outsim_app): def test_poutput_color_never(outsim_app): msg = 'Hello World' outsim_app.colors = 'Never' - outsim_app.poutput(utils.style_message(msg, fg='cyan')) + outsim_app.poutput(utils.style(msg, fg='cyan')) out = outsim_app.stdout.getvalue() expected = msg + '\n' assert out == expected diff --git a/tests/test_utils.py b/tests/test_utils.py index ada8bc86..e1f34b8a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -25,21 +25,21 @@ def test_ansi_safe_wcswidth(): ansi_str = Fore.GREEN + base_str + Fore.RESET assert cu.ansi_safe_wcswidth(ansi_str) != len(ansi_str) -def test_style_message(): +def test_style(): base_str = HELLO_WORLD ansi_str = Fore.BLUE + Back.GREEN + base_str + Fore.RESET + Back.RESET - assert cu.style_message(base_str, fg='blue', bg='green') == ansi_str + assert cu.style(base_str, fg='blue', bg='green') == ansi_str -def test_style_message_color_not_exist(): +def test_style_color_not_exist(): base_str = HELLO_WORLD try: - cu.style_message(base_str, fg='hello', bg='green') + cu.style(base_str, fg='hello', bg='green') assert False except ValueError: assert True try: - cu.style_message(base_str, fg='blue', bg='hello') + cu.style(base_str, fg='blue', bg='hello') assert False except ValueError: assert True |