NeoMutt  2019-12-07-168-gc45f47
Teaching an old dog new tricks
DOXYGEN
terminal.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stdbool.h>
31 #include <stdio.h>
32 #include "mutt/lib.h"
33 #include "terminal.h"
34 #include "mutt_curses.h"
35 #ifdef HAVE_NCURSESW_NCURSES_H
36 #include <ncursesw/term.h> // IWYU pragma: keep
37 #elif defined(HAVE_NCURSES_NCURSES_H)
38 #include <ncurses/term.h> // IWYU pragma: keep
39 #elif !defined(USE_SLANG_CURSES)
40 #include <term.h>
41 #endif
42 
44 
45 /* de facto standard escapes for tsl/fsl */
46 static const char *tsl = "\033]0;"; // Escape
47 static const char *fsl = "\007"; // Ctrl-G (BEL)
48 
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 }
97 
104 void mutt_ts_status(char *str)
105 {
106  if (!str || (*str == '\0'))
107  return;
108 
109  fprintf(stderr, "%s%s%s", tsl, str, fsl);
110 }
111 
118 void mutt_ts_icon(char *str)
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); // Escape
125 }
static const char * tsl
Definition: terminal.c:46
Define wrapper functions around Curses/Slang.
bool mutt_ts_capability(void)
Check terminal capabilities.
Definition: terminal.c:55
Set the terminal title/icon.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:1071
Ignore case when comparing strings.
Definition: string2.h:68
bool TsSupported
Terminal Setting is supported.
Definition: terminal.c:43
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:168
static const char * fsl
Definition: terminal.c:47
void mutt_ts_icon(char *str)
Set the icon in the terminal title bar.
Definition: terminal.c:118
void mutt_ts_status(char *str)
Set the text of the terminal title bar.
Definition: terminal.c:104
Convenience wrapper for the library headers.