NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
curses2.h File Reference

Curses Colour. More...

#include "config.h"
#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 31 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 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}
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
void curses_color_dump(struct CursesColor *cc, const char *prefix)
Log one Curses colour.
Definition: debug.c:122
static int color_debug(enum LogLevel level, const char *format,...)
Definition: debug.h:53
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
#define FREE(x)
Definition: memory.h:45
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
Colour in the ncurses palette.
Definition: curses2.h:41
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, sizeof(*cc_new));
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:100
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
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
#define TAILQ_INSERT_BEFORE(listelm, elm, field)
Definition: queue.h:786
color_t fg
Foreground colour.
Definition: curses2.h:42
color_t bg
Background colour.
Definition: curses2.h:43
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_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}
#define TAILQ_INIT(head)
Definition: queue.h:765
+ 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}
+ Here is the call graph for this function:
+ Here is the caller graph for this function: