]> granicus.if.org Git - neomutt/commitdiff
split out terminal setting
authorRichard Russon <rich@flatcap.org>
Sun, 1 Apr 2018 02:33:43 +0000 (03:33 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 1 Apr 2018 02:33:43 +0000 (03:33 +0100)
Makefile.autosetup
curs_main.c
globals.h
main.c
mutt_menu.h
pager.c
terminal.c [new file with mode: 0644]
terminal.h [new file with mode: 0644]

index 4b2787eceb6c26ef23639ff9a26d993d4d548eed..a49de85af34d69f1100702abd699699f949f432c 100644 (file)
@@ -70,7 +70,7 @@ NEOMUTTOBJS=  addrbook.o alias.o attach.o bcache.o body.o browser.o buffy.o \
                postpone.o query.o recvattach.o recvcmd.o resize.o rfc1524.o \
                rfc2047.o rfc2231.o rfc3676.o safe_asprintf.o score.o send.o \
                sendlib.o sidebar.o smtp.o sort.o state.o status.o system.o \
-               tags.o thread.o url.o version.o
+               tags.o terminal.o thread.o url.o version.o
 
 @if !HAVE_WCSCASECMP
 NEOMUTTOBJS+=  wcscasecmp.o
index 56a64238a86d45da4b9166f21188ec581076147f..77f115c1abc1f51d75a1d52cf9eb96459b5eb081 100644 (file)
 #include "protos.h"
 #include "sort.h"
 #include "tags.h"
+#include "terminal.h"
 #include "thread.h"
-#ifdef HAVE_NCURSESW_NCURSES_H
-#include <ncursesw/term.h>
-#elif defined(HAVE_NCURSES_NCURSES_H)
-#include <ncurses/term.h>
-#elif !defined(USE_SLANG_CURSES)
-#include <term.h>
-#endif
 #ifdef USE_SIDEBAR
 #include "sidebar.h"
 #endif
@@ -145,10 +139,6 @@ static const char *NoVisible = N_("No visible messages.");
 #define CAN_COLLAPSE(header)                                                   \
   ((CollapseUnread || !UNREAD(header)) && (CollapseFlagged || !FLAGGED(header)))
 
-/* de facto standard escapes for tsl/fsl */
-static char *tsl = "\033]0;";
-static char *fsl = "\007";
-
 /**
  * collapse/uncollapse all threads
  * @param menu   current menu
@@ -518,77 +508,6 @@ static int main_change_folder(struct Menu *menu, int op, char *buf,
   return 0;
 }
 
-/**
- * mutt_ts_capability - Check terminal capabilities
- *
- * terminal status capability check. terminfo must have been initialized.
- */
-bool mutt_ts_capability(void)
-{
-  const char *term = mutt_str_getenv("TERM");
-  char *tcaps = NULL;
-#ifdef HAVE_USE_EXTENDED_NAMES
-  int tcapi;
-#endif
-  char **termp = NULL;
-  char *known[] = {
-    "color-xterm", "cygwin", "eterm",  "kterm", "nxterm",
-    "putty",       "rxvt",   "screen", "xterm", NULL,
-  };
-
-  /* If tsl is set, then terminfo says that status lines work. */
-  tcaps = tigetstr("tsl");
-  if (tcaps && tcaps != (char *) -1 && *tcaps)
-  {
-    /* update the static defns of tsl/fsl from terminfo */
-    tsl = tcaps;
-
-    tcaps = tigetstr("fsl");
-    if (tcaps && tcaps != (char *) -1 && *tcaps)
-      fsl = tcaps;
-
-    return true;
-  }
-
-/* If XT (boolean) is set, then this terminal supports the standard escape. */
-/* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
-#ifdef HAVE_USE_EXTENDED_NAMES
-  use_extended_names(true);
-  tcapi = tigetflag("XT");
-  if (tcapi == 1)
-    return true;
-#endif /* HAVE_USE_EXTENDED_NAMES */
-
-  /* Check term types that are known to support the standard escape without
-   * necessarily asserting it in terminfo. */
-  for (termp = known; termp; termp++)
-  {
-    if (term && *termp && (mutt_str_strncasecmp(term, *termp, strlen(*termp)) != 0))
-      return true;
-  }
-
-  /* not supported */
-  return false;
-}
-
-void mutt_ts_status(char *str)
-{
-  /* If empty, do not set.  To clear, use a single space. */
-  if (str == NULL || *str == '\0')
-    return;
-  fprintf(stderr, "%s%s%s", tsl, str, fsl);
-}
-
-void mutt_ts_icon(char *str)
-{
-  /* If empty, do not set.  To clear, use a single space. */
-  if (str == NULL || *str == '\0')
-    return;
-
-  /* icon setting is not supported in terminfo, so hardcode the escape - yuck */
-  fprintf(stderr, "\033]1;%s\007", str);
-}
-
 /**
  * index_make_entry - Format a menu item for the index list
  * @param[out] buf    Buffer in which to save string
@@ -883,7 +802,7 @@ static void index_menu_redraw(struct Menu *menu)
     mutt_draw_statusline(MuttStatusWindow->cols, buf, sizeof(buf));
     NORMAL_COLOR;
     menu->redraw &= ~REDRAW_STATUS;
-    if (TsEnabled && TSSupported)
+    if (TsEnabled && TsSupported)
     {
       menu_status_line(buf, sizeof(buf), menu, NONULL(TSStatusFormat));
       mutt_ts_status(buf);
index 293bc8764e82bde542586a01d25a4798a3fa17a4..941d8f4d4dc96d6ab27b490cbd3d375de44a80a3 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -46,7 +46,6 @@ WHERE char *ShortHostname;
 
 WHERE struct ListHead Muttrc INITVAL(STAILQ_HEAD_INITIALIZER(Muttrc));
 
-WHERE short TSSupported;
 WHERE char *Username;
 
 WHERE char *CurrentFolder;
diff --git a/main.c b/main.c
index c33a8679662abf0ad6fce9ebfd4203e7a3df59de..83b0cab0a4234aa1f79948546498f1afad739053 100644 (file)
--- a/main.c
+++ b/main.c
@@ -53,6 +53,7 @@
 #include "ncrypt/ncrypt.h"
 #include "options.h"
 #include "protos.h"
+#include "terminal.h"
 #include "url.h"
 #include "version.h"
 #ifdef ENABLE_NLS
@@ -524,7 +525,7 @@ int main(int argc, char *argv[], char *envp[])
       goto main_curses; // TEST08: can't test -- fake term?
 
     /* check whether terminal status is supported (must follow curses init) */
-    TSSupported = mutt_ts_capability();
+    TsSupported = mutt_ts_capability();
   }
 
   /* set defaults and read init files */
