Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Commit

Permalink
Ignore private control functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hSaria committed Jan 11, 2022
1 parent 06c69e1 commit ef28eaf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions chromaterm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
READ_SIZE = 4096 # 4 KiB

# Sequences upon which ct will split during processing. This includes new lines,
# vertical spaces, form feeds, C1 set (ECMA-048), SCS (G0 through G3 sets),
# CSI (excluding SGR), and OSC.
SPLIT_RE = re.compile(br'(\r\n?|\n|\v|\f|\x1b[\x40-\x5a\x5c\x5e\x5f]|'
# vertical spaces, form feeds, private control functions (ECMA-035) and C1 set
# (ECMA-048), SCS (G0 through G3 sets), CSI (excluding SGR), and OSC.
SPLIT_RE = re.compile(br'(\r\n?|\n|\v|\f|\x1b[\x30-\x5a\x5c\x5e\x5f]|'
br'\x1b[\x28-\x2b\x2d-\x2f][\x20-\x7e]|'
br'\x1b\x5b[\x30-\x3f]*[\x20-\x2f]*[\x40-\x6c\x6e-\x7e]|'
br'\x1b\x5d[^\x07\x1b]*(?:\x07|\x1b\x5c)?)')
Expand Down
9 changes: 9 additions & 0 deletions tests/test__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,15 @@ def test_split_buffer_printer_commands():
assert chromaterm.__main__.split_buffer(data) == expected


def test_split_buffer_private_control_functions():
'''Split based on the ECMA-035 private control functions.'''
for char_id in range(int('30', 16), int('40', 16)):
data = b'Hello \x1b%c World' % char_id
expected = ((b'Hello ', b'\x1b%c' % char_id), (b' World', b''))

assert chromaterm.__main__.split_buffer(data) == expected


def test_split_buffer_c1_set():
'''Split based on the ECMA-048 C1 set, excluding CSI and OSC.'''
c1_except_csi_and_osc = itertools.chain(
Expand Down

0 comments on commit ef28eaf

Please sign in to comment.