From e3d92df936b97aef3cd51f1e85eb3c47409069c5 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 8 Oct 2017 13:45:08 +0100 Subject: [PATCH] Save and restore true-colour state with the cursor. I spotted this myself while looking through the code in search of the cause of the background-colour-erase bug: saving and restoring the cursor via ESC 7 / ESC 8 ought to also save and restore the current graphics rendition attributes including foreground and background colour settings, but it was not saving and restoring the new term->curr_truecolour along with term->curr_attr. So there's now a term->save_truecolour to keep that in, and also a term->alt_save_truecolour to take account of the fact that all the saved cursor state variables get swapped out _again_ when switching between the main and alternate screens. (However, there is not a term->alt_truecolour to complete the cross product, because the _active_ graphics rendition is carried over when switching between the terminal screens; it's only the _saved_ one from ESC 7 / ESC 8 that is saved separately. That's consistent with the behaviour we've had all along for ordinary fg/bg colour selection.) --- terminal.c | 8 ++++++++ terminal.h | 1 + 2 files changed, 9 insertions(+) diff --git a/terminal.c b/terminal.c index 8c44b906..7a7207a0 100644 --- a/terminal.c +++ b/terminal.c @@ -1297,6 +1297,7 @@ static void power_on(Terminal *term, int clear) term->default_attr = term->save_attr = term->alt_save_attr = term->curr_attr = ATTR_DEFAULT; term->curr_truecolour.fg = term->curr_truecolour.bg = optionalrgb_none; + term->save_truecolour = term->alt_save_truecolour = term->curr_truecolour; term->term_editing = term->term_echoing = FALSE; term->app_cursor_keys = conf_get_int(term->conf, CONF_app_cursor); term->app_keypad_keys = conf_get_int(term->conf, CONF_app_keypad); @@ -1987,6 +1988,7 @@ static void swap_screen(Terminal *term, int which, int reset, int keep_cur_pos) { int t; pos tp; + truecolour ttc; tree234 *ttr; if (!which) @@ -2051,6 +2053,10 @@ static void swap_screen(Terminal *term, int which, int reset, int keep_cur_pos) if (!reset && !keep_cur_pos) term->save_attr = term->alt_save_attr; term->alt_save_attr = t; + ttc = term->save_truecolour; + if (!reset && !keep_cur_pos) + term->save_truecolour = term->alt_save_truecolour; + term->alt_save_truecolour = ttc; t = term->save_utf; if (!reset && !keep_cur_pos) term->save_utf = term->alt_save_utf; @@ -2346,6 +2352,7 @@ static void save_cursor(Terminal *term, int save) if (save) { term->savecurs = term->curs; term->save_attr = term->curr_attr; + term->save_truecolour = term->curr_truecolour; term->save_cset = term->cset; term->save_utf = term->utf; term->save_wnext = term->wrapnext; @@ -2360,6 +2367,7 @@ static void save_cursor(Terminal *term, int save) term->curs.y = term->rows - 1; term->curr_attr = term->save_attr; + term->curr_truecolour = term->save_truecolour; term->cset = term->save_cset; term->utf = term->save_utf; term->wrapnext = term->save_wnext; diff --git a/terminal.h b/terminal.h index 4a205a77..fcb321c4 100644 --- a/terminal.h +++ b/terminal.h @@ -140,6 +140,7 @@ struct terminal_tag { /* ESC 7 saved state for the alternate screen */ pos alt_savecurs; int alt_save_attr; + truecolour alt_save_truecolour; int alt_save_cset, alt_save_csattr; int alt_save_utf, alt_save_wnext; int alt_save_sco_acs;