index a83a1bd83f73fd90b10787520e21f308a113a9f5..fa72d49bb056b39d741ec9263dcda1def2e1b205 100644 (file)
@@ -119,9 +119,6 @@ void menu_redraw_sidebar(struct Menu *menu);
 #endif
 void menu_redraw_status(struct Menu *menu);
 void menu_status_line(char *buf, size_t buflen, struct Menu *menu, const char *p);
-bool mutt_ts_capability(void);
-void mutt_ts_status(char *str);
-void mutt_ts_icon(char *str);
 void menu_top_page(struct Menu *menu);
 
 void         mutt_menu_current_redraw(void);
diff --git a/pager.c b/pager.c
index 531fae58ae814270d76ff362f6438c4f5a716f4e..e819dec97a5fcf5f0043e298aa26092aa83bc425 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -53,6 +53,7 @@
 #include "options.h"
 #include "protos.h"
 #include "sort.h"
+#include "terminal.h"
 #ifdef USE_SIDEBAR
 #include "sidebar.h"
 #endif
@@ -2017,7 +2018,7 @@ static void pager_menu_redraw(struct Menu *pager_menu)
       mutt_draw_statusline(rd->pager_status_window->cols, bn, sizeof(bn));
     }
     NORMAL_COLOR;
-    if (TsEnabled && TSSupported && rd->index)
+    if (TsEnabled && TsSupported && rd->index)
     {
       menu_status_line(buffer, sizeof(buffer), rd->index, NONULL(TSStatusFormat));
       mutt_ts_status(buffer);
diff --git a/terminal.c b/terminal.c
new file mode 100644 (file)
index 0000000..7e18d51
--- /dev/null
@@ -0,0 +1,119 @@
+/**
+ * @file
+ * Set the terminal title/icon
+ *
+ * @authors
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * 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/>.
+ */
+
+#include "config.h"
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include "mutt/mutt.h"
+#include "mutt_curses.h"
+#ifdef HAVE_NCURSESW_NCURSES_H
+#include <ncursesw/term.h>
+#elif defined(HAVE_NCURSES_NCURSES_H)
+#include <ncurses/term.h>
+#elif !defined(USE_SLANG_CURSES)
+#include <term.h>
+#endif
+
+bool TsSupported; /**< Terminal Setting is supported */
+
+/* de facto standard escapes for tsl/fsl */
+static char *tsl = "\033]0;";
+static char *fsl = "\007";
+
+/**
+ * mutt_ts_capability - Check terminal capabilities
+ * @retval true Terminal is capable of having its title/icon set
+ *
+ * @note This must happen after the terminfo has been initialised.
+ */
+bool mutt_ts_capability(void)
+{
+  char *known[] = {
+    "color-xterm", "cygwin", "eterm",  "kterm", "nxterm",
+    "putty",       "rxvt",   "screen", "xterm", NULL,
+  };
+
+  /* If tsl is set, then terminfo says that status lines work. */
+  char *tcaps = tigetstr("tsl");
+  if (tcaps && tcaps != (char *) -1 && *tcaps)
+  {
+    /* update the static definitiions of tsl/fsl from terminfo */
+    tsl = tcaps;
+
+    tcaps = tigetstr("fsl");
+    if (tcaps && (tcaps != (char *) -1) && *tcaps)
+      fsl = tcaps;
+
+    return true;
+  }
+
+#ifdef HAVE_USE_EXTENDED_NAMES
+  /* If XT (boolean) is set, then this terminal supports the standard escape. */
+  /* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
+  use_extended_names(true);
+  int tcapi = tigetflag("XT");
+  if (tcapi == 1)
+    return true;
+#endif
+
+  /* Check term types that are known to support the standard escape without
+   * necessarily asserting it in terminfo. */
+  const char *term = mutt_str_getenv("TERM");
+  for (char **termp = known; termp; termp++)
+  {
+    if (term && *termp && (mutt_str_strncasecmp(term, *termp, strlen(*termp)) != 0))
+      return true;
+  }
+
+  /* not supported */
+  return false;
+}
+
+/**
+ * mutt_ts_status - Set the text of the terminal title bar
+ * @param str Text to set
+ *
+ * @note To clear the text, set the title to a single space.
+ */
+void mutt_ts_status(char *str)
+{
+  if (!str || (*str == '\0'))
+    return;
+
+  fprintf(stderr, "%s%s%s", tsl, str, fsl);
+}
+
+/**
+ * mutt_ts_icon - Set the icon in the terminal title bar
+ * @param str Icon string
+ *
+ * @note To clear the icon, set it to a single space.
+ */
+void mutt_ts_icon(char *str)
+{
+  if (!str || (*str == '\0'))
+    return;
+
+  /* icon setting is not supported in terminfo, so hardcode the escape */
+  fprintf(stderr, "\033]1;%s\007", str);
+}
diff --git a/terminal.h b/terminal.h
new file mode 100644 (file)
index 0000000..7b9b583
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * @file
+ * Set the terminal title/icon
+ *
+ * @authors
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * 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/>.
+ */
+
+#ifndef _MUTT_TERMINAL_H
+#define _MUTT_TERMINAL_H
+
+#include <stdbool.h>
+
+extern bool TsSupported;
+
+bool mutt_ts_capability(void);
+void mutt_ts_status(char *str);
+void mutt_ts_icon(char *str);
+
+#endif /* _MUTT_TERMINAL_H */