Skip to content

cmd2.styles

cmd2.styles

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.

Notes

Cmd2 uses Rich for its terminal output, and while this module defines a set of cmd2-specific styles, it's important to understand that these aren't the only styles that can appear. Components like Rich tracebacks and the rich-argparse library, which cmd2 uses for its help output, also apply their own built-in styles. Additionally, app developers may use other Rich objects that have their own default styles.

For a complete theming experience, you can create a custom theme that includes styles from Rich and rich-argparse. The cmd2.theme.update_theme() function automatically updates rich-argparse's styles with any custom styles provided in your theme dictionary, so you don't have to modify them directly.

You can find Rich's default styles in the rich.default_styles module. For rich-argparse, the style names are defined in the rich_argparse.RichHelpFormatter.styles dictionary.

For prompt-toolkit default styles, see: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/main/src/prompt_toolkit/styles/defaults.py

DEFAULT_CMD2_STYLES module-attribute

DEFAULT_CMD2_STYLES = {
    COMMAND_LINE: Style(color=CYAN, bold=True),
    COMPLETION_MENU: Style(
        color="#000000", bgcolor="#bbbbbb"
    ),
    COMPLETION_MENU_COMPLETION: Style(),
    COMPLETION_MENU_CURRENT: Style(
        color=GREEN, bgcolor=BLACK
    ),
    COMPLETION_MENU_META: Style(
        color="#000000", bgcolor="#bbbbbb"
    ),
    COMPLETION_MENU_META_CURRENT: Style(
        color=BLACK, bgcolor=BRIGHT_GREEN
    ),
    ERROR: Style(color=BRIGHT_RED),
    HELP_HEADER: Style(color=BRIGHT_GREEN),
    HELP_LEADER: Style(color=CYAN),
    LEXER_COMMAND: Style(color=GREEN),
    LEXER_ALIAS: Style(color=CYAN),
    LEXER_MACRO: Style(color=MAGENTA),
    LEXER_FLAG: Style(color=RED),
    LEXER_ARGUMENT: Style(color=YELLOW),
    SUCCESS: Style(color=GREEN),
    TABLE_BORDER: Style(color=BRIGHT_GREEN),
    WARNING: Style(color=BRIGHT_YELLOW),
}

DEFAULT_ARGPARSE_STYLES module-attribute

DEFAULT_ARGPARSE_STYLES = copy()

Cmd2Style

Bases: 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.

COMMAND_LINE class-attribute instance-attribute

COMMAND_LINE = 'cmd2.example'

COMPLETION_MENU class-attribute instance-attribute

COMPLETION_MENU = 'cmd2.completion-menu'

COMPLETION_MENU_COMPLETION class-attribute instance-attribute

COMPLETION_MENU_COMPLETION = (
    "cmd2.completion-menu.completion"
)

COMPLETION_MENU_CURRENT class-attribute instance-attribute

COMPLETION_MENU_CURRENT = (
    "cmd2.completion-menu.completion.current"
)

COMPLETION_MENU_META class-attribute instance-attribute

COMPLETION_MENU_META = (
    "cmd2.completion-menu.meta.completion"
)

COMPLETION_MENU_META_CURRENT class-attribute instance-attribute

COMPLETION_MENU_META_CURRENT = (
    "cmd2.completion-menu.meta.completion.current"
)

ERROR class-attribute instance-attribute

ERROR = 'cmd2.error'

HELP_HEADER class-attribute instance-attribute

HELP_HEADER = 'cmd2.help.header'

HELP_LEADER class-attribute instance-attribute

HELP_LEADER = 'cmd2.help.leader'

LEXER_COMMAND class-attribute instance-attribute

LEXER_COMMAND = 'cmd2.lexer.command'

LEXER_ALIAS class-attribute instance-attribute

LEXER_ALIAS = 'cmd2.lexer.alias'

LEXER_MACRO class-attribute instance-attribute

LEXER_MACRO = 'cmd2.lexer.macro'

LEXER_FLAG class-attribute instance-attribute

LEXER_FLAG = 'cmd2.lexer.flag'

LEXER_ARGUMENT class-attribute instance-attribute

LEXER_ARGUMENT = 'cmd2.lexer.argument'

SUCCESS class-attribute instance-attribute

SUCCESS = 'cmd2.success'

TABLE_BORDER class-attribute instance-attribute

TABLE_BORDER = 'cmd2.table_border'

WARNING class-attribute instance-attribute

WARNING = 'cmd2.warning'