NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
attr.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stddef.h>
32#include <stdint.h>
33#include "mutt/lib.h"
34#include "attr.h"
35#include "curses2.h"
36#include "debug.h"
37
45{
46 if (!ac)
47 return;
48
49 if (ac->curses_color)
50 color_debug(LL_DEBUG5, "clear %p\n", ac);
52 ac->attrs = 0;
53}
54
59void attr_color_free(struct AttrColor **ptr)
60{
61 if (!ptr || !*ptr)
62 return;
63
64 struct AttrColor *ac = *ptr;
65 if (ac->ref_count > 1)
66 {
67 ac->ref_count--;
68 *ptr = NULL;
69 return;
70 }
71
73 FREE(ptr);
74}
75
81{
82 struct AttrColor *ac = mutt_mem_calloc(1, sizeof(*ac));
83
84 ac->ref_count = 1;
85
86 return ac;
87}
88
97void attr_color_list_clear(struct AttrColorList *acl)
98{
99 if (!acl)
100 return;
101
102 struct AttrColor *ac = NULL;
103 struct AttrColor *tmp = NULL;
104 TAILQ_FOREACH_SAFE(ac, acl, entries, tmp)
105 {
106 TAILQ_REMOVE(acl, ac, entries);
107 attr_color_free(&ac);
108 }
109}
110
119struct AttrColor *attr_color_list_find(struct AttrColorList *acl, uint32_t fg,
120 uint32_t bg, int attrs)
121{
122 if (!acl)
123 return NULL;
124
125 struct AttrColor *ac = NULL;
126 TAILQ_FOREACH(ac, acl, entries)
127 {
128 if (ac->attrs != attrs)
129 continue;
130
131 struct CursesColor *cc = ac->curses_color;
132 if (!cc)
133 continue;
134
135 if ((cc->fg == fg) && (cc->bg == bg))
136 return ac;
137 }
138 return NULL;
139}
140
146struct AttrColor attr_color_copy(const struct AttrColor *ac)
147{
148 struct AttrColor copy = { 0 };
149 if (ac)
150 copy = *ac;
151
152 return copy;
153}
154
161{
162 if (!ac)
163 return false;
164
165 return ((ac->attrs != 0) || ac->curses_color);
166}
167
174bool attr_color_match(struct AttrColor *ac1, struct AttrColor *ac2)
175{
176 if ((!ac1) ^ (!ac2)) // One is set, but not the other
177 return false;
178
179 if (!ac1) // Two empty colours match
180 return true;
181
182 return ((ac1->curses_color == ac2->curses_color) && (ac1->attrs == ac2->attrs));
183}
void attr_color_clear(struct AttrColor *ac)
Free the contents of an AttrColor.
Definition: attr.c:44
struct AttrColor * attr_color_list_find(struct AttrColorList *acl, uint32_t fg, uint32_t bg, int attrs)
Find an AttrColor in a list.
Definition: attr.c:119
bool attr_color_is_set(struct AttrColor *ac)
Is the object coloured?
Definition: attr.c:160
bool attr_color_match(struct AttrColor *ac1, struct AttrColor *ac2)
Do the colours match?
Definition: attr.c:174
struct AttrColor attr_color_copy(const struct AttrColor *ac)
Copy a colour.
Definition: attr.c:146
struct AttrColor * attr_color_new(void)
Create a new AttrColor.
Definition: attr.c:80
void attr_color_free(struct AttrColor **ptr)
Free an AttrColor.
Definition: attr.c:59
void attr_color_list_clear(struct AttrColorList *acl)
Free the contents of an AttrColorList.
Definition: attr.c:97
Colour and attributes.
Curses Colour.
void curses_color_free(struct CursesColor **ptr)
Free a CursesColor.
Definition: curses.c:119
int color_debug(enum LogLevel level, const char *format,...)
Write to the log file.
Definition: debug.c:44
Colour Debugging.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:43
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_REMOVE(head, elm, field)
Definition: queue.h:841
A curses colour and its attributes.
Definition: attr.h:35
short ref_count
Number of users.
Definition: attr.h:38
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