NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
terminal.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include <stdio.h>
32#include "mutt/lib.h"
33#include "terminal.h"
34#include "mutt_curses.h"
35#ifdef HAVE_NCURSESW_NCURSES_H
36#include <ncursesw/term.h> // IWYU pragma: keep
37#elif defined(HAVE_NCURSES_NCURSES_H)
38#include <ncurses/term.h> // IWYU pragma: keep
39#endif
40
42
43/* de facto standard escapes for tsl/fsl */
44static const char *tsl = "\033]0;"; // Escape
45static const char *fsl = "\007"; // Ctrl-G (BEL)
46
54{
55 const char *known[] = {
56 "color-xterm", "cygwin", "eterm", "kterm", "nxterm",
57 "putty", "rxvt", "screen", "xterm", NULL,
58 };
59
60#ifdef HAVE_USE_EXTENDED_NAMES
61 /* If tsl is set, then terminfo says that status lines work. */
62 char *tcaps = tigetstr("tsl");
63 if (tcaps && (tcaps != (char *) -1) && *tcaps)
64 {
65 /* update the static definitions of tsl/fsl from terminfo */
66 tsl = tcaps;
67
68 tcaps = tigetstr("fsl");
69 if (tcaps && (tcaps != (char *) -1) && *tcaps)
70 fsl = tcaps;
71
72 return true;
73 }
74
75 /* If XT (boolean) is set, then this terminal supports the standard escape. */
76 /* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
77 int tcapi = tigetflag("XT");
78 if (tcapi == 1)
79 return true;
80#endif
81
82 /* Check term types that are known to support the standard escape without
83 * necessarily asserting it in terminfo. */
84 const char *term = mutt_str_getenv("TERM");
85 for (const char **termp = known; termp; termp++)
86 {
87 if (term && *termp && !mutt_istr_startswith(term, *termp))
88 return true;
89 }
90
91 /* not reached */
92 return false;
93}
94
101void mutt_ts_status(char *str)
102{
103 if (!str || (*str == '\0'))
104 return;
105
106 fprintf(stderr, "%s%s%s", tsl, str, fsl);
107}
108
115void mutt_ts_icon(char *str)
116{
117 if (!str || (*str == '\0'))
118 return;
119
120 /* icon setting is not supported in terminfo, so hardcode the escape */
121 fprintf(stderr, "\033]1;%s\007", str); // Escape
122}
Convenience wrapper for the library headers.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:927
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:239
Define wrapper functions around Curses.
bool TsSupported
Terminal Setting is supported.
Definition: terminal.c:41
static const char * fsl
Definition: terminal.c:45
static const char * tsl
Definition: terminal.c:44
void mutt_ts_icon(char *str)
Set the icon in the terminal title bar.
Definition: terminal.c:115
bool mutt_ts_capability(void)
Check terminal capabilities.
Definition: terminal.c:53
void mutt_ts_status(char *str)
Set the text of the terminal title bar.
Definition: terminal.c:101
Set the terminal title/icon.