Skip to content

Strip

A Strip contains the result of rendering a widget. See line API for how to use Strips.

Strip class

def __init__(self, segments, cell_length=None):

Represents a 'strip' (horizontal line) of a Textual Widget.

A Strip is like an immutable list of Segments. The immutability allows for effective caching.

Parameters
Parameter Default Description
segments
Iterable[Segment]
required

An iterable of segments.

cell_length
int | None
None

The cell length if known, or None to calculate on demand.

cell_length property

cell_length: int

Get the number of cells required to render this object.

link_ids: set[str]

A set of the link ids in this Strip.

text property

text: str

Segment text.

adjust_cell_length method

def adjust_cell_length(self, cell_length, style=None):

Adjust the cell length, possibly truncating or extending.

Parameters
Parameter Default Description
cell_length
int
required

New desired cell length.

style
Style | None
None

Style when extending, or None.

Returns
Type Description
Strip

A new strip with the supplied cell length.

apply_filter method

def apply_filter(self, filter, background):

Apply a filter to all segments in the strip.

Parameters
Parameter Default Description
filter
LineFilter
required

A line filter object.

Returns
Type Description
Strip

A new Strip.

apply_style method

def apply_style(self, style):

Apply a style to the Strip.

Parameters
Parameter Default Description
style
Style
required

A Rich style.

Returns
Type Description
Strip

A new strip.

blank classmethod

def blank(cls, cell_length, style=None):

Create a blank strip.

Parameters
Parameter Default Description
cell_length
int
required

Desired cell length.

style
StyleType | None
None

Style of blank.

Returns
Type Description
Strip

New strip.

crop method

def crop(self, start, end=None):

Crop a strip between two cell positions.

Parameters
Parameter Default Description
start
int
required

The start cell position (inclusive).

end
int | None
None

The end cell position (exclusive).

Returns
Type Description
Strip

A new Strip.

crop_extend method

def crop_extend(self, start, end, style):

Crop between two points, extending the length if required.

Parameters
Parameter Default Description
start
int
required

Start offset of crop.

end
int
required

End offset of crop.

style
Style | None
required

Style of additional padding.

Returns
Type Description
Strip

New cropped Strip.

divide method

def divide(self, cuts):

Divide the strip in to multiple smaller strips by cutting at given (cell) indices.

Parameters
Parameter Default Description
cuts
Iterable[int]
required

An iterable of cell positions as ints.

Returns
Type Description
Sequence[Strip]

A new list of strips.

extend_cell_length method

def extend_cell_length(self, cell_length, style=None):

Extend the cell length if it is less than the given value.

Parameters
Parameter Default Description
cell_length
int
required

Required minimum cell length.

style
Style | None
None

Style for padding if the cell length is extended.

Returns
Type Description
Strip

A new Strip.

from_lines classmethod

def from_lines(cls, lines, cell_length=None):

Convert lines (lists of segments) to a list of Strips.

Parameters
Parameter Default Description
lines
list[list[Segment]]
required

List of lines, where a line is a list of segments.

cell_length
int | None
None

Cell length of lines (must be same) or None if not known.

Returns
Type Description
list[Strip]

List of strips.

index_to_cell_position method

def index_to_cell_position(self, index):

Given a character index, return the cell position of that character. This is the sum of the cell lengths of all the characters before the character at index.

Parameters
Parameter Default Description
index
int
required

The index to convert.

Returns
Type Description
int

The cell position of the character at index.

join classmethod

def join(cls, strips):

Join a number of strips in to one.

Parameters
Parameter Default Description
strips
Iterable[Strip | None]
required

An iterable of Strips.

Returns
Type Description
Strip

A new combined strip.

simplify method

def simplify(self):

Simplify the segments (join segments with same style)

Returns
Type Description
Strip

New strip.

def style_links(self, link_id, link_style):

Apply a style to Segments with the given link_id.

Parameters
Parameter Default Description
link_id
str
required

A link id.

link_style
Style
required

Style to apply.

Returns
Type Description
Strip

New strip (or same Strip if no changes).

StripRenderable class

def __init__(self, strips, width=None):

A renderable which renders a list of strips in to lines.

get_line_length function

def get_line_length(segments):

Get the line length (total length of all segments).

Parameters
Parameter Default Description
segments
Iterable[Segment]
required

Iterable of segments.

Returns
Type Description
int

Length of line in cells.