rich.segment¶
- class rich.segment.ControlType(value)[source]¶
Non-printable control codes which typically translate to ANSI codes.
- class rich.segment.Segment(text, style=None, control=None)[source]¶
A piece of text with associated style. Segments are produced by the Console render process and are ultimately converted in to strings to be written to the terminal.
- Parameters
- classmethod adjust_line_length(line, length, style=None, pad=True)[source]¶
Adjust a line to a given width (cropping or padding as required).
- Parameters
segments (Iterable[Segment]) – A list of segments in a single line.
length (int) – The desired width of the line.
style (Style, optional) – The style of padding if used (space on the end). Defaults to None.
pad (bool, optional) – Pad lines with spaces if they are shorter than length. Defaults to True.
- Returns
A line of segments with the desired length.
- Return type
List[Segment]
- classmethod align_bottom(lines, width, height, style, new_lines=False)[source]¶
Aligns render to bottom (adds extra lines above as required).
- Args:
lines (List[List[Segment]]): A list of lines. width (int): Desired width. height (int, optional): Desired height or None for no change. style (Style): Style of any padding added. Defaults to None. new_lines (bool, optional): Padded lines should include “
“. Defaults to False.
- Returns:
List[List[Segment]]: New list of lines.
- classmethod align_middle(lines, width, height, style, new_lines=False)[source]¶
Aligns lines to middle (adds extra lines to above and below as required).
- Args:
lines (List[List[Segment]]): A list of lines. width (int): Desired width. height (int, optional): Desired height or None for no change. style (Style): Style of any padding added. new_lines (bool, optional): Padded lines should include “
“. Defaults to False.
- Returns:
List[List[Segment]]: New list of lines.
- classmethod align_top(lines, width, height, style, new_lines=False)[source]¶
Aligns lines to top (adds extra lines to bottom as required).
- Args:
lines (List[List[Segment]]): A list of lines. width (int): Desired width. height (int, optional): Desired height or None for no change. style (Style): Style of any padding added. new_lines (bool, optional): Padded lines should include “
“. Defaults to False.
- Returns:
List[List[Segment]]: New list of lines.
- classmethod apply_style(segments, style=None, post_style=None)[source]¶
Apply style(s) to an iterable of segments.
Returns an iterable of segments where the style is replaced by
style + segment.style + post_style
.- Parameters
- Returns
A new iterable of segments (possibly the same iterable).
- Return type
Iterable[Segments]
- property cell_length: int¶
The number of terminal cells required to display self.text.
- Returns
A number of cells.
- Return type
- property control¶
Alias for field number 2
- classmethod filter_control(segments, is_control=False)[source]¶
Filter segments by
is_control
attribute.
- classmethod set_shape(lines, width, height=None, style=None, new_lines=False)[source]¶
Set the shape of a list of lines (enclosing rectangle).
- Args:
lines (List[List[Segment]]): A list of lines. width (int): Desired width. height (int, optional): Desired height or None for no change. style (Style, optional): Style of any padding added. new_lines (bool, optional): Padded lines should include “
“. Defaults to False.
- Returns:
List[List[Segment]]: New list of lines.
- classmethod simplify(segments)[source]¶
Simplify an iterable of segments by combining contiguous segments with the same style.
- classmethod split_and_crop_lines(segments, length, style=None, pad=True, include_new_lines=True)[source]¶
Split segments in to lines, and crop lines greater than a given length.
- Parameters
- Returns
An iterable of lines of segments.
- Return type
Iterable[List[Segment]]
- split_cells(cut)[source]¶
Split segment in to two segments at the specified column.
If the cut point falls in the middle of a 2-cell wide character then it is replaced by two spaces, to preserve the display width of the parent segment.
- property style¶
Alias for field number 1
- property text¶
Alias for field number 0