NeoMutt  2022-04-29-323-g5fcc6c
Teaching an old dog new tricks
merged.c File Reference

Merged colours. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "attr.h"
#include "color.h"
#include "curses2.h"
#include "debug.h"
+ Include dependency graph for merged.c:

Go to the source code of this file.


void merged_colors_init (void)
 Initialise the Merged colours. More...
void merged_colors_clear (void)
 Free the list of Merged colours. More...
struct AttrColormerged_colors_find (int fg, int bg, int attrs)
 Find a Merged colour. More...
struct AttrColormerged_color_overlay (struct AttrColor *base, struct AttrColor *over)
 Combine two colours. More...


struct AttrColorList MergedColors
 Array of user colours. More...

Detailed Description

Merged colours.

  • 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

Definition in file merged.c.

Function Documentation

◆ merged_colors_init()

void merged_colors_init ( void  )

Initialise the Merged colours.

Definition at line 46 of file merged.c.

struct AttrColorList MergedColors
Array of user colours.
Definition: merged.c:41
#define TAILQ_INIT(head)
Definition: queue.h:765
+ Here is the caller graph for this function:

◆ merged_colors_clear()

void merged_colors_clear ( void  )

Free the list of Merged colours.

Definition at line 54 of file merged.c.

56 struct AttrColor *ac = NULL;
57 struct AttrColor *tmp = NULL;
59 TAILQ_FOREACH_SAFE(ac, &MergedColors, entries, tmp)
60 {
61 TAILQ_REMOVE(&MergedColors, ac, entries);
63 FREE(&ac);
64 }
void curses_color_free(struct CursesColor **ptr)
Free a CursesColor.
Definition: curses.c:116
#define FREE(x)
Definition: memory.h:43
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
A curses colour and its attributes.
Definition: attr.h:35
struct CursesColor * curses_color
Underlying Curses colour.
Definition: attr.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ merged_colors_find()

struct AttrColor * merged_colors_find ( int  fg,
int  bg,
int  attrs 

Find a Merged colour.

fgForeground colour
bgBackground colour
attrsAttributes, e.g. A_UNDERLINE
Return values
ptrMatching Merged colour

Definition at line 74 of file merged.c.

76 struct AttrColor *ac = NULL;
77 TAILQ_FOREACH(ac, &MergedColors, entries)
78 {
79 if (ac->attrs != attrs)
80 continue;
82 bool has_color = (fg != COLOR_DEFAULT) || (bg != COLOR_DEFAULT);
83 struct CursesColor *cc = ac->curses_color;
85 // Both have only attributes
86 if (!has_color && !cc)
87 return ac;
89 // One has colour, but not the other
90 if ((has_color && !cc) || (!has_color && cc))
91 continue;
93 if ((cc->fg == fg) && (cc->bg == bg))
94 return ac;
95 }
96 return NULL;
Definition: color.h:101
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
int attrs
Text attributes, e.g. A_BOLD.
Definition: attr.h:37
Colour in the ncurses palette.
Definition: curses2.h:38
uint32_t fg
Foreground colour.
Definition: curses2.h:41
uint32_t bg
Background colour.
Definition: curses2.h:42
+ Here is the caller graph for this function:

◆ merged_color_overlay()

struct AttrColor * merged_color_overlay ( struct AttrColor base,
struct AttrColor over 

Combine two colours.

baseBase colour
overOverlay colour
Return values
ptrMerged colour

If either the foreground or background of the overlay is 'default', then the base colour will show through. The attributes of both base and overlay will be OR'd together.

Definition at line 109 of file merged.c.

111 if (!over || (!over->curses_color && (over->attrs == 0)))
112 return base;
113 if (!base || (!base->curses_color && (base->attrs == 0)))
114 return over;
116 struct CursesColor *cc_base = base->curses_color;
117 struct CursesColor *cc_over = over->curses_color;
119 uint32_t fg = COLOR_DEFAULT;
120 uint32_t bg = COLOR_DEFAULT;
122 if (cc_over)
123 {
124 fg = cc_over->fg;
125 bg = cc_over->bg;
126 }
128 if (cc_base)
129 {
130 if (fg == COLOR_DEFAULT)
131 fg = cc_base->fg;
132 if (bg == COLOR_DEFAULT)
133 bg = cc_base->bg;
134 }
136 int attrs = base->attrs | over->attrs;
138 struct AttrColor *ac = merged_colors_find(fg, bg, attrs);
139 if (ac)
140 return ac;
142 ac = attr_color_new();
143 ac->curses_color = curses_color_new(fg, bg);
144 ac->attrs = attrs;
145 TAILQ_INSERT_TAIL(&MergedColors, ac, entries);
148 return ac;
struct AttrColor * attr_color_new(void)
Create a new AttrColor.
Definition: attr.c:80
struct CursesColor * curses_color_new(int fg, int bg)
Create a new CursesColor.
Definition: curses.c:148
void merged_colors_dump(void)
Dump all the Merged colours to the log.
Definition: debug.c:449
struct AttrColor * merged_colors_find(int fg, int bg, int attrs)
Find a Merged colour.
Definition: merged.c:74
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MergedColors

struct AttrColorList MergedColors

Array of user colours.

Definition at line 41 of file merged.c.