NeoMutt  2024-02-01-35-geee02f
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
57{
58 static const char *known[] = {
59 "color-xterm", "cygwin", "eterm", "kterm", "nxterm",
60 "putty", "rxvt", "screen", "xterm", NULL,
61 };
62
63#ifdef HAVE_USE_EXTENDED_NAMES
64 /* If tsl is set, then terminfo says that status lines work. */
65 char *tcaps = tigetstr("tsl");
66 if (tcaps && (tcaps != (char *) -1) && *tcaps)
67 {
68 /* update the static definitions of tsl/fsl from terminfo */
69 TSL = tcaps;
70
71 tcaps = tigetstr("fsl");
72 if (tcaps && (tcaps != (char *) -1) && *tcaps)
73 FSL = tcaps;
74
75 return true;
76 }
77
78 /* If XT (boolean) is set, then this terminal supports the standard escape. */
79 /* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
80 int tcapi = tigetflag("XT");
81 if (tcapi == 1)
82 return true;
83#endif
84
85 /* Check term types that are known to support the standard escape without
86 * necessarily asserting it in terminfo. */
87 const char *term = mutt_str_getenv("TERM");
88 for (const char **termp = known; termp; termp++)
89 {
90 if (term && *termp && !mutt_istr_startswith(term, *termp))
91 return true;
92 }
93
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:775
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
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:56
void mutt_ts_status(char *str)
Set the text of the terminal title bar.
Definition: terminal.c:103
Set the terminal title/icon.