From f5f62ee02dbfc43c18262517f3611ccb91147288 Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Sat, 27 Apr 2024 17:32:45 +0200 Subject: [PATCH] Disable DEC Special Graphics at exit if vt100 If a vt100 terminal receives the Shift In character '\016' it will enable the 7 bit DEC Special Graphics character set used for line drawing. For most users this can happen due to line noise from the tty device and will likely mess up your terminal even after tio exits. To better handle this we want to make sure that tio disables this mode by sending the Shift Out character '\017' at exit. This mechanism will only activate if environment variable TERM assumes value "vt100". --- src/options.c | 8 ++++++++ src/options.h | 1 + src/tty.c | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/src/options.c b/src/options.c index a460ab7..f538f42 100644 --- a/src/options.c +++ b/src/options.c @@ -118,6 +118,7 @@ struct option_t option = .exclude_drivers = NULL, .exclude_tids = NULL, .hex_n_value = 0, + .vt100 = false, }; void print_help(char *argv[]) @@ -487,6 +488,13 @@ void options_parse(int argc, char *argv[]) option.color = -1; } + // Check for vt100 terminal + char *term = getenv("TERM"); + if ((term != NULL) && (!strcmp(term, "vt100"))) + { + option.vt100 = true; + } + while (1) { static struct option long_options[] = diff --git a/src/options.h b/src/options.h index d5a054b..016978d 100644 --- a/src/options.h +++ b/src/options.h @@ -95,6 +95,7 @@ struct option_t const char *exclude_drivers; const char *exclude_tids; int hex_n_value; + bool vt100; }; extern struct option_t option; diff --git a/src/tty.c b/src/tty.c index 6be7581..ccbb44d 100644 --- a/src/tty.c +++ b/src/tty.c @@ -1067,6 +1067,14 @@ void stdin_configure(void) void stdout_restore(void) { tcsetattr(STDOUT_FILENO, TCSANOW, &stdout_old); + + // If terminal is vt100 + if (option.vt100) + { + // Disable DEC Special Graphics character set just in case it was randomly + // enabled by noise from serial device. + putchar('\017'); + } } void stdout_configure(void)