From 0aafd011c0adc58ddf43783764b96fdd74578243 Mon Sep 17 00:00:00 2001 From: dequis Date: Fri, 23 Jun 2017 21:53:16 -0300 Subject: Add a startup warning if the TERM var is wrong inside tmux/screen One of the most common and confusing issues we get in #irssi, this should help identifying and mitigating it. --- src/fe-text/irssi.c | 2 ++ src/fe-text/term-terminfo.c | 28 ++++++++++++++++++++++++++++ src/fe-text/term.h | 2 ++ 3 files changed, 32 insertions(+) (limited to 'src/fe-text') diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c index ef443670..0288e4f1 100644 --- a/src/fe-text/irssi.c +++ b/src/fe-text/irssi.c @@ -207,6 +207,8 @@ static void textui_finish_init(void) fe_settings_set_print("nick"); if (user_settings_changed & USER_SETTINGS_HOSTNAME) fe_settings_set_print("hostname"); + + term_environment_check(); } static void textui_deinit(void) diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c index 6645cfb0..d96e235d 100644 --- a/src/fe-text/term-terminfo.c +++ b/src/fe-text/term-terminfo.c @@ -733,3 +733,31 @@ void term_gets(GArray *buffer, int *line_count) } } } + +static const char* term_env_warning = + "The TERM environment variable is set to '%s' which can cause display " + "glitches when running under %s.\n" + "Consider changing TERM to 'screen' or 'screen-256color' instead."; + +void term_environment_check(void) +{ + const char *term, *sty, *tmux, *multiplexer; + + term = g_getenv("TERM"); + sty = g_getenv("STY"); + tmux = g_getenv("TMUX"); + + multiplexer = (sty && *sty) ? "screen" : + (tmux && *tmux) ? "tmux" : NULL; + + if (!multiplexer) { + return; + } + + if (term && (g_str_has_prefix(term, "screen") || + g_str_has_prefix(term, "tmux"))) { + return; + } + + g_warning(term_env_warning, term, multiplexer); +} diff --git a/src/fe-text/term.h b/src/fe-text/term.h index 0c7847f6..4b1e2874 100644 --- a/src/fe-text/term.h +++ b/src/fe-text/term.h @@ -105,4 +105,6 @@ void term_gets(GArray *buffer, int *line_count); void term_common_init(void); void term_common_deinit(void); +void term_environment_check(void); + #endif -- cgit v1.2.3 From 0d5e353ef1be253106ed66417b270d03b2b91ed3 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Sun, 7 Jan 2018 11:43:13 +0100 Subject: Reword warning message Include multiplexer name in TERM recommendation --- src/fe-text/term-terminfo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/fe-text') diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c index d96e235d..f4c4d17c 100644 --- a/src/fe-text/term-terminfo.c +++ b/src/fe-text/term-terminfo.c @@ -735,9 +735,9 @@ void term_gets(GArray *buffer, int *line_count) } static const char* term_env_warning = - "The TERM environment variable is set to '%s' which can cause display " - "glitches when running under %s.\n" - "Consider changing TERM to 'screen' or 'screen-256color' instead."; + "You seem to be running Irssi inside %2$s, but the TERM environment variable" + "is set to '%1$s', which can cause display glitches.\n" + "Consider changing TERM to '%2$s' or '%2$s-256color' instead."; void term_environment_check(void) { -- cgit v1.2.3 From 063c85da6c4e73a292525aa01b5cad70ed6bf82b Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Sun, 7 Jan 2018 20:01:00 +0100 Subject: Fix space in message --- src/fe-text/term-terminfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/fe-text') diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c index f4c4d17c..ba8bdcaf 100644 --- a/src/fe-text/term-terminfo.c +++ b/src/fe-text/term-terminfo.c @@ -735,7 +735,7 @@ void term_gets(GArray *buffer, int *line_count) } static const char* term_env_warning = - "You seem to be running Irssi inside %2$s, but the TERM environment variable" + "You seem to be running Irssi inside %2$s, but the TERM environment variable " "is set to '%1$s', which can cause display glitches.\n" "Consider changing TERM to '%2$s' or '%2$s-256color' instead."; -- cgit v1.2.3