NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
curses.c File Reference

Curses Colour. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include "mutt/lib.h"
#include "gui/lib.h"
#include "color.h"
#include "curses2.h"
#include "debug.h"
+ Include dependency graph for curses.c:

Go to the source code of this file.

Functions

void curses_colors_init (void)
 Initialise the Curses colours.
 
struct CursesColorcurses_colors_find (color_t fg, color_t bg)
 Find a Curses colour by foreground/background.
 
static int curses_color_init (color_t fg, color_t bg)
 Initialise a new Curses colour.
 
void curses_color_free (struct CursesColor **ptr)
 Free a CursesColor.
 
struct CursesColorcurses_color_new (color_t fg, color_t bg)
 Create a new CursesColor.
 

Variables

struct CursesColorList CursesColors
 List of all Curses colours.
 
int NumCursesColors
 Number of ncurses colours left to allocate.
 

Detailed Description

Curses Colour.

Authors
  • Richard Russon

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/.

Definition in file curses.c.

Function Documentation

◆ curses_colors_init()

void curses_colors_init ( void  )

Initialise the Curses colours.

Definition at line 44 of file curses.c.

45{
46 color_debug(LL_DEBUG5, "init CursesColors\n");
49}
int NumCursesColors
Number of ncurses colours left to allocate.
Definition: curses.c:39
struct CursesColorList CursesColors
List of all Curses colours.
Definition: curses.c:38
static int color_debug(enum LogLevel level, const char *format,...)
Definition: debug.h:52
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
#define TAILQ_INIT(head)
Definition: queue.h:783
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ curses_colors_find()

struct CursesColor * curses_colors_find ( color_t  fg,
color_t  bg 
)

Find a Curses colour by foreground/background.

Parameters
fgForeground colour
bgBackground colour
Return values
ptrCurses colour

Definition at line 57 of file curses.c.

58{
59 struct CursesColor *cc = NULL;
60 TAILQ_FOREACH(cc, &CursesColors, entries)
61 {
62 if ((cc->fg == fg) && (cc->bg == bg))
63 {
64 curses_color_dump(cc, "find");
65 return cc;
66 }
67 }
68
69 return NULL;
70}
void curses_color_dump(struct CursesColor *cc, const char *prefix)
Log one Curses colour.
Definition: debug.c:122
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:743
Colour in the ncurses palette.
Definition: curses2.h:41
color_t fg
Foreground colour.
Definition: curses2.h:42
color_t bg
Background colour.
Definition: curses2.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ curses_color_init()

static int curses_color_init ( color_t  fg,
color_t  bg 
)
static

Initialise a new Curses colour.

Parameters
fgForeground colour
bgBackground colour
Return values
numIndex of Curses colour

Definition at line 78 of file curses.c.

79{
80 color_debug(LL_DEBUG5, "find lowest index\n");
81 int index = 16;
82 struct CursesColor *cc = NULL;
83 TAILQ_FOREACH(cc, &CursesColors, entries)
84 {
85 if (cc->index == index)
86 index++;
87 else
88 break;
89 }
90 color_debug(LL_DEBUG5, "lowest index = %d\n", index);
91 if (index >= COLOR_PAIRS)
92 {
93 if (COLOR_PAIRS > 0)
94 {
95 static bool warned = false;
96 if (!warned)
97 {
98 mutt_error(_("Too many colors: %d / %d"), index, COLOR_PAIRS);
99 warned = true;
100 }
101 }
102 return 0;
103 }
104
105#ifdef NEOMUTT_DIRECT_COLORS
106 int rc = init_extended_pair(index, fg, bg);
107 color_debug(LL_DEBUG5, "init_extended_pair(%d,%d,%d) -> %d\n", index, fg, bg, rc);
108#else
109 int rc = init_pair(index, fg, bg);
110 color_debug(LL_DEBUG5, "init_pair(%d,%d,%d) -> %d\n", index, fg, bg, rc);
111#endif
112
113 return index;
114}
#define mutt_error(...)
Definition: logging2.h:92
#define _(a)
Definition: message.h:28
short index
Index number.
Definition: curses2.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ curses_color_free()

void curses_color_free ( struct CursesColor **  ptr)

Free a CursesColor.

Parameters
ptrCursesColor to be freed

Definition at line 120 of file curses.c.

121{
122 if (!ptr || !*ptr)
123 return;
124
125 struct CursesColor *cc = *ptr;
126
127 cc->ref_count--;
128 if (cc->ref_count > 0)
129 {
130 curses_color_dump(cc, "curses rc--");
131 *ptr = NULL;
132 return;
133 }
134
135 curses_color_dump(cc, "curses free");
136 TAILQ_REMOVE(&CursesColors, cc, entries);
138 color_debug(LL_DEBUG5, "CursesColors: %d\n", NumCursesColors);
139 FREE(ptr);
140}
#define FREE(x)
Definition: memory.h:55
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:862
short ref_count
Number of users.
Definition: curses2.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ curses_color_new()

struct CursesColor * curses_color_new ( color_t  fg,
color_t  bg 
)

Create a new CursesColor.

Parameters
fgForeground colour
bgBackground colour
Return values
ptrNew CursesColor

If the colour already exists, this function will return a pointer to the object (and increase its ref-count).

Definition at line 151 of file curses.c.

152{
153 color_debug(LL_DEBUG5, "fg %d, bg %d\n", fg, bg);
154 if ((fg == COLOR_DEFAULT) && (bg == COLOR_DEFAULT))
155 {
156 color_debug(LL_DEBUG5, "both unset\n");
157 return NULL;
158 }
159
160 struct CursesColor *cc = curses_colors_find(fg, bg);
161 if (cc)
162 {
163 cc->ref_count++;
164 curses_color_dump(cc, "curses rc++");
165 return cc;
166 }
167
168 color_debug(LL_DEBUG5, "new curses\n");
170 if (index == 0)
171 return NULL;
172
173 struct CursesColor *cc_new = MUTT_MEM_CALLOC(1, struct CursesColor);
175 color_debug(LL_DEBUG5, "CursesColor %p\n", (void *) cc_new);
176 cc_new->fg = fg;
177 cc_new->bg = bg;
178 cc_new->ref_count = 1;
179 cc_new->index = index;
180
181 // insert curses colour
182 TAILQ_FOREACH(cc, &CursesColors, entries)
183 {
184 if (cc->index > index)
185 {
186 color_debug(LL_DEBUG5, "insert\n");
187 TAILQ_INSERT_BEFORE(cc, cc_new, entries);
188 goto done;
189 }
190 }
191
192 TAILQ_INSERT_TAIL(&CursesColors, cc_new, entries);
193 color_debug(LL_DEBUG5, "tail\n");
194
195done:
196 curses_color_dump(cc_new, "curses new");
197 color_debug(LL_DEBUG5, "CursesColors: %d\n", NumCursesColors);
198 return cc_new;
199}
#define COLOR_DEFAULT
Definition: color.h:96
static int curses_color_init(color_t fg, color_t bg)
Initialise a new Curses colour.
Definition: curses.c:78
struct CursesColor * curses_colors_find(color_t fg, color_t bg)
Find a Curses colour by foreground/background.
Definition: curses.c:57
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:827
#define TAILQ_INSERT_BEFORE(listelm, elm, field)
Definition: queue.h:804
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ CursesColors

struct CursesColorList CursesColors

List of all Curses colours.

Definition at line 38 of file curses.c.

◆ NumCursesColors

int NumCursesColors

Number of ncurses colours left to allocate.

Definition at line 39 of file curses.c.