NeoMutt  2024-04-16-36-g75b6fb
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 49 of file attr.c.

50{
51 if (!ac)
52 return;
53
54 if (ac->curses_color)
55 color_debug(LL_DEBUG5, "clear %p\n", (void *) ac);
57
58 memset(&ac->fg, 0, sizeof(ac->fg));
59 memset(&ac->bg, 0, sizeof(ac->bg));
60
63 ac->attrs = A_NORMAL;
64}
#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 167 of file attr.c.

168{
169 if (ac)
170 return *ac;
171 else
172 return (struct AttrColor){ 0 };
173}
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 70 of file attr.c.

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

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

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

92{
93 struct AttrColor *ac = mutt_mem_calloc(1, sizeof(*ac));
94
96 ac->fg.type = CT_SIMPLE;
98
100 ac->bg.type = CT_SIMPLE;
102
103 ac->attrs = A_NORMAL;
104
105 ac->ref_count = 1;
106
107 return ac;
108}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
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 118 of file attr.c.

119{
120 if (!acl)
121 return;
122
123 struct AttrColor *ac = NULL;
124 struct AttrColor *tmp = NULL;
125 TAILQ_FOREACH_SAFE(ac, acl, entries, tmp)
126 {
127 TAILQ_REMOVE(acl, ac, entries);
128 attr_color_free(&ac);
129 }
130}
void attr_color_free(struct AttrColor **ptr)
Free an AttrColor.
Definition: attr.c:70
#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 140 of file attr.c.

142{
143 if (!acl)
144 return NULL;
145
146 struct AttrColor *ac = NULL;
147 TAILQ_FOREACH(ac, acl, entries)
148 {
149 if (ac->attrs != attrs)
150 continue;
151
152 struct CursesColor *cc = ac->curses_color;
153 if (!cc)
154 continue;
155
156 if ((cc->fg == fg) && (cc->bg == bg))
157 return ac;
158 }
159 return NULL;
160}
#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 396 of file attr.c.

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