Skip to content

Commit cefd93f

Browse files
committed
Renamed ColorName enum to Color.
1 parent 5ce3f0b commit cefd93f

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

cmd2/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
set_default_argument_parser_type,
2121
)
2222
from .cmd2 import Cmd
23-
from .colors import ColorName
23+
from .colors import Color
2424
from .command_definition import (
2525
CommandSet,
2626
with_default_category,
@@ -68,8 +68,8 @@
6868
'CommandResult',
6969
'CommandSet',
7070
'Statement',
71-
# Color
72-
"ColorName",
71+
# Colors
72+
"Color",
7373
# Decorators
7474
'with_argument_list',
7575
'with_argparser',

cmd2/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from backports.strenum import StrEnum
99

1010

11-
class ColorName(StrEnum):
11+
class Color(StrEnum):
1212
"""An enumeration of all color names supported by the Rich library.
1313
1414
Using this enum allows for autocompletion and prevents typos when

cmd2/styles.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
else:
1818
from backports.strenum import StrEnum
1919

20-
from .colors import ColorName
20+
from .colors import Color
2121

2222

2323
class Cmd2Style(StrEnum):
@@ -41,11 +41,11 @@ class Cmd2Style(StrEnum):
4141

4242
# Default styles used by cmd2. Tightly coupled with the Cmd2Style enum.
4343
DEFAULT_CMD2_STYLES: dict[str, StyleType] = {
44-
Cmd2Style.ERROR: Style(color=ColorName.BRIGHT_RED),
45-
Cmd2Style.EXAMPLE: Style(color=ColorName.CYAN, bold=True),
46-
Cmd2Style.HELP_HEADER: Style(color=ColorName.CYAN, bold=True),
47-
Cmd2Style.HELP_TITLE: Style(color=ColorName.BRIGHT_GREEN, bold=True),
48-
Cmd2Style.RULE_LINE: Style(color=ColorName.BRIGHT_GREEN),
49-
Cmd2Style.SUCCESS: Style(color=ColorName.GREEN),
50-
Cmd2Style.WARNING: Style(color=ColorName.BRIGHT_YELLOW),
44+
Cmd2Style.ERROR: Style(color=Color.BRIGHT_RED),
45+
Cmd2Style.EXAMPLE: Style(color=Color.CYAN, bold=True),
46+
Cmd2Style.HELP_HEADER: Style(color=Color.CYAN, bold=True),
47+
Cmd2Style.HELP_TITLE: Style(color=Color.BRIGHT_GREEN, bold=True),
48+
Cmd2Style.RULE_LINE: Style(color=Color.BRIGHT_GREEN),
49+
Cmd2Style.SUCCESS: Style(color=Color.GREEN),
50+
Cmd2Style.WARNING: Style(color=Color.BRIGHT_YELLOW),
5151
}

docs/api/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ incremented according to the [Semantic Version Specification](https://semver.org
3030
- [cmd2.rl_utils](./rl_utils.md) - imports the proper Readline for the platform and provides utility
3131
functions for it
3232
- [cmd2.string_utils](./string_utils.md) - string utility functions
33-
- [cmd2.styles](./styles.md) - custom Rich styles and their corresponding names for cmd2.
33+
- [cmd2.styles](./styles.md) - cmd2-specific Rich styles and a StrEnum of their corresponding names
3434
- [cmd2.terminal_utils](./terminal_utils.md) - support for terminal control escape sequences
3535
- [cmd2.transcript](./transcript.md) - functions and classes for running and validating transcripts
3636
- [cmd2.utils](./utils.md) - various utility classes and functions

tests/test_cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from cmd2 import (
2222
COMMAND_NAME,
2323
Cmd2Style,
24-
ColorName,
24+
Color,
2525
clipboard,
2626
constants,
2727
exceptions,
@@ -1224,7 +1224,7 @@ def test_escaping_prompt() -> None:
12241224
assert rl_escape_prompt(prompt) == prompt
12251225

12261226
# This prompt has color which needs to be escaped
1227-
prompt = stylize('InColor', style=ColorName.CYAN)
1227+
prompt = stylize('InColor', style=Color.CYAN)
12281228

12291229
escape_start = "\x01"
12301230
escape_end = "\x02"

tests/test_string_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from rich.style import Style
44

55
from cmd2 import (
6-
ColorName,
6+
Color,
77
rich_utils,
88
)
99
from cmd2 import (
@@ -59,7 +59,7 @@ def test_align_left_wide_text() -> None:
5959
def test_align_left_with_style() -> None:
6060
character = '-'
6161

62-
styled_text = su.stylize('table', style=ColorName.BRIGHT_BLUE)
62+
styled_text = su.stylize('table', style=Color.BRIGHT_BLUE)
6363
width = 8
6464

6565
aligned = su.align_left(styled_text, width=width, character=character)
@@ -85,7 +85,7 @@ def test_align_center_wide_text() -> None:
8585
def test_align_center_with_style() -> None:
8686
character = '-'
8787

88-
styled_text = su.stylize('table', style=ColorName.BRIGHT_BLUE)
88+
styled_text = su.stylize('table', style=Color.BRIGHT_BLUE)
8989
width = 8
9090

9191
aligned = su.align_center(styled_text, width=width, character=character)
@@ -111,7 +111,7 @@ def test_align_right_wide_text() -> None:
111111
def test_align_right_with_style() -> None:
112112
character = '-'
113113

114-
styled_text = su.stylize('table', style=ColorName.BRIGHT_BLUE)
114+
styled_text = su.stylize('table', style=Color.BRIGHT_BLUE)
115115
width = 8
116116

117117
aligned = su.align_right(styled_text, width=width, character=character)
@@ -122,8 +122,8 @@ def test_stylize() -> None:
122122
styled_str = su.stylize(
123123
HELLO_WORLD,
124124
style=Style(
125-
color=ColorName.GREEN,
126-
bgcolor=ColorName.BLUE,
125+
color=Color.GREEN,
126+
bgcolor=Color.BLUE,
127127
bold=True,
128128
underline=True,
129129
),
@@ -134,15 +134,15 @@ def test_stylize() -> None:
134134

135135
def test_strip_style() -> None:
136136
base_str = HELLO_WORLD
137-
styled_str = su.stylize(base_str, style=ColorName.GREEN)
137+
styled_str = su.stylize(base_str, style=Color.GREEN)
138138
assert base_str != styled_str
139139
assert base_str == su.strip_style(styled_str)
140140

141141

142142
def test_str_width() -> None:
143143
# Include a full-width character
144144
base_str = HELLO_WORLD + "深"
145-
styled_str = su.stylize(base_str, style=ColorName.GREEN)
145+
styled_str = su.stylize(base_str, style=Color.GREEN)
146146
expected_width = len(HELLO_WORLD) + 2
147147
assert su.str_width(base_str) == su.str_width(styled_str) == expected_width
148148

tests/test_terminal_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from cmd2 import (
6-
ColorName,
6+
Color,
77
string_utils,
88
)
99
from cmd2 import (
@@ -24,7 +24,7 @@ def test_set_title() -> None:
2424
'(Cmd) ',
2525
'help his',
2626
12,
27-
string_utils.stylize('Hello World!', style=ColorName.MAGENTA),
27+
string_utils.stylize('Hello World!', style=Color.MAGENTA),
2828
'\x1b[2K\r\x1b[35mHello World!\x1b[0m',
2929
),
3030
(127, '\n(Cmd) ', 'help ', 5, 'foo', '\x1b[2K\x1b[1A\x1b[2K\rfoo'),

0 commit comments

Comments
 (0)