diff --git a/openandroidinstaller/widgets.py b/openandroidinstaller/widgets.py index fe479767..d57c006f 100644 --- a/openandroidinstaller/widgets.py +++ b/openandroidinstaller/widgets.py @@ -42,7 +42,12 @@ def __init__(self, expand: bool = True, visible: bool = False): def build(self): self._box = Container( - content=Column(scroll="auto", expand=True, auto_scroll=True), + content=Column( + controls=[Text("", selectable=True)], + scroll="auto", + expand=True, + auto_scroll=True, + ), margin=10, padding=10, alignment=alignment.top_left, @@ -61,7 +66,10 @@ def write_line(self, line: str): Ignores empty lines. """ if (type(line) == str) and line.strip(): - self._box.content.controls.append(Text(f">{line.strip()}", selectable=True)) + self._box.content.controls[0].value += f"\n>{line.strip()}" + self._box.content.controls[0].value = self._box.content.controls[ + 0 + ].value.strip("\n") self.update() def toggle_visibility(self): @@ -72,7 +80,7 @@ def toggle_visibility(self): def clear(self): """Clear terminal output.""" - self._box.content.controls = [] + self._box.content.controls[0].value = "" self.update() def update(self): diff --git a/tests/test_terminal_box.py b/tests/test_terminal_box.py index 526254c5..6a530e50 100644 --- a/tests/test_terminal_box.py +++ b/tests/test_terminal_box.py @@ -42,8 +42,8 @@ def test_write_lines(mocker): for line in ["test", "test_line2", True]: terminal_box.write_line(line) - # two text elements should appear - assert len(terminal_box._box.content.controls) == 2 + # two lines of text should appear + assert len(terminal_box._box.content.controls[0].value.split("\n")) == 2 def test_toggle_visibility(mocker): @@ -87,5 +87,5 @@ def test_clear_terminal(mocker): # now clear terminal_box.clear() - # two text elements should appear - assert len(terminal_box._box.content.controls) == 0 + # text element should be empty + assert terminal_box._box.content.controls[0].value == ""