NeoMutt  2021-10-29-43-g6b8931
Teaching an old dog new tricks
DOXYGEN
lib.h File Reference

Color and attribute parsing. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "color.h"
#include "command2.h"
#include "notify2.h"
#include "quoted.h"
#include "regex4.h"
#include "simple2.h"
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool mutt_color_is_header (enum ColorId color_id)
 
int mutt_color_alloc (uint32_t fg, uint32_t bg)
 Allocate a colour pair. More...
 
int mutt_color_combine (uint32_t fg_attr, uint32_t bg_attr)
 Combine two colours. More...
 
void mutt_color_free (uint32_t fg, uint32_t bg)
 Free a colour. More...
 
void mutt_colors_init (void)
 Initialize colours. More...
 
void mutt_colors_cleanup (void)
 Cleanup all the colours. More...
 
void colors_clear (void)
 Reset all the colours. More...
 

Detailed Description

Color and attribute parsing.

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

Function Documentation

◆ mutt_color_is_header()

bool mutt_color_is_header ( enum ColorId  color_id)

◆ mutt_color_alloc()

int mutt_color_alloc ( uint32_t  fg,
uint32_t  bg 
)

Allocate a colour pair.

Parameters
fgForeground colour ID
bgBackground colour ID
Return values
numCombined colour pair

Definition at line 188 of file color.c.

189 {
190  struct ColorList *p = UserColors;
191 
192  /* check to see if this color is already allocated to save space */
193  while (p)
194  {
195  if ((p->fg == fg) && (p->bg == bg))
196  {
197  (p->ref_count)++;
198  return COLOR_PAIR(p->index);
199  }
200  p = p->next;
201  }
202 
203  /* check to see if there are colors left */
204  if (++NumUserColors > COLOR_PAIRS)
205  return A_NORMAL;
206 
207  /* find the smallest available index (object) */
208  int i = 1;
209  while (true)
210  {
211  p = UserColors;
212  while (p)
213  {
214  if (p->index == i)
215  break;
216  p = p->next;
217  }
218  if (!p)
219  break;
220  i++;
221  }
222 
223  /* Check for pair overflow too.
224  * We are currently using init_pair(), which only accepts size short. */
225  if (i > SHRT_MAX)
226  return (0);
227 
228  p = mutt_mem_malloc(sizeof(struct ColorList));
229  p->next = UserColors;
230  UserColors = p;
231 
232  p->index = i;
233  p->ref_count = 1;
234  p->bg = bg;
235  p->fg = fg;
236 
237  if (fg == COLOR_DEFAULT)
238  fg = COLOR_UNSET;
239  if (bg == COLOR_DEFAULT)
240  bg = COLOR_UNSET;
241  init_pair(i, fg, bg);
242 
243  mutt_debug(LL_DEBUG3, "Color pairs used so far: %d\n", NumUserColors);
244 
245  return COLOR_PAIR(p->index);
246 }
struct ColorList * UserColors
Array of user colours.
Definition: color.c:49
int NumUserColors
Number of user colours.
Definition: color.c:50
#define COLOR_DEFAULT
Definition: color.h:103
#define COLOR_UNSET
Definition: color.h:104
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG3
Log at debug level 3.
Definition: logging.h:42
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
A set of colors.
Definition: color.c:56
struct ColorList * next
Linked list.
Definition: color.c:63
short index
Index number.
Definition: color.c:61
uint32_t fg
Foreground colour.
Definition: color.c:59
uint32_t bg
Background colour.
Definition: color.c:60
short ref_count
Number of users.
Definition: color.c:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_combine()

int mutt_color_combine ( uint32_t  fg_attr,
uint32_t  bg_attr 
)

Combine two colours.

Parameters
fg_attrColour pair of foreground to use
bg_attrColour pair of background to use
Return values
numColour pair of combined colour

Definition at line 281 of file color.c.

282 {
283  uint32_t fg = COLOR_DEFAULT;
284  uint32_t bg = COLOR_DEFAULT;
285 
286  mutt_lookup_color(fg_attr, &fg, NULL);
287  mutt_lookup_color(bg_attr, NULL, &bg);
288 
289  if ((fg == COLOR_DEFAULT) && (bg == COLOR_DEFAULT))
290  return A_NORMAL;
291  return mutt_color_alloc(fg, bg);
292 }
static int mutt_lookup_color(short pair, uint32_t *fg, uint32_t *bg)
Get the colours from a colour pair.
Definition: color.c:256
int mutt_color_alloc(uint32_t fg, uint32_t bg)
Allocate a colour pair.
Definition: color.c:188
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_free()

void mutt_color_free ( uint32_t  fg,
uint32_t  bg 
)

Free a colour.

Parameters
fgForeground colour ID
bgBackground colour ID

If there are no more users, the resource will be freed.

Definition at line 109 of file color.c.

110 {
111  struct ColorList *q = NULL;
112 
113  struct ColorList *p = UserColors;
114  while (p)
115  {
116  if ((p->fg == fg) && (p->bg == bg))
117  {
118  (p->ref_count)--;
119  if (p->ref_count > 0)
120  return;
121 
122  NumUserColors--;
123  mutt_debug(LL_DEBUG1, "Color pairs used so far: %d\n", NumUserColors);
124 
125  if (p == UserColors)
126  {
128  FREE(&p);
129  return;
130  }
131  q = UserColors;
132  while (q)
133  {
134  if (q->next == p)
135  {
136  q->next = p->next;
137  FREE(&p);
138  return;
139  }
140  q = q->next;
141  }
142  /* can't get here */
143  }
144  p = p->next;
145  }
146 }
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ mutt_colors_init()

void mutt_colors_init ( void  )

Initialize colours.

Definition at line 172 of file color.c.

173 {
178 
179  start_color();
180 }
void color_notify_init(void)
Initialise the Colour notification.
Definition: notify.c:38
void regex_colors_init(void)
Initialise the Regex colours.
Definition: regex.c:95
void simple_colors_init(void)
Initialise the simple colour definitions.
Definition: simple.c:41
void quoted_colors_init(void)
Initialise the quoted-email colours.
Definition: quoted.c:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_colors_cleanup()

void mutt_colors_cleanup ( void  )

Cleanup all the colours.

Definition at line 163 of file color.c.

164 {
165  colors_clear();
167 }
void color_notify_free(void)
Free the Colour notification.
Definition: notify.c:47
void colors_clear(void)
Reset all the colours.
Definition: color.c:151
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ colors_clear()

void colors_clear ( void  )

Reset all the colours.

Definition at line 151 of file color.c.

152 {
156 
158 }
void regex_colors_clear(void)
Clear the Regex colours.
Definition: regex.c:111
void simple_colors_clear(void)
Reset the simple colour definitions.
Definition: simple.c:58
static void color_list_free(struct ColorList **ptr)
Free the list of curses colours.
Definition: color.c:85
void quoted_colors_clear(void)
Reset the quoted-email colours.
Definition: quoted.c:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function: