NeoMutt  2025-12-11-911-gd8d604
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 "core/lib.h"
#include "gui/lib.h"
#include "color.h"
#include "curses2.h"
#include "debug.h"
#include "module_data.h"
+ Include dependency graph for curses.c:

Go to the source code of this file.

Functions

void curses_colors_init (struct CursesColorList *curses_colors, int *num_curses_colors)
 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.
 

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 ( struct CursesColorList * curses_colors,
int * num_curses_colors )

Initialise the Curses colours.

Parameters
curses_colorsList of Curses colours
num_curses_colorsPointer to the count of Curses colours

Definition at line 45 of file curses.c.

46{
47 color_debug(LL_DEBUG5, "init CursesColors\n");
48 TAILQ_INIT(curses_colors);
49 *num_curses_colors = 0;
50}
static int color_debug(enum LogLevel level, const char *format,...)
Definition debug.h:51
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
#define TAILQ_INIT(head)
Definition queue.h:822
+ 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 58 of file curses.c.

59{
61 struct CursesColor *cc = NULL;
62 TAILQ_FOREACH(cc, &mod_data->curses_colors, entries)
63 {
64 if ((cc->fg == fg) && (cc->bg == bg))
65 {
66 curses_color_dump(cc, "find");
67 return cc;
68 }
69 }
70
71 return NULL;
72}
void curses_color_dump(struct CursesColor *cc, const char *prefix)
Log one Curses colour.
Definition debug.c:120
@ MODULE_ID_COLOR
ModuleColor, Color
Definition module_api.h:53
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
Color private Module data.
Definition module_data.h:35
struct CursesColorList curses_colors
List of all Curses colours.
Definition module_data.h:37
Colour in the ncurses palette.
Definition curses2.h:40
color_t fg
Foreground colour.
Definition curses2.h:41
color_t bg
Background colour.
Definition curses2.h:42
Container for Accounts, Notifications.
Definition neomutt.h:41
+ 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 80 of file curses.c.

81{
83 color_debug(LL_DEBUG5, "find lowest index\n");
84 int index = 16;
85 struct CursesColor *cc = NULL;
86 TAILQ_FOREACH(cc, &mod_data->curses_colors, entries)
87 {
88 if (cc->index == index)
89 index++;
90 else
91 break;
92 }
93 color_debug(LL_DEBUG5, "lowest index = %d\n", index);
94 if (index >= COLOR_PAIRS)
95 {
96 if (COLOR_PAIRS > 0)
97 {
98 static bool warned = false;
99 if (!warned)
100 {
101 mutt_error(_("Too many colors: %d / %d"), index, COLOR_PAIRS);
102 warned = true;
103 }
104 }
105 return 0;
106 }
107
108#ifdef NEOMUTT_DIRECT_COLORS
109 int rc = init_extended_pair(index, fg, bg);
110 color_debug(LL_DEBUG5, "init_extended_pair(%d,%d,%d) -> %d\n", index, fg, bg, rc);
111#else
112 int rc = init_pair(index, fg, bg);
113 color_debug(LL_DEBUG5, "init_pair(%d,%d,%d) -> %d\n", index, fg, bg, rc);
114#endif
115
116 return index;
117}
#define mutt_error(...)
Definition logging2.h:94
#define _(a)
Definition message.h:28
short index
Index number.
Definition curses2.h:43
+ 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 123 of file curses.c.

124{
125 if (!ptr || !*ptr)
126 return;
127
128 struct CursesColor *cc = *ptr;
129
130 cc->ref_count--;
131 if (cc->ref_count > 0)
132 {
133 curses_color_dump(cc, "curses rc--");
134 *ptr = NULL;
135 return;
136 }
137
138 curses_color_dump(cc, "curses free");
140 TAILQ_REMOVE(&mod_data->curses_colors, cc, entries);
141 mod_data->num_curses_colors--;
142 color_debug(LL_DEBUG5, "CursesColors: %d\n", mod_data->num_curses_colors);
143 FREE(ptr);
144}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define TAILQ_REMOVE(head, elm, field)
Definition queue.h:901
int num_curses_colors
Number of ncurses colours left to allocate.
Definition module_data.h:38
short ref_count
Number of users.
Definition curses2.h:44
+ 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 155 of file curses.c.

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