NeoMutt  2025-09-05-55-g97fc89
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
attr.h File Reference

Colour and attributes. More...

#include "config.h"
#include <stdbool.h>
#include "mutt/lib.h"
#include "curses2.h"
+ Include dependency graph for attr.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ColorElement
 One element of a Colour. More...
 
struct  AttrColor
 A curses colour and its attributes. More...
 

Enumerations

enum  ColorType { CT_SIMPLE , CT_PALETTE , CT_RGB }
 Type of Colour. More...
 
enum  ColorPrefix { COLOR_PREFIX_NONE , COLOR_PREFIX_ALERT , COLOR_PREFIX_BRIGHT , COLOR_PREFIX_LIGHT }
 Constants for colour prefixes of named colours. More...
 

Functions

 TAILQ_HEAD (AttrColorList, AttrColor)
 
void attr_color_clear (struct AttrColor *ac)
 Free the contents of an AttrColor.
 
struct AttrColor attr_color_copy (const struct AttrColor *ac)
 Copy a colour.
 
void attr_color_free (struct AttrColor **ptr)
 Free an AttrColor.
 
bool attr_color_is_set (const struct AttrColor *ac)
 Is the object coloured?
 
bool attr_color_match (struct AttrColor *ac1, struct AttrColor *ac2)
 Do the colours match?
 
struct AttrColorattr_color_new (void)
 Create a new AttrColor.
 
void attr_color_list_clear (struct AttrColorList *acl)
 Free the contents of an AttrColorList.
 
struct AttrColorattr_color_list_find (struct AttrColorList *acl, color_t fg, color_t bg, int attrs)
 Find an AttrColor in a list.
 
void attr_color_overwrite (struct AttrColor *ac_old, const struct AttrColor *ac_new)
 Update an AttrColor in-place.
 

Detailed Description

Colour and attributes.

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 attr.h.

Enumeration Type Documentation

◆ ColorType

enum ColorType

Type of Colour.

Enumerator
CT_SIMPLE 

Simple colour, e.g. "Red".

CT_PALETTE 

Palette colour, e.g. "color207".

CT_RGB 

True colour, e.g. "#11AAFF".

Definition at line 34 of file attr.h.

35{
36 CT_SIMPLE,
38 CT_RGB,
39};
@ CT_SIMPLE
Simple colour, e.g. "Red".
Definition attr.h:36
@ CT_PALETTE
Palette colour, e.g. "color207".
Definition attr.h:37
@ CT_RGB
True colour, e.g. "#11AAFF".
Definition attr.h:38

◆ ColorPrefix

Constants for colour prefixes of named colours.

Enumerator
COLOR_PREFIX_NONE 

no prefix

COLOR_PREFIX_ALERT 

"alert" colour prefix

COLOR_PREFIX_BRIGHT 

"bright" colour prefix

COLOR_PREFIX_LIGHT 

"light" colour prefix

Definition at line 44 of file attr.h.

45{
50};
@ COLOR_PREFIX_NONE
no prefix
Definition attr.h:46
@ COLOR_PREFIX_ALERT
"alert" colour prefix
Definition attr.h:47
@ COLOR_PREFIX_LIGHT
"light" colour prefix
Definition attr.h:49
@ COLOR_PREFIX_BRIGHT
"bright" colour prefix
Definition attr.h:48

Function Documentation

◆ TAILQ_HEAD()

TAILQ_HEAD ( AttrColorList ,
AttrColor  )
+ Here is the call graph for this function:

◆ attr_color_clear()

void attr_color_clear ( struct AttrColor * ac)

Free the contents of an AttrColor.

Parameters
acAttrColor to empty
Note
The AttrColor object isn't freed

Definition at line 47 of file attr.c.

48{
49 if (!ac)
50 return;
51
52 if (ac->curses_color)
53 color_debug(LL_DEBUG5, "clear %p\n", (void *) ac);
55
56 memset(&ac->fg, 0, sizeof(ac->fg));
57 memset(&ac->bg, 0, sizeof(ac->bg));
58
61 ac->attrs = A_NORMAL;
62}
#define COLOR_DEFAULT
Definition color.h:103
void curses_color_free(struct CursesColor **ptr)
Free a CursesColor.
Definition curses.c:120
static int color_debug(enum LogLevel level, const char *format,...)
Definition debug.h:52
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:48
struct ColorElement bg
Background colour.
Definition attr.h:68
struct ColorElement fg
Foreground colour.
Definition attr.h:67
int attrs
Text attributes, e.g. A_BOLD.
Definition attr.h:69
struct CursesColor * curses_color
Underlying Curses colour.
Definition attr.h:70
color_t color
Colour.
Definition attr.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attr_color_copy()

struct AttrColor attr_color_copy ( const struct AttrColor * ac)

Copy a colour.

Parameters
acColour to copy
Return values
objCopy of the colour

Definition at line 165 of file attr.c.

166{
167 if (ac)
168 return *ac;
169 else
170 return (struct AttrColor) { 0 };
171}
A curses colour and its attributes.
Definition attr.h:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attr_color_free()

void attr_color_free ( struct AttrColor ** ptr)

Free an AttrColor.

Parameters
ptrAttrColor to free

Definition at line 68 of file attr.c.

69{
70 if (!ptr || !*ptr)
71 return;
72
73 struct AttrColor *ac = *ptr;
74 if (ac->ref_count > 1)
75 {
76 ac->ref_count--;
77 *ptr = NULL;
78 return;
79 }
80
82 FREE(ptr);
83}
void attr_color_clear(struct AttrColor *ac)
Free the contents of an AttrColor.
Definition attr.c:47
#define FREE(x)
Definition memory.h:62
short ref_count
Number of users.
Definition attr.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attr_color_is_set()

