Skip to content

Commit

Permalink
Add: use_c1 option to Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
eight04 committed Feb 28, 2024
1 parent 08a46e7 commit b81be31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pyte/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ class Stream:
"[^" + "".join(map(re.escape, _special)) + "]+")
del _special

def __init__(self, screen: Optional[Screen] = None, strict: bool = True) -> None:
def __init__(self, screen: Optional[Screen] = None, strict: bool = True, use_c1: bool = True) -> None:
self.listener: Optional[Screen] = None
self.strict = strict
self.use_utf8: bool = True
self.use_c1: bool = use_c1

self._taking_plain_text: Optional[bool] = None

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

basic_dispatch[char]()
elif char == CSI_C1:
elif char == CSI_C1 and self.use_c1:
# All parameters are unsigned, positive decimal integers, with
# the most significant digit sent first. Any parameter greater
# than 9999 is set to 9999. If you do not specify a value, a 0
Expand Down Expand Up @@ -354,7 +355,7 @@ def create_dispatcher(mapping: Mapping[str, str]) -> Dict[str, Callable[..., Non
else:
csi_dispatch[char](*params)
break # CSI is finished.
elif char == OSC_C1:
elif char == OSC_C1 and self.use_c1:
code = yield None
if code == "R":
continue # Reset palette. Not implemented.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,13 @@ def test_byte_stream_select_other_charset():
# c) enable utf-8
stream.select_other_charset("G")
assert stream.use_utf8


def test_byte_stream_without_c1() -> None:
screen = pyte.ByteScreen(3, 3)
stream = pyte.ByteStream(screen, use_c1=False)
stream.select_other_charset("@")
b = '𡶐'.encode("big5-hkscs")
stream.feed(b)
assert screen.display[0] == "\x9b\xf3 "
assert stream.use_c1 == False

0 comments on commit b81be31

Please sign in to comment.