-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathstyles.py
More file actions
51 lines (39 loc) · 1.81 KB
/
styles.py
File metadata and controls
51 lines (39 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Defines custom Rich styles and their corresponding names for cmd2.
This module provides a centralized and discoverable way to manage Rich styles used
within the cmd2 framework. It defines a StrEnum for style names and a dictionary
that maps these names to their default style objects.
"""
import sys
from rich.style import (
Style,
StyleType,
)
if sys.version_info >= (3, 11):
from enum import StrEnum
else:
from backports.strenum import StrEnum
from .colors import Color
class Cmd2Style(StrEnum):
"""An enumeration of the names of custom Rich styles used in cmd2.
Using this enum allows for autocompletion and prevents typos when
referencing cmd2-specific styles.
This StrEnum is tightly coupled with DEFAULT_CMD2_STYLES. Any name
added here must have a corresponding style definition there.
"""
ERROR = "cmd2.error" # Error text (used by perror())
EXAMPLE = "cmd2.example" # Command line examples in help text
HELP_HEADER = "cmd2.help.header" # Help table header text
HELP_LEADER = "cmd2.help.leader" # Text right before the help tables are listed
RULE_LINE = "rule.line" # Rich style for horizontal rules
SUCCESS = "cmd2.success" # Success text (used by psuccess())
WARNING = "cmd2.warning" # Warning text (used by pwarning())
# Default styles used by cmd2. Tightly coupled with the Cmd2Style enum.
DEFAULT_CMD2_STYLES: dict[str, StyleType] = {
Cmd2Style.ERROR: Style(color=Color.BRIGHT_RED),
Cmd2Style.EXAMPLE: Style(color=Color.CYAN, bold=True),
Cmd2Style.HELP_HEADER: Style(color=Color.BRIGHT_GREEN, bold=True),
Cmd2Style.HELP_LEADER: Style(color=Color.CYAN, bold=True),
Cmd2Style.RULE_LINE: Style(color=Color.BRIGHT_GREEN),
Cmd2Style.SUCCESS: Style(color=Color.GREEN),
Cmd2Style.WARNING: Style(color=Color.BRIGHT_YELLOW),
}