1 /**
2  * @file
3  * Define wrapper functions around Curses
4  *
5  * @authors
6  * Copyright (C) 1996-2000,2012 Michael R. Elkins <me@mutt.org>
7  * Copyright (C) 2004 g10 Code GmbH
8  * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
9  *
10  * @copyright
11  * This program is free software: you can redistribute it and/or modify it under
12  * the terms of the GNU General Public License as published by the Free Software
13  * Foundation, either version 2 of the License, or (at your option) any later
14  * version.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License along with
22  * this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 /**
26  * @page gui_curses Wrapper around Curses
27  *
28  * Wrapper functions around Curses
29  */
30 
31 #include "config.h"
32 #include "mutt_curses.h"
33 #include "color/lib.h"
34 
35 /**
36  * mutt_curses_set_attr - Set the attributes for text
37  * @param attr Attributes to set, e.g. A_UNDERLINE
38  */
mutt_curses_set_attr(int attr)39 void mutt_curses_set_attr(int attr)
40 {
41   bkgdset(attr | ' ');
42 }
43 
44 /**
45  * mutt_curses_set_color_by_id - Set the current colour for text
46  * @param color Colour to set, e.g. #MT_COLOR_HEADER
47  *
48  * If the system has bkgdset() use it rather than attrset() so that the clr*()
49  * functions will properly set the background attributes all the way to the
50  * right column.
51  */
mutt_curses_set_color_by_id(enum ColorId color)52 void mutt_curses_set_color_by_id(enum ColorId color)
53 {
54   const int chosen = simple_colors_get(color);
55   const int normal = simple_colors_get(MT_COLOR_NORMAL);
56   bkgdset((chosen ? chosen : normal) | ' ');
57 }
58 
59 /**
60  * mutt_curses_set_cursor - Set the cursor state
61  * @param state State to set, e.g. #MUTT_CURSOR_INVISIBLE
62  */
mutt_curses_set_cursor(enum MuttCursorState state)63 void mutt_curses_set_cursor(enum MuttCursorState state)
64 {
65   static int SavedCursor = MUTT_CURSOR_VISIBLE;
66 
67   if (state == MUTT_CURSOR_RESTORE_LAST)
68     state = SavedCursor;
69   else
70     SavedCursor = state;
71 
72   if (curs_set(state) == ERR)
73   {
74     if (state == MUTT_CURSOR_VISIBLE)
75       curs_set(MUTT_CURSOR_VERY_VISIBLE);
76   }
77 }
78