From 6d198d867fada1496d680022762883bf674cda53 Mon Sep 17 00:00:00 2001 From: luojiahao Date: Thu, 19 Jun 2025 16:03:15 +0800 Subject: [PATCH] modify method of clearing terminal scroll buffer --- debian/changelog | 6 ++++ debian/clear_console.c | 64 ++++-------------------------------------- 2 files changed, 12 insertions(+), 58 deletions(-) diff --git a/debian/changelog b/debian/changelog index 93bff40..5ddef43 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +bash (5.2.21-2.1deepin1) unstable; urgency=medium + + * modify method of clearing terminal scroll buffer + + -- luojiahao Thu, 19 Jun 2025 15:19:12 +0800 + bash (5.2.21-2.1) unstable; urgency=medium * Non-maintainer upload. diff --git a/debian/clear_console.c b/debian/clear_console.c index 4cd3f26..3f87df1 100644 --- a/debian/clear_console.c +++ b/debian/clear_console.c @@ -165,75 +165,24 @@ int is_pseudo_tty(int fd) return 0; } -int clear_console(int fd) +int clear_console() { - int num, tmp_num; -#if defined(__linux__) - struct vt_stat vtstat; -#endif - /* Linux console secure erase (since 2.6.39), this is sufficient there; other terminals silently ignore this code. If they don't and write junk instead, well, we're clearing the screen anyway. */ write(1, "\e[3J", 4); - /* clear screen */ - setupterm((char *) 0, 1, (int *) 0); - if (tputs(clear_screen, lines > 0 ? lines : 1, putch) == ERR) - { - exit(1); - } - if (is_pseudo_tty(STDIN_FILENO)) return 0; if (!strcmp(getenv("TERM"), "screen")) return 0; - /* get current vt */ -#if defined(__linux__) - if (ioctl(fd, VT_GETSTATE, &vtstat) < 0) -#elif defined(__FreeBSD_kernel__) - if (ioctl(fd, VT_ACTIVATE, &num) < 0) -#endif - { - if (!quiet) - fprintf(stderr, "%s: cannot get VTstate\n", progname); - exit(1); - } -#if defined(__linux__) - num = vtstat.v_active; -#endif - tmp_num = (num == 6 ? 5 : 6); - - /* switch vt to clear the scrollback buffer */ - if (ioctl(fd, VT_ACTIVATE, tmp_num)) - { - if (!quiet) - perror("chvt: VT_ACTIVATE"); - exit(1); - } - - if (ioctl(fd, VT_WAITACTIVE, tmp_num)) - { - if (!quiet) - perror("VT_WAITACTIVE"); - exit(1); - } - - /* switch back */ - if (ioctl(fd, VT_ACTIVATE, num)) - { - if (!quiet) - perror("chvt: VT_ACTIVATE"); - exit(1); - } - - if (ioctl(fd, VT_WAITACTIVE, num)) + /* clear screen */ + setupterm((char *) 0, 1, (int *) 0); + if (tputs(clear_screen, lines > 0 ? lines : 1, putch) == ERR) { - if (!quiet) - perror("VT_WAITACTIVE"); exit(1); } return 0; @@ -241,7 +190,6 @@ int clear_console(int fd) int main (int argc, char* argv[]) { - int fd; int result; /* option handling */ int an_option; @@ -278,14 +226,14 @@ int main (int argc, char* argv[]) exit(1); } - if ((fd = get_console_fd(NULL)) == -1) + if ((get_console_fd(NULL)) == -1) { if (!quiet) fprintf(stderr, "%s: terminal is not a console\n", progname); exit(1); } - clear_console(fd); + clear_console(); return 0; }