1from itertools
import zip_longest
14 from .console
import (
22 from .text
import Text
24from .cells
import cell_len
25from .measure
import Measurement
31 """A list subclass which renders its contents to the console."""
34 self, renderables: Optional[Iterable[
"RenderableType"]] =
None
37 list(renderables)
if renderables
is not None else []
41 self, console:
"Console", options:
"ConsoleOptions"
43 """Console render method to insert line-breaks."""
47 self, console:
"Console", options:
"ConsoleOptions"
59 def append(self, renderable:
"RenderableType") ->
None:
62 def __iter__(self) -> Iterable["RenderableType"]:
67 """A list subclass which can render to the console."""
69 def __init__(self, lines: Iterable[
"Text"] = ()) ->
None:
70 self.
_lines: List[
"Text"] = list(lines)
73 return f
"Lines({self._lines!r})"
86 def __getitem__(self, index: Union[slice, int]) -> Union[
"Text", List[
"Text"]]:
97 self, console:
"Console", options:
"ConsoleOptions"
99 """Console render method to insert line-breaks."""
105 def extend(self, lines: Iterable[
"Text"]) ->
None:
108 def pop(self, index: int = -1) ->
"Text":
115 justify:
"JustifyMethod" =
"left",
116 overflow:
"OverflowMethod" =
"fold",
118 """Justify and overflow text to a given width.
121 console (Console): Console instance.
122 width (int): Number of characters per line.
123 justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
124 overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
127 from .text
import Text
129 if justify ==
"left":
132 elif justify ==
"center":
138 elif justify ==
"right":
143 elif justify ==
"full":
149 num_spaces =
len(words) - 1
150 spaces = [1
for _
in range(num_spaces)]
153 while words_size + num_spaces < width:
154 spaces[
len(spaces) - index - 1] += 1
156 index = (index + 1) %
len(spaces)
157 tokens: List[Text] = []
158 for index, (word, next_word)
in enumerate(
159 zip_longest(words, words[1:])
162 if index <
len(spaces):
165 space_style = style
if style == next_style
else line.style
167 self[line_index] =
Text(
"").join(tokens)
Iterator["Text"] __iter__(self)
"Lines" __setitem__(self, int index, "Text" value)
"Text" __getitem__(self, int index)
None append(self, "Text" line)
None __init__(self, Iterable["Text"] lines=())
"RenderResult" __rich_console__(self, "Console" console, "ConsoleOptions" options)
"Text" pop(self, int index=-1)
None extend(self, Iterable["Text"] lines)
None justify(self, "Console" console, int width, "JustifyMethod" justify="left", "OverflowMethod" overflow="fold")
"Measurement" __rich_measure__(self, "Console" console, "ConsoleOptions" options)
None append(self, "RenderableType" renderable)
Iterable["RenderableType"] __iter__(self)
"RenderResult" __rich_console__(self, "Console" console, "ConsoleOptions" options)
None __init__(self, Optional[Iterable["RenderableType"]] renderables=None)