NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
curses2.h File Reference

Curses Colour. More...

#include <stdint.h>
#include "mutt/lib.h"
+ Include dependency graph for curses2.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CursesColor
 Colour in the ncurses palette. More...
 

Typedefs

typedef int32_t color_t
 Type for 24-bit colour value.
 

Functions

 TAILQ_HEAD (CursesColorList, CursesColor)
 
void curses_color_free (struct CursesColor **ptr)
 Free a CursesColor.
 
struct CursesColorcurses_color_new (color_t fg, color_t bg)
 Create a new CursesColor.
 
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.
 

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 curses2.h.

Typedef Documentation

◆ color_t

typedef int32_t color_t

Type for 24-bit colour value.

Definition at line 30 of file curses2.h.

Function Documentation

◆ TAILQ_HEAD()

TAILQ_HEAD ( CursesColorList ,
CursesColor  )

◆ 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}
void curses_color_dump(struct CursesColor *cc, const char *prefix)
Log one Curses colour.
Definition debug.c:120
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 FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
@ 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_REMOVE(head, elm, field)
Definition queue.h:901
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
Colour in the ncurses palette.
Definition curses2.h:40
short ref_count
Number of users.
Definition curses2.h:44
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_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_FOREACH(var, head, field)
Definition queue.h:782
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:866
#define TAILQ_INSERT_BEFORE(listelm, elm, field)
Definition queue.h:843
color_t fg
Foreground colour.
Definition curses2.h:41
color_t bg
Background colour.
Definition curses2.h:42
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_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}
#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 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}
+ Here is the call graph for this function:
+ Here is the caller graph for this function: