Skip to content

ButtonStyle

ButtonStyle defines the visual appearance of buttons: text color, selection highlight, padding, and prefix/suffix decorators.

Pass a style to Component as global_buttons_style, or to an individual Button as local_button_style.


Class reference

ButtonStyle

Visual style definition for buttons.

Parameters:

Name Type Description Default
text_color str

ANSI escape code for the label text color (works with colorama functions).

required
highlight_color str

ANSI escape code applied to the selected button background (works with colorama functions).

required
spaces_count int

Padding spaces around each label (minimum 2).

required
left_decorator str

String prepended to the button label.

required
right_decorator str

String appended to the button label.

required

text_color property

text_color: str

ANSI escape code for the label text color.

highlight_color property

highlight_color: str

ANSI escape code applied to the selected button background.

spaces_count property

spaces_count: int

Padding spaces around each button label (minimum 2).

left_decorator property

left_decorator: str

String prepended to the button label.

right_decorator property

right_decorator: str

String appended to the button label.


How a button is rendered

{index}  {left_decorator}{spaces}{label}{spaces}{right_decorator}

When the button is selected, text_color and highlight_color are prepended and a reset sequence is appended.

Example with CORPORATE_STYLE:

[ Option A ]   <- unselected (blue text, no background)
[ Option B ]   <- selected   (bold white text, blue background)

Using colorama

from colorama import Fore, Back
from interactive_buttons import ButtonStyle

ocean_style = ButtonStyle(
    text_color=Fore.CYAN,
    highlight_color=Back.BLUE,
    spaces_count=4,
    left_decorator="~~",
    right_decorator="~~",
)

Using raw ANSI codes

from interactive_buttons import ButtonStyle

ocean_style = ButtonStyle(
    text_color="\033[36m",     # cyan
    highlight_color="\033[44m",  # blue background
    spaces_count=4,
    left_decorator="~~",
    right_decorator="~~",
)

spaces_count minimum

The constructor enforces a minimum value of 2 for spaces_count. Values below 2 are silently raised to 2.


Pre-built presets

Rather than building a ButtonStyle from scratch, you can use one of the 12 built-in presets.

from interactive_buttons import ButtonStyle, SUNSET_STYLE

style = ButtonStyle(**SUNSET_STYLE)