NeoMutt  2024-04-25-102-g19653a
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, 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   
)

◆ 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 48 of file attr.c.

49{
50 if (!ac)
51 return;
52
53 if (ac->curses_color)
54 color_debug(LL_DEBUG5, "clear %p\n", (void *) ac);
56
57 memset(&ac->fg, 0, sizeof(ac->fg));
58 memset(&ac->bg, 0, sizeof(ac->bg));
59
62 ac->attrs = A_NORMAL;
63}
#define COLOR_DEFAULT
Definition: color.h:100
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:53
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
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 166 of file attr.c.

167{
168 if (ac)
169 return *ac;
170 else
171 return (struct AttrColor){ 0 };
172}
A curses colour and its attributes.
Definition: attr.h:66
+ 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 69 of file attr.c.

70{
71 if (!ptr || !*ptr)
72 return;
73
74 struct AttrColor *ac = *ptr;
75 if (ac->ref_count > 1)
76 {
77 ac->ref_count--;
78 *ptr = NULL;
79 return;
80 }
81
83 FREE(ptr);
84}
void attr_color_clear(struct AttrColor *ac)
Free the contents of an AttrColor.
Definition: attr.c:48
#define FREE(x)
Definition: memory.h:45
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 179 of file attr.c.

180{
181 if (!ac)
182 return false;
183
184 return ((ac->attrs != A_NORMAL) || ac->curses_color);
185}
+ 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 193 of file attr.c.

194{
195 if ((!ac1) ^ (!ac2)) // One is set, but not the other
196 return false;
197
198 if (!ac1) // Two empty colours match
199 return true;
200
201 return ((ac1->curses_color == ac2->curses_color) && (ac1->attrs == ac2->attrs));
202}
+ 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 90 of file attr.c.

91{
92 struct AttrColor *ac = mutt_mem_calloc(1, sizeof(*ac));
93
95 ac->fg.type = CT_SIMPLE;
97
99 ac->bg.type = CT_SIMPLE;
101
102 ac->attrs = A_NORMAL;
103
104 ac->ref_count = 1;
105
106 return ac;
107}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
enum ColorType type
Type of Colour.
Definition: attr.h:58
enum ColorPrefix prefix
Optional Colour Modifier.
Definition: attr.h:59
+ Here is the call graph for this function:
+ 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 117 of file attr.c.

118{
119 if (!acl)
120 return;
121
122 struct AttrColor *ac = NULL;
123 struct AttrColor *tmp = NULL;
124 TAILQ_FOREACH_SAFE(ac, acl, entries, tmp)
125 {
126 TAILQ_REMOVE(acl, ac, entries);
127 attr_color_free(&ac);
128 }
129}
void attr_color_free(struct AttrColor **ptr)
Free an AttrColor.
Definition: attr.c:69
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
+ 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 139 of file attr.c.

141{
142 if (!acl)
143 return NULL;
144
145 struct AttrColor *ac = NULL;
146 TAILQ_FOREACH(ac, acl, entries)
147 {
148 if (ac->attrs != attrs)
149 continue;
150
151 struct CursesColor *cc = ac->curses_color;
152 if (!cc)
153 continue;
154
155 if ((cc->fg == fg) && (cc->bg == bg))
156 return ac;
157 }
158 return NULL;
159}
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
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,
struct AttrColor ac_new 
)

Update an AttrColor in-place.

Parameters
ac_oldAttrColor to overwrite
ac_newAttrColor to copy

Definition at line 395 of file attr.c.

396{
397 if (!ac_old || !ac_new)
398 return;
399
400 color_t fg = ac_new->fg.color;
401 color_t bg = ac_new->bg.color;
402 int attrs = ac_new->attrs;
403
404 modify_color_by_prefix(ac_new->fg.prefix, true, &fg, &attrs);
405 modify_color_by_prefix(ac_new->bg.prefix, false, &bg, &attrs);
406
407#ifdef NEOMUTT_DIRECT_COLORS
408 if ((ac_new->fg.type == CT_SIMPLE) || (ac_new->fg.type == CT_PALETTE))
410 else if (fg < 8)
411 fg = 8;
412 if ((ac_new->bg.type == CT_SIMPLE) || (ac_new->bg.type == CT_PALETTE))
414 else if (bg < 8)
415 bg = 8;
416#endif
417
418 struct CursesColor *cc = curses_color_new(fg, bg);
420 ac_old->fg = ac_new->fg;
421 ac_old->bg = ac_new->bg;
422 ac_old->attrs = attrs;
423 ac_old->curses_color = cc;
424}
color_t color_xterm256_to_24bit(const color_t color)
Convert a xterm color to its RGB value.
Definition: attr.c:320
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:211
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: