NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
terminal.c
Go to the documentation of this file.
1
23
29
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
53
/* de facto standard escapes for tsl/fsl */
55
static
const
char
*
TSL
=
"\033]0;"
;
// Escape
57
static
const
char
*
FSL
=
"\007"
;
// Ctrl-G (BEL)
58
66
const
char
*
mutt_tigetstr
(
const
char
*name)
67
{
68
char
*cap = tigetstr(name);
69
if
(!cap || (cap == (
char
*) -1) || (*cap ==
'\0'
))
70
return
NULL;
71
72
return
cap;
73
}
74
81
bool
mutt_ts_capability
(
void
)
82
{
83
static
const
char
*known[] = {
84
"color-xterm"
,
"cygwin"
,
"eterm"
,
"kterm"
,
"nxterm"
,
85
"putty"
,
"rxvt"
,
"screen"
,
"xterm"
, NULL,
86
};
87
88
#ifdef HAVE_USE_EXTENDED_NAMES
89
/* If tsl is set, then terminfo says that status lines work. */
90
const
char
*tcaps =
mutt_tigetstr
(
"tsl"
);
91
if
(tcaps)
92
{
93
/* update the static definitions of tsl/fsl from terminfo */
94
TSL
= tcaps;
95
96
tcaps =
mutt_tigetstr
(
"fsl"
);
97
if
(tcaps)
98
FSL
= tcaps;
99
100
return
true
;
101
}
102
103
/* If XT (boolean) is set, then this terminal supports the standard escape. */
104
/* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
105
int
tcapi = tigetflag(
"XT"
);
106
if
(tcapi == 1)
107
return
true
;
108
#endif
109
110
/* Check term types that are known to support the standard escape without
111
* necessarily asserting it in terminfo. */
112
const
char
*term =
mutt_str_getenv
(
"TERM"
);
113
for
(
const
char
**termp = known; *termp; termp++)
114
{
115
if
(term &&
mutt_istr_startswith
(term, *termp))
116
return
true
;
117
}
118
119
return
false
;
120
}
121
128
void
mutt_ts_status
(
char
*str)
129
{
130
if
(!str || (*str ==
'\0'
))
131
return
;
132
133
fprintf(stderr,
"%s%s%s"
,
TSL
, str,
FSL
);
134
}
135
142
void
mutt_ts_icon
(
char
*str)
143
{
144
if
(!str || (*str ==
'\0'
))
145
return
;
146
147
/* icon setting is not supported in terminfo, so hardcode the escape */
148
fprintf(stderr,
"\033]1;%s\007"
, str);
// Escape
149
}
lib.h
Convenience wrapper for the library headers.
mutt_str_getenv
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition
string.c:732
mutt_istr_startswith
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition
string.c:246
mutt_curses.h
Define wrapper functions around Curses.
FSL
static const char * FSL
FSL: from_status_line - Sent after the terminal title.
Definition
terminal.c:57
TSL
static const char * TSL
TSL: to_status_line - Sent before the terminal title.
Definition
terminal.c:55
mutt_tigetstr
const char * mutt_tigetstr(const char *name)
Get terminal capabilities.
Definition
terminal.c:66
mutt_ts_icon
void mutt_ts_icon(char *str)
Set the icon in the terminal title bar.
Definition
terminal.c:142
mutt_ts_capability
bool mutt_ts_capability(void)
Check terminal capabilities.
Definition
terminal.c:81
mutt_ts_status
void mutt_ts_status(char *str)
Set the text of the terminal title bar.
Definition
terminal.c:128
terminal.h
Set the terminal title/icon.