From: Richard Russon Date: Fri, 27 Sep 2019 13:21:46 +0000 (+0100) Subject: refactor: curs_set() to mutt_curses_set_cursor() X-Git-Tag: 2019-10-25~30^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=12371ffc31444671310c9078ad0094f2a404e317;p=neomutt refactor: curs_set() to mutt_curses_set_cursor() Encapsulate a curses function to reduce dependencies. --- diff --git a/curs_lib.c b/curs_lib.c index 47026e775..f9db313d0 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -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 d989d2d86..9f1fdfee6 100644 --- 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 27fcf5ef7..a49467f56 100644 --- 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) { diff --git a/mutt_curses.c b/mutt_curses.c index 68c32f8c6..0cfd5b1a3 100644 --- a/mutt_curses.c +++ b/mutt_curses.c @@ -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 +} diff --git a/mutt_curses.h b/mutt_curses.h index 6b9df2d03..5b200baa5 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -84,16 +84,6 @@ 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 */ diff --git a/mutt_signal.c b/mutt_signal.c index fe3ad73c7..c1b27b736 100644 --- a/mutt_signal.c +++ b/mutt_signal.c @@ -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 4389301c9..5102aade2 100644 --- 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;