diff --git a/kitty/screen.py b/kitty/screen.py index c8eb67c13..0806d861e 100644 --- a/kitty/screen.py +++ b/kitty/screen.py @@ -10,7 +10,7 @@ from PyQt5.QtCore import QObject, pyqtSignal -from pyte import charsets as cs, control as ctrl, graphics as g, modes as mo +from pyte import charsets as cs, graphics as g, modes as mo from .data_types import Line, Cursor, rewrap_lines from .utils import wcwidth, is_simple_string, sanitize_title from .unicode import ignore_pat @@ -913,13 +913,13 @@ def report_device_attributes(self, mode=0, **kwargs): # If you implement xterm keycode querying you can change this to # mimic xterm instead (>41;327;0c) then vim wont need terminfo to # get keycodes (see :help xterm-codes) - self.write_process_input(ctrl.CSI + b'>1;4600;0c') + self.write_process_input(b'\x1b[>1;4600;0c') else: # xterm gives: [[?64;1;2;6;9;15;18;21;22c # use the simpler vte response, since we dont support # windowing/horizontal scrolling etc. # [[?64;1;2;6;9;15;18;21;22c - self.write_process_input(ctrl.CSI + b"?62c") + self.write_process_input(b"\x1b[?62c") def report_device_status(self, mode): """Reports terminal status or cursor position. @@ -930,7 +930,7 @@ def report_device_status(self, mode): .. versionadded:: 0.5.0 """ if mode == 5: # Request for terminal status. - self.write_process_input(ctrl.CSI + b"0n") + self.write_process_input(b"\x1b[0n") elif mode == 6: # Request for cursor position. x, y = wrap_cursor_position(self.cursor.x, self.cursor.y, self.lines, self.columns) x, y = x + 1, y + 1 @@ -938,7 +938,7 @@ def report_device_status(self, mode): # "Origin mode (DECOM) selects line numbering." if mo.DECOM in self.mode: y -= self.margins.top - self.write_process_input(ctrl.CSI + "{0};{1}R".format(y, x).encode('ascii')) + self.write_process_input("\x1b[{0};{1}R".format(y, x).encode('ascii')) def numeric_keypad_mode(self): pass # TODO: Implement this diff --git a/pyte/control.py b/pyte/control.py index f2a774933..931055e57 100644 --- a/pyte/control.py +++ b/pyte/control.py @@ -68,3 +68,6 @@ #: *Operating system command*. OSC = b"\x9d" + +#: Device Control function (DCS) +DCS = ESC + b"P" diff --git a/pyte/modes.py b/pyte/modes.py index 2b5c1500f..4393a2639 100644 --- a/pyte/modes.py +++ b/pyte/modes.py @@ -64,3 +64,11 @@ BRACKETED_PASTE = 2004 << 5 BRACKETED_PASTE_START = '\033[200~'.encode('ascii') BRACKETED_PASTE_END = '\033[201~'.encode('ascii') + +#: Xterm mouse protocol +SEND_MOUSE_ON_PRESS_AND_RELEASE = 1000 << 5 +HILITE_MOUSE_TRACKING = 1001 << 5 +CELL_MOTION_MOUSE_TRACKING = 1002 << 5 +FOCUS_TRACKING = 1004 << 5 +UTF8_MOUSE_MODE = 1005 << 5 +SGR_MOUSE_MODE = 1006 << 6 diff --git a/pyte/streams.py b/pyte/streams.py index 6344c2c65..15240520b 100644 --- a/pyte/streams.py +++ b/pyte/streams.py @@ -216,7 +216,7 @@ def _parser_fsm(self): debug = listener.debug ESC, CSI = ctrl.ESC, ctrl.CSI - OSC, ST = ctrl.OSC, ctrl.ST + OSC, ST, DCS = ctrl.OSC, ctrl.ST, ctrl.DCS SP_OR_GT = ctrl.SP + b">" NUL_OR_DEL = ctrl.NUL + ctrl.DEL CAN_OR_SUB = ctrl.CAN + ctrl.SUB @@ -256,6 +256,8 @@ def create_dispatcher(mapping): char = CSI # Go to CSI. elif char == b"]": char = OSC # Go to OSC. + elif char == b'P': + char = DCS # Go to DCS else: if char == b"#": sharp_dispatch[(yield)]() @@ -332,6 +334,17 @@ def create_dispatcher(mapping): listener.set_icon_name(param) if code in b"02": listener.set_title(param) + elif char == DCS: + # See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Device-Control-functions + code = yield + param = bytearray() + while True: + char = yield + if char == ST: + break + else: + param.extend(char) + # TODO: Implement these elif char not in NUL_OR_DEL: draw(char)