NeoMutt  2018-07-16 +952-a2da0a
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 <string.h>
#include "mutt/mutt.h"
#include "mutt_curses.h"
#include <term.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

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

56 {
57  const char *known[] = {
58  "color-xterm", "cygwin", "eterm", "kterm", "nxterm",
59  "putty", "rxvt", "screen", "xterm", NULL,
60  };
61 
62  /* If tsl is set, then terminfo says that status lines work. */
63  char *tcaps = tigetstr("tsl");
64  if (tcaps && tcaps != (char *) -1 && *tcaps)
65  {
66  /* update the static definitions of tsl/fsl from terminfo */
67  tsl = tcaps;
68 
69  tcaps = tigetstr("fsl");
70  if (tcaps && (tcaps != (char *) -1) && *tcaps)
71  fsl = tcaps;
72 
73  return true;
74  }
75 
76 #ifdef HAVE_USE_EXTENDED_NAMES
77  /* If XT (boolean) is set, then this terminal supports the standard escape. */
78  /* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
79  use_extended_names(true);
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_str_startswith(term, *termp, CASE_IGNORE))
91  return true;
92  }
93 
94  /* not reached */
95  return false;
96 }
static const char * tsl
Definition: terminal.c:46
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:1049
Ignore case when comparing strings.
Definition: string2.h:70
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:166
static const char * fsl
Definition: terminal.c:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

105 {
106  if (!str || (*str == '\0'))
107  return;
108 
109  fprintf(stderr, "%s%s%s", tsl, str, fsl);
110 }
static const char * tsl
Definition: terminal.c:46
static const char * fsl
Definition: terminal.c:47

+ Here is the caller graph for this function:

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

119 {
120  if (!str || (*str == '\0'))
121  return;
122 
123  /* icon setting is not supported in terminfo, so hardcode the escape */
124  fprintf(stderr, "\033]1;%s\007", str);
125 }

+ Here is the caller graph for this function:

Variable Documentation

bool TsSupported

Terminal Setting is supported.

Definition at line 43 of file terminal.c.

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

Definition at line 46 of file terminal.c.

const char* fsl = "\007"
static

Definition at line 47 of file terminal.c.