]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ptyfwd: reset color after two tty reset sequences, too
authorLennart Poettering <lennart@poettering.net>
Thu, 18 Jul 2024 12:28:52 +0000 (14:28 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Jul 2024 13:41:33 +0000 (15:41 +0200)
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

index 842aef927025751bfd4a763a1c673520dc395efb..83eef7f7d8225a9b0ceb9dd2c5bc0e3b230c089e 100644 (file)
@@ -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)