NeoMutt  2025-12-11-769-g906513
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 (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.
 

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 43 of file curses.c.

44{
46 color_debug(LL_DEBUG5, "init CursesColors\n");
47 TAILQ_INIT(&mod_data->curses_colors);
48 mod_data->num_curses_colors = 0;
49}
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
@ 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:665
#define TAILQ_INIT(head)
Definition queue.h:822
Color private Module data.
Definition module_data.h:35
int num_curses_colors
Number of ncurses colours left to allocate.
Definition module_data.h:38
struct CursesColorList curses_colors
List of all Curses colours.
Definition module_data.h:37
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_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{
60 struct CursesColor *cc = NULL;
61 TAILQ_FOREACH(cc, &mod_data->curses_colors, entries)
62 {
63 if ((cc->fg == fg) && (cc->bg == bg))
64 {
65 curses_color_dump(cc, "find");
66 return cc;
67 }
68 }
69
70 return NULL;
71}
void curses_color_dump(struct CursesColor *cc, const char *prefix)
Log one Curses colour.
Definition debug.c:120
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
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
+ 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 79 of file curses.c.

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

123{
124 if (!ptr || !*ptr)
125 return;
126
127 struct CursesColor *cc = *ptr;
128
129 cc->ref_count--;
130 if (cc->ref_count > 0)
131 {
132 curses_color_dump(cc, "curses rc--");
133 *ptr = NULL;
134 return;
135 }
136
137 curses_color_dump(cc, "curses free");
139 TAILQ_REMOVE(&mod_data->curses_colors, cc, entries);
140 mod_data->num_curses_colors--;
141 color_debug(LL_DEBUG5, "CursesColors: %d\n", mod_data->num_curses_colors);
142 FREE(ptr);
143}
#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
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 154 of file curses.c.

155{
156 color_debug(LL_DEBUG5, "fg %d, bg %d\n", fg, bg);
157 if ((fg == COLOR_DEFAULT) && (bg == COLOR_DEFAULT))
158 {
159 color_debug(LL_DEBUG5, "both unset\n");
160 return NULL;
161 }
162
163 struct CursesColor *cc = curses_colors_find(fg, bg);
164 if (cc)
165 {
166 cc->ref_count++;
167 curses_color_dump(cc, "curses rc++");
168 return cc;
169 }
170
171 color_debug(LL_DEBUG5, "new curses\n");
173 if (index == 0)
174 return NULL;
175
177 struct CursesColor *cc_new = MUTT_MEM_CALLOC(1, struct CursesColor);
178 mod_data->num_curses_colors++;
179 color_debug(LL_DEBUG5, "CursesColor %p\n", (void *) cc_new);
180 cc_new->fg = fg;
181 cc_new->bg = bg;
182 cc_new->ref_count = 1;
183 cc_new->index = index;
184
185 // insert curses colour
186 TAILQ_FOREACH(cc, &mod_data->curses_colors, entries)
187 {
188 if (cc->index > index)
189 {
190 color_debug(LL_DEBUG5, "insert\n");
191 TAILQ_INSERT_BEFORE(cc, cc_new, entries);
192 goto done;
193 }
194 }
195
196 TAILQ_INSERT_TAIL(&mod_data->curses_colors, cc_new, entries);
197 color_debug(LL_DEBUG5, "tail\n");
198
199done:
200 curses_color_dump(cc_new, "curses new");
201 color_debug(LL_DEBUG5, "CursesColors: %d\n", mod_data->num_curses_colors);
202 return cc_new;
203}
#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:79
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: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: