NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
attr.c File Reference

Colour and attributes. More...

#include "config.h"
#include <stddef.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "attr.h"
#include "curses2.h"
#include "debug.h"
+ Include dependency graph for attr.c:

Go to the source code of this file.

Functions

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

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.c.

Function Documentation

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

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}
void curses_color_free(struct CursesColor **ptr)
Free a CursesColor.
Definition: curses.c:116
int color_debug(enum LogLevel level, const char *format,...)
Write to the log file.
Definition: debug.c:44
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
int attrs
Text attributes, e.g. A_BOLD.
Definition: attr.h:37
struct CursesColor * curses_color
Underlying Curses colour.
Definition: attr.h:36
+ 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 59 of file attr.c.

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}
void attr_color_clear(struct AttrColor *ac)
Free the contents of an AttrColor.
Definition: attr.c:44
#define FREE(x)
Definition: memory.h:43
A curses colour and its attributes.
Definition: attr.h:35
short ref_count
Number of users.
Definition: attr.h:38
+ Here is the call graph for this function:
+ 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 80 of file attr.c.

81{
82 struct AttrColor *ac = mutt_mem_calloc(1, sizeof(*ac));
83
84 ac->ref_count = 1;
85
86 return ac;
87}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
+ 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 97 of file attr.c.

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}
void attr_color_free(struct AttrColor **ptr)
Free an AttrColor.
Definition: attr.c:59
#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,
uint32_t  fg,
uint32_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 119 of file attr.c.

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}
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
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
+ 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 146 of file attr.c.

147{
148 struct AttrColor copy = { 0 };
149 if (ac)
150 copy = *ac;
151
152 return copy;
153}
+ Here is the caller graph for this function:

◆ attr_color_is_set()

bool attr_color_is_set ( 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 160 of file attr.c.

161{
162 if (!ac)
163 return false;
164
165 return ((ac->attrs != 0) || ac->curses_color);
166}
+ 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 174 of file attr.c.

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}
+ Here is the caller graph for this function: