MCPcopy
hub / github.com/Textualize/rich / Lines

Class Lines

rich/containers.py:66–167  ·  view source on GitHub ↗

A list subclass which can render to the console.

Source from the content-addressed store, hash-verified

64
65
66class Lines:
67 """A list subclass which can render to the console."""
68
69 def __init__(self, lines: Iterable["Text"] = ()) -> None:
70 self._lines: List["Text"] = list(lines)
71
72 def __repr__(self) -> str:
73 return f"Lines({self._lines!r})"
74
75 def __iter__(self) -> Iterator["Text"]:
76 return iter(self._lines)
77
78 @overload
79 def __getitem__(self, index: int) -> "Text":
80 ...
81
82 @overload
83 def __getitem__(self, index: slice) -> List["Text"]:
84 ...
85
86 def __getitem__(self, index: Union[slice, int]) -> Union["Text", List["Text"]]:
87 return self._lines[index]
88
89 def __setitem__(self, index: int, value: "Text") -> "Lines":
90 self._lines[index] = value
91 return self
92
93 def __len__(self) -> int:
94 return self._lines.__len__()
95
96 def __rich_console__(
97 self, console: "Console", options: "ConsoleOptions"
98 ) -> "RenderResult":
99 """Console render method to insert line-breaks."""
100 yield from self._lines
101
102 def append(self, line: "Text") -> None:
103 self._lines.append(line)
104
105 def extend(self, lines: Iterable["Text"]) -> None:
106 self._lines.extend(lines)
107
108 def pop(self, index: int = -1) -> "Text":
109 return self._lines.pop(index)
110
111 def justify(
112 self,
113 console: "Console",
114 width: int,
115 justify: "JustifyMethod" = "left",
116 overflow: "OverflowMethod" = "fold",
117 ) -> None:
118 """Justify and overflow text to a given width.
119
120 Args:
121 console (Console): Console instance.
122 width (int): Number of cells available per line.
123 justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".

Callers 6

test_lines_rich_consoleFunction · 0.90
test_lines_justifyFunction · 0.90
splitMethod · 0.85
divideMethod · 0.85
wrapMethod · 0.85
fitMethod · 0.85

Calls

no outgoing calls

Tested by 2

test_lines_rich_consoleFunction · 0.72
test_lines_justifyFunction · 0.72