NeoMutt
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...
 

Functions

 TAILQ_HEAD (CursesColorList, CursesColor)
 
void curses_color_free (struct CursesColor **ptr)
 Free a CursesColor.
 
struct CursesColorcurses_color_new (int fg, int bg)
 Create a new CursesColor.
 
void curses_colors_init (void)
 Initialise the Curses colours.
 
struct CursesColorcurses_colors_find (int fg, int 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.

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

122{
123 if (!ptr || !*ptr)
124 return;
125
126 struct CursesColor *cc = *ptr;
127 if (cc->ref_count > 1)
128 {
129 cc->ref_count--;
130 curses_color_dump(cc, "CursesColor rc--: ");
131 *ptr = NULL;
132 return;
133 }
134
135 curses_color_dump(cc, "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
int color_debug(enum LogLevel level, const char *format,...)
Write to the log file.
Definition: debug.c:51
void curses_color_dump(struct CursesColor *cc, const char *prefix)
Log one Curses colour.
Definition: debug.c:261
@ 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: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 151 of file curses.c.

152{
153 color_debug(LL_DEBUG5, "fg %d, bg %d\n", fg, bg);
154 if (((fg == COLOR_UNSET) && (bg == COLOR_UNSET)) ||
155 ((fg == COLOR_DEFAULT) && (bg == COLOR_DEFAULT)))
156 {
157 color_debug(LL_DEBUG5, "both unset\n");
158 return NULL;
159 }
160
161 struct CursesColor *cc = curses_colors_find(fg, bg);
162 if (cc)
163 {
164 cc->ref_count++;
165 curses_color_dump(cc, "rc++: ");
166 return cc;
167 }
168
169 color_debug(LL_DEBUG5, "new curses\n");
171 if (index < 0)
172 return NULL;
173
174 struct CursesColor *cc_new = mutt_mem_calloc(1, sizeof(*cc_new));
176 color_debug(LL_DEBUG5, "CursesColor %p\n", (void *) cc_new);
177 cc_new->fg = fg;
178 cc_new->bg = bg;
179 cc_new->ref_count = 1;
180 cc_new->index = index;
181
182 // insert curses colour
183 TAILQ_FOREACH(cc, &CursesColors, entries)
184 {
185 if (cc->index > index)
186 {
187 color_debug(LL_DEBUG5, "insert\n");
188 TAILQ_INSERT_BEFORE(cc, cc_new, entries);
189 goto done;
190 }
191 }
192
193 TAILQ_INSERT_TAIL(&CursesColors, cc_new, entries);
194 color_debug(LL_DEBUG5, "tail\n");
195
196done:
197 curses_color_dump(cc_new, "CursesColor new: ");
198 color_debug(LL_DEBUG5, "CursesColors: %d\n", NumCursesColors);
199 return cc_new;
200}
#define COLOR_DEFAULT
Definition: color.h:104
#define COLOR_UNSET
Definition: color.h:105
static int curses_color_init(int fg, int bg)
Initialise a new Curses colour.
Definition: curses.c:77
struct CursesColor * curses_colors_find(int fg, int 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
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 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 ( int  fg,
int  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 return cc;
65 }
66 }
67
68 return NULL;
69}
+ Here is the caller graph for this function: