From b00cd5cbc3ba1ae1ee8e9fb8c7f7ccfd596c082d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 1 Dec 2020 17:55:17 +0530 Subject: [PATCH] Match save/restore cursor behavior of other terms For the sake of interoperability. This means that doing a DECRC without a prior DECSC is now undefined. However, one can now issue multiple DECRC for a single DECSC. Fixes #1264 --- docs/changelog.rst | 4 ++++ kitty/screen.c | 13 ++++++------- kitty/screen.h | 10 ++-------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index a9ba357d1..6314bc22b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -38,6 +38,10 @@ To update |kitty|, :doc:`follow the instructions `. - Fix one ANSI formatting escape code not being removed from the pager history buffer when piping it as plain text (:iss:`3132`) +- Match the save/restore cursor behavior of other terminals, for the sake of + interoperability. This means that doing a DECRC without a prior DECSC is now + undefined (:iss:`1264`) + 0.19.2 [2020-11-13] ------------------- diff --git a/kitty/screen.c b/kitty/screen.c index f1b4e6c43..c0152c323 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -149,6 +149,8 @@ void screen_reset(Screen *self) { if (self->linebuf == self->alt_linebuf) screen_toggle_screen_buffer(self, true, true); if (self->overlay_line.is_active) deactivate_overlay_line(self); + self->main_savepoint.is_valid = false; + self->alt_savepoint.is_valid = false; linebuf_clear(self->linebuf, BLANK_CHAR); historybuf_clear(self->historybuf); clear_hyperlink_pool(self->hyperlink_pool); @@ -1096,14 +1098,13 @@ screen_linefeed(Screen *self) { void screen_save_cursor(Screen *self) { - SavepointBuffer *pts = self->linebuf == self->main_linebuf ? &self->main_savepoints : &self->alt_savepoints; - Savepoint *sp; - buffer_push(pts, sp); + Savepoint *sp = self->linebuf == self->main_linebuf ? &self->main_savepoint : &self->alt_savepoint; cursor_copy_to(self->cursor, &(sp->cursor)); sp->mDECOM = self->modes.mDECOM; sp->mDECAWM = self->modes.mDECAWM; sp->mDECSCNM = self->modes.mDECSCNM; COPY_CHARSETS(self, sp); + sp->is_valid = true; } void @@ -1115,10 +1116,8 @@ screen_save_modes(Screen *self) { void screen_restore_cursor(Screen *self) { - SavepointBuffer *pts = self->linebuf == self->main_linebuf ? &self->main_savepoints : &self->alt_savepoints; - Savepoint *sp; - buffer_pop(pts, sp); - if (sp == NULL) { + Savepoint *sp = self->linebuf == self->main_linebuf ? &self->main_savepoint : &self->alt_savepoint; + if (!sp->is_valid) { screen_cursor_position(self, 1, 1); screen_reset_mode(self, DECOM); RESET_CHARSETS; diff --git a/kitty/screen.h b/kitty/screen.h index 6546ae244..7affb4441 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -58,16 +58,10 @@ typedef struct { bool use_latin1; Cursor cursor; bool mDECOM, mDECAWM, mDECSCNM; - + bool is_valid; } Savepoint; -typedef struct { - Savepoint buf[SAVEPOINTS_SZ]; - index_type start_of_data, count; -} SavepointBuffer; - - typedef struct { ScreenModes buf[SAVEPOINTS_SZ]; index_type start_of_data, count; @@ -97,7 +91,7 @@ typedef struct { } last_rendered; bool use_latin1, is_dirty, scroll_changed, reload_all_gpu_data; Cursor *cursor; - SavepointBuffer main_savepoints, alt_savepoints; + Savepoint main_savepoint, alt_savepoint; SavemodesBuffer modes_savepoints; PyObject *callbacks, *test_child; LineBuf *linebuf, *main_linebuf, *alt_linebuf;