NeoMutt  2025-09-05-7-geaa2bd
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 <term.h>
+ Include dependency graph for terminal.c:

Go to the source code of this file.

Functions

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

Variables

bool TsSupported
 Terminal Setting is supported.
 
static const char * TSL = "\033]0;"
 TSL: to_status_line - Sent before the terminal title.
 
static const char * FSL = "\007"
 FSL: from_status_line - Sent after the terminal title.
 

Detailed Description

Set the terminal title/icon.

Authors
  • Richard Russon
  • Pietro Cerutti

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_tigetstr()

const char * mutt_tigetstr ( const char *  name)

Get terminal capabilities.

Parameters
nameName of capability
Return values
strCapability
Note
Do not free the returned string

Definition at line 68 of file terminal.c.

69{
70 char *cap = tigetstr(name);
71 if (!cap || (cap == (char *) -1) || (*cap == '\0'))
72 return NULL;
73
74 return cap;
75}
+ Here is the caller graph for this function:

◆ 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 83 of file terminal.c.

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}
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
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
+ 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 130 of file terminal.c.

131{
132 if (!str || (*str == '\0'))
133 return;
134
135 fprintf(stderr, "%s%s%s", TSL, str, FSL);
136}
+ 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 144 of file terminal.c.

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}
+ Here is the caller graph for this function:

Variable Documentation

◆ TsSupported

bool TsSupported

Terminal Setting is supported.

Definition at line 53 of file terminal.c.

◆ TSL

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

TSL: to_status_line - Sent before the terminal title.

Definition at line 57 of file terminal.c.

◆ FSL

const char* FSL = "\007"
static

FSL: from_status_line - Sent after the terminal title.

Definition at line 59 of file terminal.c.