Skip to content

textual.filter

Filter classes.

Note

Filters are used internally, and not recommended for use by Textual app developers.

Filters are used internally to process terminal output after it has been rendered. Currently this is used internally to convert the application to monochrome, when the NO_COLOR env var is set.

In the future, this system will be used to implement accessibility features.

NO_DIM module-attribute

NO_DIM = Style(dim=False)

A Style to set dim to False.

ANSIToTruecolor

ANSIToTruecolor(terminal_theme)

Bases: LineFilter

Convert ANSI colors to their truecolor equivalents.

Parameters:

Name Type Description Default

terminal_theme

TerminalTheme

A rich terminal theme.

required

apply

Transform a list of segments.

Parameters:

Name Type Description Default

segments

list[Segment]

A list of segments.

required

background

Color

The background color.

required

Returns:

Type Description
list[Segment]

A new list of segments.

truecolor_style cached

truecolor_style(style)

Replace system colors with truecolor equivalent.

Parameters:

Name Type Description Default

style

Style

Style to apply truecolor filter to.

required

Returns:

Type Description
Style

New style.

DimFilter

DimFilter(dim_factor=0.5)

Bases: LineFilter

Replace dim attributes with modified colors.

Parameters:

Name Type Description Default

dim_factor

float

The factor to dim by; 0 is 100% background (i.e. invisible), 1.0 is no change.

0.5

apply

Transform a list of segments.

Parameters:

Name Type Description Default

segments

list[Segment]

A list of segments.

required

background

Color

The background color.

required

Returns:

Type Description
list[Segment]

A new list of segments.

LineFilter

Bases: ABC

Base class for a line filter.

apply abstractmethod

Transform a list of segments.

Parameters:

Name Type Description Default

segments

list[Segment]

A list of segments.

required

background

Color

The background color.

required

Returns:

Type Description
list[Segment]

A new list of segments.

Monochrome

Bases: LineFilter

Convert all colors to monochrome.

apply

Transform a list of segments.

Parameters:

Name Type Description Default

segments

list[Segment]

A list of segments.

required

background

Color

The background color.

required

Returns:

Type Description
list[Segment]

A new list of segments.

dim_color cached

dim_color(background, color, factor)

Dim a color by blending towards the background

Parameters:

Name Type Description Default

background

Color

background color.

required

color

Color

Foreground color.

required

factor

float

Blend factor

required

Returns:

Type Description
Color

New dimmer color.

dim_style cached

dim_style(style, background, factor)

Replace dim attribute with a dim color.

Parameters:

Name Type Description Default

style

Style

Style to dim.

required

factor

float

Blend factor.

required

Returns:

Type Description
Style

New dimmed style.

monochrome_style cached

monochrome_style(style)

Convert colors in a style to monochrome.

Parameters:

Name Type Description Default

style

Style

A Rich Style.

required

Returns:

Type Description
Style

A new Rich style.