bool attr_color_is_set ( const struct AttrColor * ac)

Is the object coloured?

Parameters
acColour to check
Return values
trueYes, a 'color' command has been used on this object

Definition at line 178 of file attr.c.

179{
180 if (!ac)
181 return false;
182
183 return ((ac->attrs != A_NORMAL) || ac->curses_color);
184}
+ Here is the caller graph for this function:

◆ attr_color_match()

bool attr_color_match ( struct AttrColor * ac1,
struct AttrColor * ac2 )

Do the colours match?

Parameters
ac1First colour
ac2Second colour
Return values
trueThe colours and attributes match

Definition at line 192 of file attr.c.

193{
194 if ((!ac1) ^ (!ac2)) // One is set, but not the other
195 return false;
196
197 if (!ac1) // Two empty colours match
198 return true;
199
200 return ((ac1->curses_color == ac2->curses_color) && (ac1->attrs == ac2->attrs));
201}
+ Here is the caller graph for this function:

◆ attr_color_new()

struct AttrColor * attr_color_new ( void )

Create a new AttrColor.

Return values
ptrNew AttrColor

Definition at line 89 of file attr.c.

90{
91 struct AttrColor *ac = MUTT_MEM_CALLOC(1, struct AttrColor);
92
94 ac->fg.type = CT_SIMPLE;
96
98 ac->bg.type = CT_SIMPLE;
100
101 ac->attrs = A_NORMAL;
102
103 ac->ref_count = 1;
104
105 return ac;
106}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:47
enum ColorType type
Type of Colour.
Definition attr.h:58
enum ColorPrefix prefix
Optional Colour Modifier.
Definition attr.h:59
+ Here is the caller graph for this function:

◆ attr_color_list_clear()

void attr_color_list_clear ( struct AttrColorList * acl)

Free the contents of an AttrColorList.

Parameters
aclList to clear

Free each of the AttrColors in a list.

Note
The list object isn't freed, only emptied

Definition at line 116 of file attr.c.

117{
118 if (!acl)
119 return;
120
121 struct AttrColor *ac = NULL;
122 struct AttrColor *tmp = NULL;
123 TAILQ_FOREACH_SAFE(ac, acl, entries, tmp)
124 {
125 TAILQ_REMOVE(acl, ac, entries);
126 attr_color_free(&ac);
127 }
128}
void attr_color_free(struct AttrColor **ptr)
Free an AttrColor.
Definition attr.c:68
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition queue.h:792
#define TAILQ_REMOVE(head, elm, field)
Definition queue.h:901
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attr_color_list_find()

struct AttrColor * attr_color_list_find ( struct AttrColorList * acl,
color_t fg,
color_t bg,
int attrs )

Find an AttrColor in a list.

Parameters
aclList to search
fgForeground colour
bgBackground colour
attrsAttributes, e.g. A_UNDERLINE
Return values
ptrMatching AttrColor

Definition at line 138 of file attr.c.

140{
141 if (!acl)
142 return NULL;
143
144 struct AttrColor *ac = NULL;
145 TAILQ_FOREACH(ac, acl, entries)
146 {
147 if (ac->attrs != attrs)
148 continue;
149
150 struct CursesColor *cc = ac->curses_color;
151 if (!cc)
152 continue;
153
154 if ((cc->fg == fg) && (cc->bg == bg))
155 return ac;
156 }
157 return NULL;
158}
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
Colour in the ncurses palette.
Definition curses2.h:41
color_t fg
Foreground colour.
Definition curses2.h:42
color_t bg
Background colour.
Definition curses2.h:43
+ Here is the caller graph for this function:

◆ attr_color_overwrite()

void attr_color_overwrite ( struct AttrColor * ac_old,
const struct AttrColor * ac_new )

Update an AttrColor in-place.

Parameters
ac_oldAttrColor to overwrite
ac_newAttrColor to copy

Definition at line 394 of file attr.c.

395{
396 if (!ac_old || !ac_new)
397 return;
398
399 color_t fg = ac_new->fg.color;
400 color_t bg = ac_new->bg.color;
401 int attrs = ac_new->attrs;
402
403 modify_color_by_prefix(ac_new->fg.prefix, true, &fg, &attrs);
404 modify_color_by_prefix(ac_new->bg.prefix, false, &bg, &attrs);
405
406#ifdef NEOMUTT_DIRECT_COLORS
407 if ((ac_new->fg.type == CT_SIMPLE) || (ac_new->fg.type == CT_PALETTE))
409 else if (fg < 8)
410 fg = 8;
411 if ((ac_new->bg.type == CT_SIMPLE) || (ac_new->bg.type == CT_PALETTE))
413 else if (bg < 8)
414 bg = 8;
415#endif
416
417 struct CursesColor *cc = curses_color_new(fg, bg);
419 ac_old->fg = ac_new->fg;
420 ac_old->bg = ac_new->bg;
421 ac_old->attrs = attrs;
422 ac_old->curses_color = cc;
423}
color_t color_xterm256_to_24bit(const color_t color)
Convert a xterm color to its RGB value.
Definition attr.c:319
void modify_color_by_prefix(enum ColorPrefix prefix, bool is_fg, color_t *col, int *attrs)
Modify a colour/attributes based on a prefix, e.g.
Definition attr.c:210
int32_t color_t
Type for 24-bit colour value.
Definition curses2.h:31
struct CursesColor * curses_color_new(color_t fg, color_t bg)
Create a new CursesColor.
Definition curses.c:151
+ Here is the call graph for this function:
+ Here is the caller graph for this function: