Skip to content

textual.style

The Style class contains all the information needed to generate styled terminal output.

You won't often need to create Style objects directly, if you are using Content for output. But you might want to use styles for more customized widgets.

Style dataclass

Represents a style in the Visual interface (color and other attributes).

Styles may be added together, which combines their style attributes.

background_style cached property

background_style: Style

Just the background color, with no other attributes.

has_transparent_foreground property

has_transparent_foreground: bool

Is the foreground transparent (or not set)?

hash cached property

hash: int

A hash of the style's attributes.

markup_tag cached property

markup_tag: str

Identifier used to close tags in markup.

meta cached property

meta: Mapping[str, Any]

Get meta information (can not be changed after construction).

rich_style cached property

rich_style: RichStyle

Convert this Styles into a Rich style.

Returns:

Type Description
RichStyle

A Rich style object.

style_definition cached property

style_definition: str

Style encoded in a string (may be parsed from Style.parse).

without_color cached property

without_color: Style

The style without any colors.

combine classmethod

combine(styles)

Add a number of styles and get the result.

from_meta classmethod

from_meta(meta)

Create a Visual Style containing meta information.

Parameters:

Name Type Description Default
meta Mapping[str, Any]

A dictionary of meta information.

required

Returns:

Type Description
Style

A new Style.

from_rich_style classmethod

from_rich_style(rich_style, theme=None)

Build a Style from a (Rich) Style.

Parameters:

Name Type Description Default
rich_style RichStyle

A Rich Style object.

required
theme TerminalTheme | None

Optional Rich [terminal theme][rich.terminal_theme.TerminalTheme].

None

Returns:

Type Description
Style

New Style.

from_styles classmethod

from_styles(styles)

Create a Visual Style from a Textual styles object.

Parameters:

Name Type Description Default
styles StylesBase

A Styles object, such as my_widget.styles.

required

null classmethod

null()

Get a null (no color or style) style.

parse classmethod

parse(text_style, variables=None)

Parse a style from text.

Parameters:

Name Type Description Default
text_style str

A style encoded in a string.

required
variables dict[str, str] | None

Optional mapping of CSS variables. None to get variables from the app.

None

Returns:

Type Description
Style

New style.

rich_style_with_offset

rich_style_with_offset(x, y)

Get a Rich style with the given offset included in meta.

This is used in text selection.

Parameters:

Name Type Description Default
x int

X coordinate.

required
y int

Y coordinate.

required

Returns:

Type Description
RichStyle

A Rich Style object.