NeoMutt  2025-09-05-7-geaa2bd
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
37/*
38 * The inclusion logic must be kept in sync with that of gui/mutt_curses.h.
39 * We aren't including term.h there because it pollutes the global name space
40 * with a lot of common names that we use in our source code, e.g., `pad_char`,
41 * so we'd like to scope its inclusion to this source file.
42 */
43#ifdef HAVE_NCURSESW_NCURSES_H
44#include <ncursesw/term.h>
45#elif defined(HAVE_NCURSES_NCURSES_H)
46#include <ncurses/term.h>
47#elif defined(HAVE_NCURSES_H)
48#include <term.h>
49#else
50#include <term.h>
51#endif
52
54
55/* de facto standard escapes for tsl/fsl */
57static const char *TSL = "\033]0;"; // Escape
59static const char *FSL = "\007"; // Ctrl-G (BEL)
60
68const char *mutt_tigetstr(const char *name)
69{
70 char *cap = tigetstr(name);
71 if (!cap || (cap == (char *) -1) || (*cap == '\0'))
72 return NULL;
73
74 return cap;
75}
76
84{
85 static const char *known[] = {
86 "color-xterm", "cygwin", "eterm", "kterm", "nxterm",
87 "putty", "rxvt", "screen", "xterm", NULL,
88 };
89
90#ifdef HAVE_USE_EXTENDED_NAMES
91 /* If tsl is set, then terminfo says that status lines work. */
92 const char *tcaps = mutt_tigetstr("tsl");
93 if (tcaps)
94 {
95 /* update the static definitions of tsl/fsl from terminfo */
96 TSL = tcaps;
97
98 tcaps = mutt_tigetstr("fsl");
99 if (tcaps)
100 FSL = tcaps;
101
102 return true;
103 }
104
105 /* If XT (boolean) is set, then this terminal supports the standard escape. */
106 /* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
107 int tcapi = tigetflag("XT");
108 if (tcapi == 1)
109 return true;
110#endif
111
112 /* Check term types that are known to support the standard escape without
113 * necessarily asserting it in terminfo. */
114 const char *term = mutt_str_getenv("TERM");
115 for (const char **termp = known; *termp; termp++)
116 {
117 if (term && !mutt_istr_startswith(term, *termp))
118 return true;
119 }
120
121 return false;
122}
123
130void mutt_ts_status(char *str)
131{
132 if (!str || (*str == '\0'))
133 return;
134
135 fprintf(stderr, "%s%s%s", TSL, str, FSL);
136}
137
144void mutt_ts_icon(char *str)
145{
146 if (!str || (*str == '\0'))
147 return;
148
149 /* icon setting is not supported in terminfo, so hardcode the escape */
150 fprintf(stderr, "\033]1;%s\007", str); // Escape
151}
Convenience wrapper for the library headers.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:725
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:243
Define wrapper functions around Curses.
bool TsSupported
Terminal Setting is supported.
Definition: terminal.c:53
static const char * FSL
FSL: from_status_line - Sent after the terminal title.
Definition: terminal.c:59
static const char * TSL
TSL: to_status_line - Sent before the terminal title.
Definition: terminal.c:57
const char * mutt_tigetstr(const char *name)
Get terminal capabilities.
Definition: terminal.c:68
void mutt_ts_icon(char *str)
Set the icon in the terminal title bar.
Definition: terminal.c:144
bool mutt_ts_capability(void)
Check terminal capabilities.
Definition: terminal.c:83
void mutt_ts_status(char *str)
Set the text of the terminal title bar.
Definition: terminal.c:130
Set the terminal title/icon.