NeoMutt  2023-03-22
Teaching an old dog new tricks
DOXYGEN
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...
 

Functions

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

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.

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

117{
118 if (!ptr || !*ptr)
119 return;
120
121 struct CursesColor *cc = *ptr;
122 if (cc->ref_count > 1)
123 {
124 cc->ref_count--;
125 curses_color_dump(cc, "CursesColor rc--: ");
126 *ptr = NULL;
127 // curses_colors_dump();
128 return;
129 }
130
131 curses_color_dump(cc, "free: ");
132 TAILQ_REMOVE(&CursesColors, cc, entries);
134 color_debug(LL_DEBUG5, "CursesColors: %d\n", NumCursesColors);
135 // curses_colors_dump();
136 FREE(ptr);
137}
int NumCursesColors
Definition: curses.c:37
struct CursesColorList CursesColors
List of all Curses colours.
Definition: curses.c:36
int color_debug(enum LogLevel level, const char *format,...)
Write to the log file.
Definition: debug.c:44
void curses_color_dump(struct CursesColor *cc, const char *prefix)
Log one Curses colour.
Definition: debug.c:254
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
#define FREE(x)
Definition: memory.h:43
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
Colour in the ncurses palette.
Definition: curses2.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 ( int  fg,
int  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 148 of file curses.c.

149{
150 color_debug(LL_DEBUG5, "fg %d, bg %d\n", fg, bg);
151 if (((fg == COLOR_UNSET) && (bg == COLOR_UNSET)) ||
152 ((fg == COLOR_DEFAULT) && (bg == COLOR_DEFAULT)))
153 {
154 color_debug(LL_DEBUG5, "both unset\n");
155 return NULL;
156 }
157
158 struct CursesColor *cc = curses_colors_find(fg, bg);
159 if (cc)
160 {
161 cc->ref_count++;
162 curses_color_dump(cc, "rc++: ");
163 return cc;
164 }
165
166 color_debug(LL_DEBUG5, "new curses\n");
168 if (index < 0)
169 return NULL;
170
171 struct CursesColor *cc_new = mutt_mem_calloc(1, sizeof(*cc_new));
173 color_debug(LL_DEBUG5, "CursesColor %p\n", cc_new);
174 cc_new->fg = fg;
175 cc_new->bg = bg;
176 cc_new->ref_count = 1;
177 cc_new->index = index;
178
179 // insert curses colour
180 TAILQ_FOREACH(cc, &CursesColors, entries)
181 {
182 if (cc->index > index)
183 {
184 color_debug(LL_DEBUG5, "insert\n");
185 TAILQ_INSERT_BEFORE(cc, cc_new, entries);
186 goto done;
187 }
188 }
189
190 TAILQ_INSERT_TAIL(&CursesColors, cc_new, entries);
191 color_debug(LL_DEBUG5, "tail\n");
192
193done:
194 curses_color_dump(cc_new, "CursesColor new: ");
195 color_debug(LL_DEBUG5, "CursesColors: %d\n", NumCursesColors);
196 return cc_new;
197}
#define COLOR_DEFAULT
Definition: color.h:102
#define COLOR_UNSET
Definition: color.h:103
static int curses_color_init(int fg, int bg)
Initialise a new Curses colour.
Definition: curses.c:75
struct CursesColor * curses_colors_find(int fg, int bg)
Find a Curses colour by foreground/background.
Definition: curses.c:55
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
short index
Index number.
Definition: curses2.h:43
uint32_t fg
Foreground colour.
Definition: curses2.h:41
uint32_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_colors_init()

void curses_colors_init ( void  )

Initialise the Curses colours.

Definition at line 42 of file curses.c.

43{
44 color_debug(LL_DEBUG5, "init CursesColors\n");
47}
#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 ( int  fg,
int  bg 
)

Find a Curses colour by foreground/background.

Parameters
fgForeground colour
bgBackground colour
Return values
ptrCurses colour

Definition at line 55 of file curses.c.

56{
57 struct CursesColor *cc = NULL;
58 TAILQ_FOREACH(cc, &CursesColors, entries)
59 {
60 if ((cc->fg == fg) && (cc->bg == bg))
61 {
62 return cc;
63 }
64 }
65
66 return NULL;
67}
+ Here is the caller graph for this function: