From 46b89b83e39a6eaa3cbc452ae5e9d3dbe25c8736 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 18 Jul 2024 14:28:52 +0200 Subject: [PATCH] ptyfwd: reset color after two tty reset sequences, too When we patch in a bg color we must make sure that when certain "reset" sequences are transferred we fix up the bg color again. Do so for \033[!p ("soft terminal reset") and \033c ("reset to initial state" aka "full reset"). --- src/shared/ptyfwd.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c index 842aef92702..83eef7f7d82 100644 --- a/src/shared/ptyfwd.c +++ b/src/shared/ptyfwd.c @@ -443,6 +443,16 @@ static int pty_forward_ansi_process(PTYForward *f, size_t offset) { } else if (c == ']') { f->ansi_color_state = ANSI_COLOR_STATE_OSC_SEQUENCE; continue; + } else if (c == 'c') { + /* "Full reset" aka "Reset to initial state"*/ + r = insert_background_color(f, i+1); + if (r < 0) + return r; + + i += r; + + f->ansi_color_state = ANSI_COLOR_STATE_TEXT; + continue; } break; @@ -462,7 +472,15 @@ static int pty_forward_ansi_process(PTYForward *f, size_t offset) { } else { /* Otherwise, the CSI sequence is over */ - if (c == 'm') { + if (c == 'p' && streq_ptr(f->csi_sequence, "!")) { + + /* CSI ! p → "Soft Reset", let's immediately fix our bg color again */ + r = insert_background_color(f, i+1); + if (r < 0) + return r; + + i += r; + } else if (c == 'm') { /* This is an "SGR" (Select Graphic Rendition) sequence. Patch in our background color. */ r = insert_background_fix(f, i); if (r < 0) -- 2.47.3