]> granicus.if.org Git - neomutt/commitdiff
refactor: curs_set() to mutt_curses_set_cursor()
authorRichard Russon <rich@flatcap.org>
Fri, 27 Sep 2019 13:21:46 +0000 (14:21 +0100)
committerRichard Russon <rich@flatcap.org>
Sat, 28 Sep 2019 02:18:27 +0000 (03:18 +0100)
Encapsulate a curses function to reduce dependencies.

curs_lib.c
index.c
menu.c
mutt_curses.c
mutt_curses.h
mutt_signal.c
pager.c

index 47026e7750a8e2dd1790000f5863e6eab1a70cbf..f9db313d0327b484f07c5e47e6010c7ef0a6afd5 100644 (file)
@@ -468,7 +468,7 @@ enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
 void mutt_query_exit(void)
 {
   mutt_flushinp();
-  curs_set(1);
+  mutt_curses_set_cursor(MUTT_CURSOR_VISIBLE);
   if (C_Timeout)
     mutt_getch_timeout(-1); /* restore blocking operation */
   if (mutt_yesorno(_("Exit NeoMutt?"), MUTT_YES) == MUTT_YES)
@@ -476,7 +476,7 @@ void mutt_query_exit(void)
     mutt_exit(1);
   }
   mutt_clear_error();
-  mutt_curs_set(-1);
+  mutt_curses_set_cursor(MUTT_CURSOR_RESTORE_LAST);
   SigInt = 0;
 }
 
@@ -809,31 +809,6 @@ void mutt_flushinp(void)
   flushinp();
 }
 
-#if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
-/**
- * mutt_curs_set - Set the cursor position
- * @param cursor
- * * -1: restore the value of the last call
- * *  0: make the cursor invisible
- * *  1: make the cursor visible
- */
-void mutt_curs_set(int cursor)
-{
-  static int SavedCursor = 1;
-
-  if (cursor < 0)
-    cursor = SavedCursor;
-  else
-    SavedCursor = cursor;
-
-  if (curs_set(cursor) == ERR)
-  {
-    if (cursor == 1) /* cnorm */
-      curs_set(2);   /* cvvis */
-  }
-}
-#endif
-
 /**
  * mutt_multi_choice - Offer the user a multiple choice question
  * @param prompt  Message prompt
diff --git a/index.c b/index.c
index d989d2d8624781fdb4fba88bd854b796e86e1321..9f1fdfee6ca365ee84ba7680d7a29e27cc522478 100644 (file)
--- a/index.c
+++ b/index.c
@@ -1202,7 +1202,7 @@ int mutt_index_menu(void)
     }
 
     if (op >= 0)
-      mutt_curs_set(0);
+      mutt_curses_set_cursor(MUTT_CURSOR_INVISIBLE);
 
     if (menu->type == MENU_MAIN)
     {
@@ -1256,7 +1256,7 @@ int mutt_index_menu(void)
         continue;
       }
 
-      mutt_curs_set(1);
+      mutt_curses_set_cursor(MUTT_CURSOR_VISIBLE);
 
       /* special handling for the tag-prefix function */
       if ((op == OP_TAG_PREFIX) || (op == OP_TAG_PREFIX_COND))
@@ -1304,7 +1304,7 @@ int mutt_index_menu(void)
       else
         menu->oldcurrent = -1;
 
-      mutt_curs_set(1); /* fallback from the pager */
+      mutt_curses_set_cursor(MUTT_CURSOR_VISIBLE); /* fallback from the pager */
     }
 
 #ifdef USE_NNTP
diff --git a/menu.c b/menu.c
index 27fcf5ef7f5f5079274957bb8f968275875825a1..a49467f56b90ec0fc8829757920e600c974c4de7 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -1371,7 +1371,7 @@ int mutt_menu_loop(struct Menu *menu)
     if (menu->tagprefix && (i != OP_TAG_PREFIX) && (i != OP_TAG_PREFIX_COND) && (i != -2))
       menu->tagprefix = false;
 
-    mutt_curs_set(0);
+    mutt_curses_set_cursor(MUTT_CURSOR_INVISIBLE);
 
     if (menu_redraw(menu) == OP_REDRAW)
       return OP_REDRAW;
@@ -1432,7 +1432,7 @@ int mutt_menu_loop(struct Menu *menu)
     else if (menu->tagged && C_AutoTag)
       menu->tagprefix = true;
 
-    mutt_curs_set(1);
+    mutt_curses_set_cursor(MUTT_CURSOR_VISIBLE);
 
     if (SigWinch)
     {
index 68c32f8c6ebcad793f638612eff5abde3fe31fb1..0cfd5b1a390bc5ef1f9743235e6224aec3a5d683 100644 (file)
@@ -59,3 +59,25 @@ void mutt_curses_set_color(enum ColorId color)
     attrset(ColorDefs[MT_COLOR_NORMAL]);
 #endif
 }
