NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
merged.c
Go to the documentation of this file.
1
31#include "config.h"
32#include <stddef.h>
33#include <stdbool.h>
34#include <stdint.h>
35#include "mutt/lib.h"
36#include "attr.h"
37#include "color.h"
38#include "curses2.h"
39#include "debug.h"
40
41struct AttrColorList MergedColors;
42
47{
49}
50
55{
56 struct AttrColor *ac = NULL;
57 struct AttrColor *tmp = NULL;
58
59 TAILQ_FOREACH_SAFE(ac, &MergedColors, entries, tmp)
60 {
61 TAILQ_REMOVE(&MergedColors, ac, entries);
63 FREE(&ac);
64 }
65}
66
74static struct AttrColor *merged_colors_find(int fg, int bg, int attrs)
75{
76 struct AttrColor *ac = NULL;
77 TAILQ_FOREACH(ac, &MergedColors, entries)
78 {
79 if (ac->attrs != attrs)
80 continue;
81
82 bool has_color = (fg != COLOR_DEFAULT) || (bg != COLOR_DEFAULT);
83 struct CursesColor *cc = ac->curses_color;
84
85 // Both have only attributes
86 if (!has_color && !cc)
87 return ac;
88
89 // One has colour, but not the other
90 if ((has_color && !cc) || (!has_color && cc))
91 continue;
92
93 if ((cc->fg == fg) && (cc->bg == bg))
94 return ac;
95 }
96 return NULL;
97}
98
109const struct AttrColor *merged_color_overlay(const struct AttrColor *base,
110 const struct AttrColor *over)
111{
112 if (!attr_color_is_set(over))
113 return base;
114 if (!attr_color_is_set(base))
115 return over;
116
117 struct CursesColor *cc_base = base->curses_color;
118 struct CursesColor *cc_over = over->curses_color;
119
120 uint32_t fg = COLOR_DEFAULT;
121 uint32_t bg = COLOR_DEFAULT;
122
123 if (cc_over)
124 {
125 fg = cc_over->fg;
126 bg = cc_over->bg;
127 }
128
129 if (cc_base)
130 {
131 if (fg == COLOR_DEFAULT)
132 fg = cc_base->fg;
133 if (bg == COLOR_DEFAULT)
134 bg = cc_base->bg;
135 }
136
137 int attrs = base->attrs | over->attrs;
138
139 struct AttrColor *ac = merged_colors_find(fg, bg, attrs);
140 if (ac)
141 return ac;
142
143 ac = attr_color_new();
144 ac->curses_color = curses_color_new(fg, bg);
145 ac->attrs = attrs;
146 TAILQ_INSERT_TAIL(&MergedColors, ac, entries);
148
149 return ac;
150}
struct AttrColor * attr_color_new(void)
Create a new AttrColor.
Definition: attr.c:80
bool attr_color_is_set(const struct AttrColor *ac)
Is the object coloured?
Definition: attr.c:160
Colour and attributes.
Color and attribute parsing.
#define COLOR_DEFAULT
Definition: color.h:104
Curses Colour.
void curses_color_free(struct CursesColor **ptr)
Free a CursesColor.
Definition: curses.c:121
struct CursesColor * curses_color_new(int fg, int bg)
Create a new CursesColor.
Definition: curses.c:151
void merged_colors_dump(void)
Dump all the Merged colours to the log.
Definition: debug.c:463
Colour Debugging.
#define FREE(x)
Definition: memory.h:45
static struct AttrColor * merged_colors_find(int fg, int bg, int attrs)
Find a Merged colour.
Definition: merged.c:74
void merged_colors_cleanup(void)
Free the list of Merged colours.
Definition: merged.c:54
void merged_colors_init(void)
Initialise the Merged colours.
Definition: merged.c:46
const struct AttrColor * merged_color_overlay(const struct AttrColor *base, const struct AttrColor *over)
Combine two colours.
Definition: merged.c:109
struct AttrColorList MergedColors
Array of user colours.
Definition: merged.c:41
Convenience wrapper for the library headers.
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
#define TAILQ_INIT(head)
Definition: queue.h:765
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
A curses colour and its attributes.
Definition: attr.h:35
int attrs
Text attributes, e.g. A_BOLD.
Definition: attr.h:37
struct CursesColor * curses_color
Underlying Curses colour.
Definition: attr.h:36
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