Skip to content

Commit b81be31

Browse files
committed
Add: use_c1 option to Stream
1 parent 08a46e7 commit b81be31

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pyte/streams.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ class Stream:
139139
"[^" + "".join(map(re.escape, _special)) + "]+")
140140
del _special
141141

142-
def __init__(self, screen: Optional[Screen] = None, strict: bool = True) -> None:
142+
def __init__(self, screen: Optional[Screen] = None, strict: bool = True, use_c1: bool = True) -> None:
143143
self.listener: Optional[Screen] = None
144144
self.strict = strict
145145
self.use_utf8: bool = True
146+
self.use_c1: bool = use_c1
146147

147148
self._taking_plain_text: Optional[bool] = None
148149

@@ -304,7 +305,7 @@ def create_dispatcher(mapping: Mapping[str, str]) -> Dict[str, Callable[..., Non
304305
continue
305306

306307
basic_dispatch[char]()
307-
elif char == CSI_C1:
308+
elif char == CSI_C1 and self.use_c1:
308309
# All parameters are unsigned, positive decimal integers, with
309310
# the most significant digit sent first. Any parameter greater
310311
# than 9999 is set to 9999. If you do not specify a value, a 0
@@ -354,7 +355,7 @@ def create_dispatcher(mapping: Mapping[str, str]) -> Dict[str, Callable[..., Non
354355
else:
355356
csi_dispatch[char](*params)
356357
break # CSI is finished.
357-
elif char == OSC_C1:
358+
elif char == OSC_C1 and self.use_c1:
358359
code = yield None
359360
if code == "R":
360361
continue # Reset palette. Not implemented.

tests/test_stream.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,13 @@ def test_byte_stream_select_other_charset():
332332
# c) enable utf-8
333333
stream.select_other_charset("G")
334334
assert stream.use_utf8
335+
336+
337+
def test_byte_stream_without_c1() -> None:
338+
screen = pyte.ByteScreen(3, 3)
339+
stream = pyte.ByteStream(screen, use_c1=False)
340+
stream.select_other_charset("@")
341+
b = '𡶐'.encode("big5-hkscs")
342+
stream.feed(b)
343+
assert screen.display[0] == "\x9b\xf3 "
344+
assert stream.use_c1 == False

0 commit comments

Comments
 (0)