diff --git a/chromaterm/cli.py b/chromaterm/cli.py index 5135fe0d..16909981 100644 --- a/chromaterm/cli.py +++ b/chromaterm/cli.py @@ -30,8 +30,10 @@ SGR_RE = re.compile(r'\x1b\[[0-9;]*m') # Sequences upon which ct will split during processing. This includes new lines, -# vertical spaces, form feeds, C1 set (ECMA-048), CSI (excluding SGR), and OSC. +# vertical spaces, form feeds, C1 set (ECMA-048), SCS (G0 through G3 sets), +# CSI (excluding SGR), and OSC. SPLIT_RE = re.compile(r'(\r\n?|\n|\v|\f|\x1b[\x40-\x5a\x5c\x5e\x5f]|' + r'\x1b[\x28-\x2b\x2d-\x2f][\x20-\x7e]|' r'\x1b\x5b[\x30-\x3f]*[\x20-\x2f]*[\x40-\x6c\x6e-\x7e]|' r'\x1b\x5d[\x08-\x0d\x20-\x7e]*(?:\x07|\x1b\x5c))') diff --git a/chromaterm/tests/test_cli.py b/chromaterm/tests/test_cli.py index ea59a412..9420f49b 100644 --- a/chromaterm/tests/test_cli.py +++ b/chromaterm/tests/test_cli.py @@ -819,6 +819,20 @@ def test_split_buffer_osc_title(): assert repr(chromaterm.cli.split_buffer(data)) == repr(expected) +def test_split_buffer_scs(): + """Select Character Set (SCS) is used to change the terminal character set.""" + g_sets = ['\x28', '\x29', '\x2a', '\x2b', '\x2d', '\x2e', '\x2f'] + char_sets = map(chr, range(int('20', 16), int('7e', 16))) + + for g_set in g_sets: + for char_set in char_sets: + code = '\x1b{}{}'.format(g_set, char_set) + data = 'Hello {} World'.format(code) + expected = (('Hello ', code), (' World', '')) + + assert repr(chromaterm.cli.split_buffer(data)) == repr(expected) + + def test_main_broken_pipe(): """Break a pipe while CT is trying to write to it. The echo at the end will close before CT has had the chance to write to the pipe.""" diff --git a/docs/release-notes.md b/docs/release-notes.md index 7a5e4add..16f9c0bb 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -5,6 +5,7 @@ ### v0.6.2 – under development * Detect bright background and foreground colors that may exist in the input of `ct`. +* [#87](https://github.com/hSaria/ChromaTerm/issues/87) - The _Select Character Set_ ANSI codes (rarely used) were not being handled (ignored) appropriately, resulting in malformed output. ---