+
+/**
+ * mutt_curses_set_cursor - Set the cursor state
+ * @param state State to set, e.g. #MUTT_CURSOR_INVISIBLE
+ */
+void mutt_curses_set_cursor(enum MuttCursorState state)
+{
+#if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
+  static int SavedCursor = MUTT_CURSOR_VISIBLE;
+
+  if (state == MUTT_CURSOR_RESTORE_LAST)
+    state = SavedCursor;
+  else
+    SavedCursor = state;
+
+  if (curs_set(state) == ERR)
+  {
+    if (state == MUTT_CURSOR_VISIBLE)
+      curs_set(MUTT_CURSOR_VERY_VISIBLE);
+  }
+#endif
+}
index 6b9df2d0371eccfa952693f468ed54f3ba7f3dab..5b200baa5864afdb0e28ec2393913d4e1fa1032f 100644 (file)
       beep();                                                                  \
   } while (false)
 
-#if !(defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
-#define curs_set(x)
-#endif
-
-#if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
-void mutt_curs_set(int cursor);
-#else
-#define mutt_curs_set(x)
-#endif
-
 #define ctrl(ch) ((ch) - '@')
 
 #ifdef KEY_ENTER
@@ -102,8 +92,20 @@ void mutt_curs_set(int cursor);
 #define CI_is_return(ch) (((ch) == '\r') || ((ch) == '\n'))
 #endif
 
+/**
+ * enum MuttCursorState - Cursor states for mutt_curses_set_cursor()
+ */
+enum MuttCursorState
+{
+  MUTT_CURSOR_RESTORE_LAST = -1, ///< Restore the previous cursor state
+  MUTT_CURSOR_INVISIBLE    =  0, ///< Hide the cursor
+  MUTT_CURSOR_VISIBLE      =  1, ///< Display a normal cursor
+  MUTT_CURSOR_VERY_VISIBLE =  2, ///< Display a very visible cursor
+};
+
 void mutt_curses_set_attr(int attr);
 void mutt_curses_set_color(enum ColorId color);
+void mutt_curses_set_cursor(enum MuttCursorState state);
 void mutt_resize_screen(void);
 
 #endif /* MUTT_MUTT_CURSES_H */
index fe3ad73c772580373ff90f37b19d5df7f60ddf9f..c1b27b736f9470ce8b2c8f21c66642459ac287e7 100644 (file)
@@ -54,7 +54,7 @@ static void curses_signal_handler(int sig)
       if (!C_Suspend)
         break;
       IsEndwin = isendwin();
-      curs_set(1);
+      mutt_curses_set_cursor(MUTT_CURSOR_VISIBLE);
       if (!IsEndwin)
         endwin();
       kill(0, SIGSTOP);
@@ -63,7 +63,7 @@ static void curses_signal_handler(int sig)
     case SIGCONT:
       if (!IsEndwin)
         refresh();
-      mutt_curs_set(-1);
+      mutt_curses_set_cursor(MUTT_CURSOR_RESTORE_LAST);
       /* We don't receive SIGWINCH when suspended; however, no harm is done by
        * just assuming we received one, and triggering the 'resize' anyway. */
       SigWinch = 1;
@@ -86,7 +86,7 @@ static void curses_signal_handler(int sig)
  */
 static void curses_exit_handler(int sig)
 {
-  curs_set(1);
+  mutt_curses_set_cursor(MUTT_CURSOR_VISIBLE);
   endwin(); /* just to be safe */
   mutt_unlink_temp_attachments();
   mutt_sig_exit_handler(sig); /* DOES NOT RETURN */
@@ -98,7 +98,7 @@ static void curses_exit_handler(int sig)
  */
 static void curses_segv_handler(int sig)
 {
-  curs_set(1);
+  mutt_curses_set_cursor(MUTT_CURSOR_VISIBLE);
   endwin(); /* just to be safe */
 #ifdef HAVE_LIBUNWIND
   show_backtrace();
diff --git a/pager.c b/pager.c
index 4389301c9aba5b7650c8ddbabb0ebd54284721dc..5102aade2ef9ec17cf0e66c880c0733a1f1551f6 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -2333,7 +2333,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P
 
   while (ch != -1)
   {
-    mutt_curs_set(0);
+    mutt_curses_set_cursor(MUTT_CURSOR_INVISIBLE);
 
     pager_custom_redraw(pager_menu);
 
@@ -2367,7 +2367,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P
     {
       mutt_clear_error();
     }
-    mutt_curs_set(1);
+    mutt_curses_set_cursor(MUTT_CURSOR_VISIBLE);
 
     bool do_new_mail = false;