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

Commit

Permalink
Fixes #87: Correctly handle SCS ANSI codes
Browse files Browse the repository at this point in the history
  • Loading branch information
hSaria committed May 17, 2020
1 parent 513c304 commit b99cbc4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion chromaterm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))')

Expand Down
14 changes: 14 additions & 0 deletions chromaterm/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down

0 comments on commit b99cbc4

Please sign in to comment.