From c50465c9c2fc335b8f3dc243bea446636fba8c75 Mon Sep 17 00:00:00 2001 From: eight04 Date: Wed, 28 Feb 2024 17:52:49 +0800 Subject: [PATCH] Fix: c0 is broken --- pyte/streams.py | 13 +++++++++++-- tests/test_stream.py | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pyte/streams.py b/pyte/streams.py index 8417042..262cbe0 100644 --- a/pyte/streams.py +++ b/pyte/streams.py @@ -238,6 +238,9 @@ def _parser_fsm(self) -> ParserGenerator: draw = listener.draw debug = listener.debug + use_c1 = self.use_c1 + in_control = False + ESC, CSI_C1 = ctrl.ESC, ctrl.CSI_C1 OSC_C1 = ctrl.OSC_C1 SP_OR_GT = ctrl.SP + ">" @@ -275,6 +278,7 @@ def create_dispatcher(mapping: Mapping[str, str]) -> Dict[str, Callable[..., Non # recognizes ``ESC % C`` sequences for selecting control # character set. However, in the current version these # are noop. + in_control = True char = yield None if char == "[": char = CSI_C1 # Go to CSI. @@ -305,7 +309,7 @@ def create_dispatcher(mapping: Mapping[str, str]) -> Dict[str, Callable[..., Non continue basic_dispatch[char]() - elif char == CSI_C1 and self.use_c1: + elif char == CSI_C1 and (use_c1 or in_control): # 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 @@ -355,11 +359,14 @@ def create_dispatcher(mapping: Mapping[str, str]) -> Dict[str, Callable[..., Non else: csi_dispatch[char](*params) break # CSI is finished. - elif char == OSC_C1 and self.use_c1: + in_control = False + elif char == OSC_C1 and (use_c1 or in_control): code = yield None if code == "R": + in_control = False continue # Reset palette. Not implemented. elif code == "P": + in_control = False continue # Set palette. Not implemented. param = "" @@ -377,6 +384,8 @@ def create_dispatcher(mapping: Mapping[str, str]) -> Dict[str, Callable[..., Non listener.set_icon_name(param) if code in "02": listener.set_title(param) + + in_control = False elif char not in NUL_OR_DEL: draw(char) diff --git a/tests/test_stream.py b/tests/test_stream.py index 79b6a57..59f0fed 100644 --- a/tests/test_stream.py +++ b/tests/test_stream.py @@ -342,3 +342,12 @@ def test_byte_stream_without_c1() -> None: stream.feed(b) assert screen.display[0] == "\x9b\xf3 " assert stream.use_c1 == False + +def test_byte_stream_without_c1_with_c0() -> None: + screen = pyte.ByteScreen(3, 3) + stream = pyte.ByteStream(screen, use_c1=False) + stream.select_other_charset("@") + stream.feed(b"\x1b[1;36m") + assert screen.display[0] == " " + +