NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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>
39#endif
40
42
43/* de facto standard escapes for tsl/fsl */
45static const char *TSL = "\033]0;"; // Escape
47static const char *FSL = "\007"; // Ctrl-G (BEL)
48
56{
57 const char *known[] = {
58 "color-xterm", "cygwin", "eterm", "kterm", "nxterm",
59 "putty", "rxvt", "screen", "xterm", NULL,
60 };
61
62#ifdef HAVE_USE_EXTENDED_NAMES
63 /* If tsl is set, then terminfo says that status lines work. */
64 char *tcaps = tigetstr("tsl");
65 if (tcaps && (tcaps != (char *) -1) && *tcaps)
66 {
67 /* update the static definitions of tsl/fsl from terminfo */
68 TSL = tcaps;
69
70 tcaps = tigetstr("fsl");
71 if (tcaps && (tcaps != (char *) -1) && *tcaps)
72 FSL = tcaps;
73
74 return true;
75 }
76
77 /* If XT (boolean) is set, then this terminal supports the standard escape. */
78 /* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
79 int tcapi = tigetflag("XT");
80 if (tcapi == 1)
81 return true;
82#endif
83
84 /* Check term types that are known to support the standard escape without
85 * necessarily asserting it in terminfo. */
86 const char *term = mutt_str_getenv("TERM");
87 for (const char **termp = known; termp; termp++)
88 {
89 if (term && *termp && !mutt_istr_startswith(term, *termp))
90 return true;
91 }
92
93 /* not reached */
94 return false;
95}
96
103void mutt_ts_status(char *str)
104{
105 if (!str || (*str == '\0'))
106 return;
107
108 fprintf(stderr, "%s%s%s", TSL, str, FSL);
109}
110
117void mutt_ts_icon(char *str)
118{
119 if (!str || (*str == '\0'))
120 return;
121
122 /* icon setting is not supported in terminfo, so hardcode the escape */
123 fprintf(stderr, "\033]1;%s\007", str); // Escape
124}
Convenience wrapper for the library headers.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:918
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:240
Define wrapper functions around Curses.
bool TsSupported
Terminal Setting is supported.
Definition: terminal.c:41
static const char * FSL
FSL: from_status_line - Sent after the terminal title.
Definition: terminal.c:47
static const char * TSL
TSL: to_status_line - Sent before the terminal title.
Definition: terminal.c:45
void mutt_ts_icon(char *str)
Set the icon in the terminal title bar.
Definition: terminal.c:117
bool mutt_ts_capability(void)
Check terminal capabilities.
Definition: terminal.c:55
void mutt_ts_status(char *str)
Set the text of the terminal title bar.
Definition: terminal.c:103
Set the terminal title/icon.