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

Style(
    background=None,
    foreground=None,
    bold=None,
    dim=None,
    italic=None,
    underline=None,
    reverse=None,
    strike=None,
    link=None,
    _meta=None,
    auto_color=False,
)

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

Just the background color, with no other attributes.

markup_tag cached property

markup_tag

Identifier used to close tags in markup.

meta cached property

meta

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

rich_style cached property

rich_style

Convert this Styles into a Rich style.

Returns:

Type Description
Style

A Rich style object.

style_definition cached property

style_definition

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

without_color cached property

without_color

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

dict[str, str]

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

Style

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 seleciton.

Parameters:

Name Type Description Default

x

int

X coordinate.

required

y

int

Y coordinate.

required

Returns:

Type Description
Style

A Rich Style object.