NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
merged.c
Go to the documentation of this file.
1
22
30
31#include "config.h"
32#include <stdbool.h>
33#include <stddef.h>
34#include "mutt/lib.h"
35#include "core/lib.h"
36#include "attr.h"
37#include "color.h"
38#include "curses2.h"
39#include "module_data.h"
40
49
54{
56 struct AttrColor *ac = NULL;
57 struct AttrColor *tmp = NULL;
58
59 TAILQ_FOREACH_SAFE(ac, &mod_data->merged_colors, entries, tmp)
60 {
61 TAILQ_REMOVE(&mod_data->merged_colors, ac, entries);
63 FREE(&ac);
64 }
65}
66
75{
77 struct AttrColor *ac = NULL;
78 TAILQ_FOREACH(ac, &mod_data->merged_colors, entries)
79 {
80 if (ac->attrs != attrs)
81 continue;
82
83 bool has_color = (fg != COLOR_DEFAULT) || (bg != COLOR_DEFAULT);
84 struct CursesColor *cc = ac->curses_color;
85
86 // Both have only attributes
87 if (!has_color && !cc)
88 return ac;
89
90 // One has colour, but not the other
91 if ((has_color && !cc) || (!has_color && cc))
92 continue;
93
94 if ((cc->fg == fg) && (cc->bg == bg))
95 return ac;
96 }
97 return NULL;
98}
99
110const struct AttrColor *merged_color_overlay(const struct AttrColor *base,
111 const struct AttrColor *over)
112{
113 if (!attr_color_is_set(over))
114 return base;
115 if (!attr_color_is_set(base))
116 return over;
117
119 struct CursesColor *cc_base = base->curses_color;
120 struct CursesColor *cc_over = over->curses_color;
121
124
125 if (cc_over)
126 {
127 fg = cc_over->fg;
128 bg = cc_over->bg;
129 }
130
131 if (cc_base)
132 {
133 if (fg == COLOR_DEFAULT)
134 fg = cc_base->fg;
135 if (bg == COLOR_DEFAULT)
136 bg = cc_base->bg;
137 }
138
139 int attrs = base->attrs | over->attrs;
140
141 struct AttrColor *ac = merged_colors_find(fg, bg, attrs);
142 if (ac)
143 return ac;
144
145 ac = attr_color_new();
147 ac->attrs = attrs;
148 ac->fg = (base->fg.color == COLOR_DEFAULT) ? over->fg : base->fg;
149 ac->bg = (base->bg.color == COLOR_DEFAULT) ? over->bg : base->bg;
150 TAILQ_INSERT_TAIL(&mod_data->merged_colors, ac, entries);
151
152 return ac;
153}
struct AttrColor * attr_color_new(void)
Create a new AttrColor.
Definition attr.c:89
bool attr_color_is_set(const struct AttrColor *ac)
Is the object coloured?
Definition attr.c:178
Colour and attributes.
Color private Module data.
Color and attribute parsing.
#define COLOR_DEFAULT
Definition color.h:102
Convenience wrapper for the core headers.
Curses Colour.
int32_t color_t
Type for 24-bit colour value.
Definition curses2.h:30
struct CursesColor * curses_color_new(color_t fg, color_t bg)
Create a new CursesColor.
Definition curses.c:154
void curses_color_free(struct CursesColor **ptr)
Free a CursesColor.
Definition curses.c:122
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
void merged_colors_cleanup(void)
Free the list of Merged colours.
Definition merged.c:53
void merged_colors_init(void)
Initialise the Merged colours.
Definition merged.c:44
const struct AttrColor * merged_color_overlay(const struct AttrColor *base, const struct AttrColor *over)
Combine two colours.
Definition merged.c:110
static struct AttrColor * merged_colors_find(color_t fg, color_t bg, int attrs)
Find a Merged colour.
Definition merged.c:74
@ MODULE_ID_COLOR
ModuleColor, Color
Definition module_api.h:53
Convenience wrapper for the library headers.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:665
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition queue.h:792
#define TAILQ_INIT(head)
Definition queue.h:822
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:866
#define TAILQ_REMOVE(head, elm, field)
Definition queue.h:901
A curses colour and its attributes.
Definition attr.h:65
struct ColorElement bg
Background colour.
Definition attr.h:67
struct ColorElement fg
Foreground colour.
Definition attr.h:66
int attrs
Text attributes, e.g. A_BOLD.
Definition attr.h:68
struct CursesColor * curses_color
Underlying Curses colour.
Definition attr.h:69
color_t color
Colour.
Definition attr.h:56
Color private Module data.
Definition module_data.h:35
struct AttrColorList merged_colors
Array of user colours.
Definition module_data.h:39
Colour in the ncurses palette.
Definition curses2.h:40
color_t fg
Foreground colour.
Definition curses2.h:41
color_t bg
Background colour.
Definition curses2.h:42
Container for Accounts, Notifications.
Definition neomutt.h:41