Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def _commit(self, idx):
with self.out_lock:
if self._above:
sys.stdout.write(f"\x1b[{self._above}A")
sys.stdout.write("\x1b[J")
sys.stdout.write("\r\x1b[J")
sys.stdout.write("".join(f"{l}\n" for l in para))
sys.stdout.flush()
self._above = 0
Expand Down
29 changes: 29 additions & 0 deletions tests/test_terminal_rendering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import io
import threading
import unittest
from unittest.mock import patch

from aloud import Player, Segment


class TerminalRenderingTests(unittest.TestCase):
def test_commit_returns_to_first_column_before_clearing_live_region(self):
player = Player.__new__(Player)
player.chunks = [Segment("one two three four five six")]
player.out_lock = threading.Lock()
player._above = 2
player._para_lines = 2
output = io.StringIO()

with patch.object(Player, "_term_width", return_value=18), \
patch("sys.stdout", output):
player._commit(0)

self.assertEqual(
output.getvalue(),
"\x1b[2A\r\x1b[Jone two three four\nfive six\n",
)


if __name__ == "__main__":
unittest.main()