NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
terminal.c File Reference

Set the terminal title/icon. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "terminal.h"
#include "mutt_curses.h"
+ Include dependency graph for terminal.c:

Go to the source code of this file.

Functions

bool mutt_ts_capability (void)
 Check terminal capabilities. More...
 
void mutt_ts_status (char *str)
 Set the text of the terminal title bar. More...
 
void mutt_ts_icon (char *str)
 Set the icon in the terminal title bar. More...
 

Variables

bool TsSupported
 Terminal Setting is supported. More...
 
static const char * tsl = "\033]0;"
 
static const char * fsl = "\007"
 

Detailed Description

Set the terminal title/icon.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file terminal.c.

Function Documentation

◆ mutt_ts_capability()

bool mutt_ts_capability ( void  )

Check terminal capabilities.

Return values
trueTerminal is capable of having its title/icon set
Note
This must happen after the terminfo has been initialised.

Definition at line 53 of file terminal.c.

54{
55 const char *known[] = {
56 "color-xterm", "cygwin", "eterm", "kterm", "nxterm",
57 "putty", "rxvt", "screen", "xterm", NULL,
58 };
59
60#ifdef HAVE_USE_EXTENDED_NAMES
61 /* If tsl is set, then terminfo says that status lines work. */
62 char *tcaps = tigetstr("tsl");
63 if (tcaps && (tcaps != (char *) -1) && *tcaps)
64 {
65 /* update the static definitions of tsl/fsl from terminfo */
66 tsl = tcaps;
67
68 tcaps = tigetstr("fsl");
69 if (tcaps && (tcaps != (char *) -1) && *tcaps)
70 fsl = tcaps;
71
72 return true;
73 }
74
75 /* If XT (boolean) is set, then this terminal supports the standard escape. */
76 /* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
77 int tcapi = tigetflag("XT");
78 if (tcapi == 1)
79 return true;
80#endif
81
82 /* Check term types that are known to support the standard escape without
83 * necessarily asserting it in terminfo. */
84 const char *term = mutt_str_getenv("TERM");
85 for (const char **termp = known; termp; termp++)
86 {
87 if (term && *termp && !mutt_istr_startswith(term, *termp))
88 return true;
89 }
90
91 /* not reached */
92 return false;
93}
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:927
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:239
static const char * fsl
Definition: terminal.c:45
static const char * tsl
Definition: terminal.c:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_ts_status()

void mutt_ts_status ( char *  str)

Set the text of the terminal title bar.

Parameters
strText to set
Note
To clear the text, set the title to a single space.

Definition at line 101 of file terminal.c.

102{
103 if (!str || (*str == '\0'))
104 return;
105
106 fprintf(stderr, "%s%s%s", tsl, str, fsl);
107}
+ Here is the caller graph for this function:

◆ mutt_ts_icon()

void mutt_ts_icon ( char *  str)

Set the icon in the terminal title bar.

Parameters
strIcon string
Note
To clear the icon, set it to a single space.

Definition at line 115 of file terminal.c.

116{
117 if (!str || (*str == '\0'))
118 return;
119
120 /* icon setting is not supported in terminfo, so hardcode the escape */
121 fprintf(stderr, "\033]1;%s\007", str); // Escape
122}
+ Here is the caller graph for this function:

Variable Documentation

◆ TsSupported

bool TsSupported

Terminal Setting is supported.

Definition at line 41 of file terminal.c.

◆ tsl

const char* tsl = "\033]0;"
static

Definition at line 44 of file terminal.c.

◆ fsl

const char* fsl = "\007"
static

Definition at line 45 of file terminal.c.