Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
Properly handle zero width characters (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbedos committed Jan 19, 2019
1 parent 7b64141 commit c39675a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion termtosvg/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ def screen_events(records, min_frame_dur=1, max_frame_dur=None, last_frame_dur=1
time = 0
for record_ in timed_records:
assert isinstance(record_, AsciiCastV2Event)
stream.feed(record_.event_data)
for c in record_.event_data:
stream.feed(c)
redraw_buffer, last_cursor = _redraw_buffer(screen, last_cursor)
display_events, events = _feed(redraw_buffer, display_events, time)
if events:
Expand Down
31 changes: 31 additions & 0 deletions termtosvg/tests/test_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,37 @@ def test_screen_events_empty_groups(self):
with self.subTest(case='No empty group - item #{}'.format(count)):
self.assertEqual(expected_item, item)

def test_screen_events_unprintable_chars(self):
# Ensure zero width characters in terminal output does not result
# in Pyte dropping all following data
# Issue https://github.com/nbedos/termtosvg/issues/89

# test_text = "e🕵️‍a"
test_text = (b'e' +
b'\xf0\x9f\x95\xb5' + # sleuth emoji
b'\xef\xb8\x8f' + # variation selector 16
b'\xe2\x80\x8d' + # zero width joiner
b'a').decode('utf-8')

records = [
AsciiCastV2Header(version=2, width=80, height=24, theme=THEME),
AsciiCastV2Event(0, 'o', test_text, None),
]
events = term.screen_events(records, 1, None, last_frame_dur=1000)

# Skip configuration event
next(events)

# Ensure data following sleuth emoji wasn't ignored
character_cells = next(events)[0].line

line_text = ''.join(character_cells[c].text
for c in sorted(character_cells))

# rstrip() removes blank cursor character at end of line
self.assertEqual(line_text[-2], test_text[-1])


def test_get_terminal_size(self):
with self.subTest(case='Successful get_terminal_size call'):
term_size_mock = MagicMock(return_value=(42, 84))
Expand Down

0 comments on commit c39675a

Please sign in to comment.