def test_adjust_line_length(): line = [Segment("Hello", "foo")] assert Segment.adjust_line_length(line, 10, style="bar") == [ Segment("Hello", "foo"), Segment(" ", "bar"), ] line = [Segment("H"), Segment("ello, World!")] assert Segment.adjust_line_length(line, 5) == [Segment("H"), Segment("ello")] line = [Segment("Hello")] assert Segment.adjust_line_length(line, 5) == line
def render(self, x: int, y: int, width: int, height: int) -> Iterable[Segment]: move_to = Control.move_to lines = self.lines[:height] new_line = Segment.line() for last, (offset_y, (line, dirty)) in loop_last( enumerate(zip(lines, self._dirty), y) ): if dirty: yield move_to(x, offset_y).segment yield from Segment.adjust_line_length(line, width) if not last: yield new_line self._dirty[:] = [False] * len(self.lines)