Skip to content

Strip

strip

Strip

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:

Name Type Description Default
segments Iterable[Segment]

An iterable of segments.

required
cell_length int | None

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

None

cell_length: int property

Get the number of cells required to render this object.

A set of the link ids in this Strip.

text: str property

Segment text.

adjust_cell_length(cell_length, style=None)

Adjust the cell length, possibly truncating or extending.

Parameters:

Name Type Description Default
cell_length int

New desired cell length.

required
style Style | None

Style when extending, or None. Defaults to None.

None

Returns:

Type Description
Strip

A new strip with the supplied cell length.

apply_filter(filter)

Apply a filter to all segments in the strip.

Parameters:

Name Type Description Default
filter LineFilter

A line filter object.

required

Returns:

Type Description
Strip

A new Strip.

apply_style(style)

Apply a style to the Strip.

Parameters:

Name Type Description Default
style Style

A Rich style.

required

Returns:

Type Description
Strip

A new strip.

blank(cell_length, style=None) classmethod

Create a blank strip.

Parameters:

Name Type Description Default
cell_length int

Desired cell length.

required
style StyleType | None

Style of blank.

None

Returns:

Type Description
Strip

New strip.

crop(start, end)

Crop a strip between two cell positions.

Parameters:

Name Type Description Default
start int

The start cell position (inclusive).

required
end int

The end cell position (exclusive).

required

Returns:

Type Description
Strip

A new Strip.

divide(cuts)

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

Parameters:

Name Type Description Default
cuts Iterable[int]

An iterable of cell positions as ints.

required

Returns:

Type Description
list[Strip]

A new list of strips.

extend_cell_length(cell_length, style=None)

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

Parameters:

Name Type Description Default
cell_length int

Required minimum cell length.

required
style Style | None

Style for padding if the cell length is extended.

None

Returns:

Type Description
Strip

A new Strip.

from_lines(lines, cell_length=None) classmethod

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

Parameters:

Name Type Description Default
lines list[list[Segment]]

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

required
cell_length int | None

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

None

Returns:

Type Description
list[Strip]

List of strips.

index_to_cell_position(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:

Name Type Description Default
index int

The index to convert.

required

Returns:

Type Description
int

The cell position of the character at index.

join(strips) classmethod

Join a number of strips in to one.

Parameters:

Name Type Description Default
strips Iterable[Strip | None]

An iterable of Strips.

required

Returns:

Type Description
Strip

A new combined strip.

simplify()

Simplify the segments (join segments with same style)

Returns:

Type Description
Strip

New strip.

Apply a style to Segments with the given link_id.

Parameters:

Name Type Description Default
link_id str

A link id.

required
link_style Style

Style to apply.

required

Returns:

Type Description
Strip

New strip (or same Strip if no changes).

get_line_length(segments)

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

Parameters:

Name Type Description Default
segments Iterable[Segment]

Iterable of segments.

required

Returns:

Type Description
int

Length of line in cells.