terminal-util: don't issue "ESC c" sequence on reset, but only when erasing the screen
authorLennart Poettering <lennart@poettering.net>
Thu, 11 Jul 2024 07:34:11 +0000 (09:34 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 19 Jul 2024 22:33:14 +0000 (00:33 +0200)
ESC c is a (vaguely defined) "reset to initial state" ANSI sequence.
Many terminals clear the screen in this case, but that's a bit drastic I
think for most resets.

ESC c was added to the reset logic in
00bc83a275fa3ca8d90579fe9597d8b651d47332 (i.e. very recently), and I
don't think the effect was clear at that time.

Let's keep the ESC c in place however when we actually want to clear the
screen. Hence move it from reset_terminal_fd() into vt_disallocate().

Fixes: #33689
(cherry picked from commit 841eb9c186816acfef8f3f724647a7f0649f214d)

src/basic/terminal-util.c

index dda592089cb2a46bef8c02232618d22761ddf9ff..3a1b7b2ede50df5c893480fc94f73fa42bec4c18 100644 (file)
@@ -584,8 +584,9 @@ int vt_disallocate(const char *name) {
         (void) loop_write(fd2,
                           "\033[r"   /* clear scrolling region */
                           "\033[H"   /* move home */
-                          "\033[3J", /* clear screen including scrollback, requires Linux 2.6.40 */
-                          10);
+                          "\033[3J"  /* clear screen including scrollback, requires Linux 2.6.40 */
+                          "\033c",   /* reset to initial state */
+                          SIZE_MAX);
         return 0;
 }
 
@@ -1558,7 +1559,6 @@ int terminal_reset_ansi_seq(int fd) {
                 return log_debug_errno(r, "Failed to set terminal to non-blocking mode: %m");
 
         k = loop_write_full(fd,
-                            "\033c"        /* reset to initial state */
                             "\033[!p"      /* soft terminal reset */
                             "\033]104\007" /* reset colors */
                             "\033[?7h",    /* enable line-wrapping */