Skip to content

Commit

Permalink
Make text in advanced output easier to copy
Browse files Browse the repository at this point in the history
  • Loading branch information
tsterbak committed Mar 3, 2023
1 parent 2e68a25 commit f77e13e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 11 additions & 3 deletions openandroidinstaller/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_terminal_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 == ""

0 comments on commit f77e13e

Please sign in to comment.