diff --git a/kitty/screen.py b/kitty/screen.py index e073ff808..b583c8373 100644 --- a/kitty/screen.py +++ b/kitty/screen.py @@ -86,6 +86,15 @@ class Screen(QObject): def display(self) -> Sequence[str]: return tuple(map(str, self.linebuf)) + def toggle_screen_buffer(self): + self.save_cursor() + if self.linebuf is self.main_linebuf: + self.linebuf, self.savepoints = self.alt_linebuf, self.alt_savepoints + else: + self.linebuf, self.savepoints = self.main_linebuf, self.main_savepoints + self.restore_cursor() + self.update_screen() + def reset(self): """Resets the terminal to its initial state. @@ -102,6 +111,8 @@ class Screen(QObject): and tabstops should be reset as well, thanks to :manpage:`xterm` -- we now know that. """ + if self.linebuf is self.alt_linebuf: + self.toggle_screen_buffer() self.linebuf.clear() self.linebuf[:] = (Line(self.columns) for i in range(self.lines)) self.mode = {mo.DECAWM, mo.DECTCEM} @@ -117,10 +128,12 @@ class Screen(QObject): # set every `n` spaces when the terminal is powered up. Since # we aim to support VT102 / VT220 and linux -- we use n = 8. self.tabstops = set(range(7, self.columns, 8)) + self.normal_keypad_mode() self.cursor = Cursor(0, 0) self.cursor_changed(self.cursor) self.cursor_position() + self.update_screen() def resize(self, lines: int, columns: int): """Resize the screen to the given dimensions. @@ -225,10 +238,7 @@ class Screen(QObject): self.cursor_changed(self.cursor) if mo.ALTERNATE_SCREEN in self.mode and self.linebuf is self.main_linebuf: - self.save_cursor() - self.linebuf, self.savepoints = self.alt_linebuf, self.alt_savepoints - self.restore_cursor() - self.update_screen() + self.toggle_screen_buffer() @property def in_bracketed_paste_mode(self): @@ -274,10 +284,7 @@ class Screen(QObject): self.cursor_changed(self.cursor) if mo.ALTERNATE_SCREEN not in self.mode and self.linebuf is not self.main_linebuf: - self.save_cursor() - self.linebuf, self.savepoints = self.main_linebuf, self.main_savepoints - self.restore_cursor() - self.update_screen() + self.toggle_screen_buffer() def define_charset(self, code, mode): """Defines ``G0`` or ``G1`` charset. @@ -975,10 +982,10 @@ class Screen(QObject): else: # DECLL pass - def numeric_keypad_mode(self): + def normal_keypad_mode(self): pass # TODO: Implement this - def application_keypad_mode(self): + def alternate_keypad_mode(self): pass # TODO: Implement this def debug(self, *args, **kwargs): diff --git a/pyte/escape.py b/pyte/escape.py index 45daaec8c..7f039bc2a 100644 --- a/pyte/escape.py +++ b/pyte/escape.py @@ -39,10 +39,10 @@ DECSC = b"7" #: selection. If none were saved, move cursor to home position. DECRC = b"8" -#: Set numeric keypad mode +#: Set normal keypad mode DECPNM = b'>' -#: Set application keypad mode +#: Set alternate keypad mode DECPAM = b'=' # "Sharp" escape sequences. diff --git a/pyte/streams.py b/pyte/streams.py index cc308a1bc..77b469c1d 100644 --- a/pyte/streams.py +++ b/pyte/streams.py @@ -82,8 +82,8 @@ class Stream(object): esc.HTS: "set_tab_stop", esc.DECSC: "save_cursor", esc.DECRC: "restore_cursor", - esc.DECPNM: 'numeric_keypad_mode', - esc.DECPAM: 'application_keypad_mode', + esc.DECPNM: 'normal_keypad_mode', + esc.DECPAM: 'alternate_keypad_mode', } #: "sharp" escape sequences -- ``ESC # ``. diff --git a/terminfo/kitty.terminfo b/terminfo/kitty.terminfo index 9a1a9ee08..a87bcc3d2 100644 --- a/terminfo/kitty.terminfo +++ b/terminfo/kitty.terminfo @@ -53,7 +53,6 @@ xterm-kitty|KovIdTTY, indn=\E[%p1%dS, initc=\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\, invis=\E[8m, - is2=\E[!p\E[?3;4l\E[4l\E>, kbs=\177, kcub1=\EOD, kcud1=\EOB, @@ -93,12 +92,10 @@ xterm-kitty|KovIdTTY, rmam=\E[?7l, rmcup=\E[?1049l, rmir=\E[4l, - rmkx=\E[?1l\E>, rmm=\E[?1034l, rmso=\E[27m, rmul=\E[24m, rs1=\Ec, - rs2=\E[!p\E[?3;4l\E[4l\E>, sc=\E7, setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m, setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m, @@ -108,7 +105,6 @@ xterm-kitty|KovIdTTY, smam=\E[?7h, smcup=\E[?1049h, smir=\E[4h, - smkx=\E[?1h\E=, smm=\E[?1034h, smso=\E[7m, smul=\E[4m, diff --git a/terminfo/x/xterm-kitty b/terminfo/x/xterm-kitty index 4483239c2..efd38d43a 100644 Binary files a/terminfo/x/xterm-kitty and b/terminfo/x/xterm-kitty differ