NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
terminal.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdbool.h>
32#include <stdio.h>
33#include "mutt/lib.h"
34#include "terminal.h"
35#include "mutt_curses.h"
36#ifdef HAVE_NCURSESW_NCURSES_H
37#include <ncursesw/term.h>
38#elif defined(HAVE_NCURSES_NCURSES_H)
39#include <ncurses/term.h>
40#endif
41
43
44/* de facto standard escapes for tsl/fsl */
46static const char *TSL = "\033]0;"; // Escape
48static const char *FSL = "\007"; // Ctrl-G (BEL)
49
57const char *mutt_tigetstr(const char *name)
58{
59 char *cap = tigetstr(name);
60 if (!cap || (cap == (char *) -1) || (*cap == '\0'))
61 return NULL;
62
63 return cap;
64}
65
73{
74 static const char *known[] = {
75 "color-xterm", "cygwin", "eterm", "kterm", "nxterm",
76 "putty", "rxvt", "screen", "xterm", NULL,
77 };
78
79#ifdef HAVE_USE_EXTENDED_NAMES
80 /* If tsl is set, then terminfo says that status lines work. */
81 const char *tcaps = mutt_tigetstr("tsl");
82 if (tcaps)
83 {
84 /* update the static definitions of tsl/fsl from terminfo */
85 TSL = tcaps;
86
87 tcaps = mutt_tigetstr("fsl");
88 if (tcaps)
89 FSL = tcaps;
90
91 return true;
92 }
93
94 /* If XT (boolean) is set, then this terminal supports the standard escape. */
95 /* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
96 int tcapi = tigetflag("XT");
97 if (tcapi == 1)
98 return true;
99#endif
100
101 /* Check term types that are known to support the standard escape without
102 * necessarily asserting it in terminfo. */
103 const char *term = mutt_str_getenv("TERM");
104 for (const char **termp = known; *termp; termp++)
105 {
106 if (term && !mutt_istr_startswith(term, *termp))
107 return true;
108 }
109
110 return false;
111}
112
119void mutt_ts_status(char *str)
120{
121 if (!str || (*str == '\0'))
122 return;
123
124 fprintf(stderr, "%s%s%s", TSL, str, FSL);
125}
126
133void mutt_ts_icon(char *str)
134{
135 if (!str || (*str == '\0'))
136 return;
137
138 /* icon setting is not supported in terminfo, so hardcode the escape */
139 fprintf(stderr, "\033]1;%s\007", str); // Escape
140}
Convenience wrapper for the library headers.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:726
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:242
Define wrapper functions around Curses.
bool TsSupported
Terminal Setting is supported.
Definition: terminal.c:42
static const char * FSL
FSL: from_status_line - Sent after the terminal title.
Definition: terminal.c:48
static const char * TSL
TSL: to_status_line - Sent before the terminal title.
Definition: terminal.c:46
const char * mutt_tigetstr(const char *name)
Get terminal capabilities.
Definition: terminal.c:57
void mutt_ts_icon(char *str)
Set the icon in the terminal title bar.
Definition: terminal.c:133
bool mutt_ts_capability(void)
Check terminal capabilities.
Definition: terminal.c:72
void mutt_ts_status(char *str)
Set the text of the terminal title bar.
Definition: terminal.c:119
Set the terminal title/icon.