Skip to content

Filter

NO_DIM module-attribute

NO_DIM = Style(dim=False)

A Style to set dim to False.

ANSIToTruecolor class

def __init__(self, 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 method

def apply(self, segments, background):

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

def truecolor_style(self, 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 class

def __init__(self, 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 method

def apply(self, segments, background):

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 class

Bases: ABC

Base class for a line filter.

apply abstractmethod

def apply(self, segments, background):

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 class

Bases: LineFilter

Convert all colors to monochrome.

apply method

def apply(self, segments, background):

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

def dim_color(background, color, factor):

Dim a color by blending towards the background

Parameters
Name Type Description Default
background RichColor

background color.

required
color RichColor

Foreground color.

required
factor float

Blend factor

required
Returns
Type Description
RichColor

New dimmer color.

dim_style cached

def 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

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