Skip to content

Styles

Merging

Styles are merged using the | operator: left | right. The result contains left's values as the baseline, with right's non-default values taking precedence.

This means style merging is additive only: a field that equals its default is treated as "not set" and does not override left. For example, CellStyle(bold=True) | CellStyle(bold=False) produces CellStyle(bold=True) because bold=False is the default and is therefore not considered an explicit override.

This design keeps style composition predictable — utility constants like text_bold can be freely layered without accidentally clearing each other — but it means you cannot use a default value to explicitly clear a previously-set property. Structure your components to avoid needing to reset style properties back to their defaults.

API

counterweight.styles.Style dataclass

Style(
    *,
    layout: Style = Style(),
    z: int = 0,
    margin_color: Color = _BLACK,
    padding_color: Color = _BLACK,
    content_color: Color = _BLACK,
    border_kind: BorderKind | None = None,
    border_style: CellStyle = _DEFAULT_CELL_STYLE,
    border_contract: int = 0,
    text_style: CellStyle = _DEFAULT_CELL_STYLE,
    text_justify: Literal[
        "left", "center", "right"
    ] = "left",
    text_wrap: TextWrap = "none"
)

layout class-attribute instance-attribute

layout: Style = field(
    default_factory=Style, compare=False, hash=False
)

z class-attribute instance-attribute

z: int = 0

margin_color class-attribute instance-attribute

margin_color: Color = _BLACK

padding_color class-attribute instance-attribute

padding_color: Color = _BLACK

content_color class-attribute instance-attribute

content_color: Color = _BLACK

border_kind class-attribute instance-attribute

border_kind: BorderKind | None = None

border_style class-attribute instance-attribute

border_style: CellStyle = _DEFAULT_CELL_STYLE

border_contract class-attribute instance-attribute

border_contract: int = 0

text_style class-attribute instance-attribute

text_style: CellStyle = _DEFAULT_CELL_STYLE

text_justify class-attribute instance-attribute

text_justify: Literal['left', 'center', 'right'] = 'left'

text_wrap class-attribute instance-attribute

text_wrap: TextWrap = 'none'

__or__

__or__(other: SS | None) -> SS

counterweight.styles.Color

red instance-attribute

red: int

green instance-attribute

green: int

blue instance-attribute

blue: int

hex property

hex: str

from_name classmethod

from_name(name: str) -> Color

from_hex cached classmethod

from_hex(hex: str) -> Color

blend

blend(other: Color, alpha: float) -> Color

counterweight.styles.CellStyle dataclass

CellStyle(
    *,
    foreground: Color = _WHITE,
    background: Color = _BLACK,
    bold: bool = False,
    dim: bool = False,
    italic: bool = False,
    underline: bool = False,
    strikethrough: bool = False
)

foreground class-attribute instance-attribute

foreground: Color = _WHITE

background class-attribute instance-attribute

background: Color = _BLACK

bold class-attribute instance-attribute

bold: bool = False

dim class-attribute instance-attribute

dim: bool = False

italic class-attribute instance-attribute

italic: bool = False

underline class-attribute instance-attribute

underline: bool = False

strikethrough class-attribute instance-attribute

strikethrough: bool = False

__post_init__

__post_init__() -> None

__hash__

__hash__() -> int