Skip to content

Commit

Permalink
Fix: c0 is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
eight04 committed Feb 28, 2024
1 parent 6faa91a commit c50465c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pyte/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ">"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = ""
Expand All @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] == " "


0 comments on commit c50465c

Please sign in to comment.