NeoMutt  2021-02-05-329-g9e03b7
Teaching an old dog new tricks
DOXYGEN
color.c File Reference

Color and attribute parsing. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "mutt.h"
#include "color.h"
#include "pattern/lib.h"
#include "context.h"
#include "init.h"
#include "mutt_commands.h"
#include "mutt_curses.h"
#include "mutt_globals.h"
#include "options.h"
+ Include dependency graph for color.c:

Go to the source code of this file.

Data Structures

struct  ColorList
 A set of colors. More...
 

Macros

#define COLOR_UNSET   UINT32_MAX
 
#define COLOR_QUOTES_MAX   10
 Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent) More...
 
#define COLOR_DEFAULT   (-2)
 
#define RGB24   (1U << 24)
 

Typedefs

typedef int(* parser_callback_t) (struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err)
 Prototype for a function to parse color config. More...
 

Functions

static struct ColorLineList * get_color_line_list (struct ColorLineList *cll)
 Sanitize and return a ColorLineList. More...
 
static void defs_init (void)
 Initialise the simple colour definitions. More...
 
static void defs_clear (void)
 Reset the simple colour definitions. More...
 
static void quotes_init (void)
 Initialise the quoted-email colours. More...
 
static void quotes_clear (void)
 Reset the quoted-email colours. More...
 
static void color_list_free (struct ColorList **ptr)
 Free the list of curses colours. More...
 
void mutt_color_free (uint32_t fg, uint32_t bg)
 Free a colour. More...
 
static void color_line_free (struct ColorLine **ptr, bool free_colors)
 Free a ColorLine. More...
 
static void color_line_list_clear (struct ColorLineList *list)
 Clear a list of colours. More...
 
static void colors_clear (void)
 Reset all the colours. More...
 
void mutt_colors_cleanup (void)
 Cleanup all the colours. More...
 
void mutt_colors_init (void)
 Initialize colours. More...
 
static struct ColorLinecolor_line_new (void)
 Create a new ColorLine. More...
 
int mutt_color_alloc (uint32_t fg, uint32_t bg)
 Allocate a colour pair. More...
 
static int mutt_lookup_color (short pair, uint32_t *fg, uint32_t *bg)
 Get the colours from a colour pair. More...
 
int mutt_color_combine (uint32_t fg_attr, uint32_t bg_attr)
 Combine two colours. More...
 
static enum CommandResult parse_color_name (const char *s, uint32_t *col, int *attr, bool is_fg, struct Buffer *err)
 Parse a colour name. More...
 
static enum CommandResult parse_object (struct Buffer *buf, struct Buffer *s, enum ColorId *obj, int *ql, struct Buffer *err)
 Identify a colour object. More...
 
static bool do_uncolor (struct Buffer *buf, struct Buffer *s, struct ColorLineList *cl, bool uncolor)
 Parse the 'uncolor' or 'unmono' command. More...
 
static enum CommandResult parse_uncolor (struct Buffer *buf, struct Buffer *s, struct Buffer *err, bool uncolor)
 Parse an 'uncolor' command. More...
 
enum CommandResult mutt_parse_uncolor (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'uncolor' command - Implements Command::parse() More...
 
enum CommandResult mutt_parse_unmono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmono' command - Implements Command::parse() More...
 
static enum CommandResult add_pattern (struct ColorLineList *top, const char *s, bool sensitive, uint32_t fg, uint32_t bg, int attr, struct Buffer *err, bool is_index, int match)
 Associate a colour to a pattern. More...
 
static enum CommandResult parse_color_pair (struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err)
 Parse a pair of colours - Implements parser_callback_t. More...
 
static enum CommandResult parse_attr_spec (struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err)
 Parse an attribute description - Implements parser_callback_t. More...
 
static int fgbgattr_to_color (int fg, int bg, int attr)
 Convert a foreground, background, attribute triplet into a colour. More...
 
static enum CommandResult parse_color (struct Buffer *buf, struct Buffer *s, struct Buffer *err, parser_callback_t callback, bool dry_run, bool color)
 Parse a 'color' command. More...
 
enum CommandResult mutt_parse_color (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'color' command - Implements Command::parse() More...
 
enum CommandResult mutt_parse_mono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'mono' command - Implements Command::parse() More...
 
int mutt_color (enum ColorId id)
 Return the color of an object. More...
 
struct ColorLineList * mutt_color_status_line (void)
 Return the ColorLineList for the status_line. More...
 
struct ColorLineList * mutt_color_index (void)
 Return the ColorLineList for the index. More...
 
struct ColorLineList * mutt_color_headers (void)
 Return the ColorLineList for headers. More...
 
struct ColorLineList * mutt_color_body (void)
 Return the ColorLineList for the body. More...
 
struct ColorLineList * mutt_color_attachments (void)
 Return the ColorLineList for the attachments. More...
 
struct ColorLineList * mutt_color_index_author (void)
 Return the ColorLineList for author in the index. More...
 
struct ColorLineList * mutt_color_index_flags (void)
 Return the ColorLineList for flags in the index. More...
 
struct ColorLineList * mutt_color_index_subject (void)
 Return the ColorLineList for subject in the index. More...
 
struct ColorLineList * mutt_color_index_tags (void)
 Return the ColorLineList for tags in the index. More...
 
int mutt_color_quote (int q)
 Return the color of a quote, cycling through the used quotes. More...
 
int mutt_color_quotes_used (void)
 Return the number of used quotes. More...
 
void mutt_color_observer_add (observer_t callback, void *global_data)
 Add an observer. More...
 
void mutt_color_observer_remove (observer_t callback, void *global_data)
 Remove an observer. More...
 
bool mutt_color_is_header (enum ColorId color_id)
 Colour is for an Email header. More...
 

Variables

struct {
   int   defs [MT_COLOR_MAX]
 Array of all fixed colours, see enum ColorId. More...
 
   struct ColorLineList   attach_list
 List of colours applied to the attachment headers. More...
 
   struct ColorLineList   body_list
 List of colours applied to the email body. More...
 
   struct ColorLineList   hdr_list
 List of colours applied to the email headers. More...
 
   struct ColorLineList   index_author_list
 List of colours applied to the author in the index. More...
 
   struct ColorLineList   index_flags_list
 List of colours applied to the flags in the index. More...
 
   struct ColorLineList   index_list
 List of default colours applied to the index. More...
 
   struct ColorLineList   index_subject_list
 List of colours applied to the subject in the index. More...
 
   struct ColorLineList   index_tag_list
 List of colours applied to tags in the index. More...
 
   struct ColorLineList   status_list
 List of colours applied to the status bar. More...
 
   int   quotes [COLOR_QUOTES_MAX]
 Array of colours for quoted email text. More...
 
   int   quotes_used
 Number of colours for quoted email text. More...
 
   struct ColorList *   user_colors
 
   int   num_user_colors
 
   struct Notify *   notify
 Notifications: ColorId, EventColor. More...
 
Colors
 Wrapper for all the colours. More...
 
static const struct Mapping ColorNames []
 
const struct Mapping Fields []
 
const struct Mapping ComposeFields []
 

Detailed Description

Color and attribute parsing.

Authors
  • Michael R. Elkins
  • R Primus

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

Macro Definition Documentation

◆ COLOR_UNSET

#define COLOR_UNSET   UINT32_MAX

Definition at line 52 of file color.c.

◆ COLOR_QUOTES_MAX

#define COLOR_QUOTES_MAX   10

Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)

Definition at line 53 of file color.c.

◆ COLOR_DEFAULT

#define COLOR_DEFAULT   (-2)

Definition at line 128 of file color.c.

◆ RGB24

#define RGB24   (1U << 24)

Definition at line 135 of file color.c.

Typedef Documentation

◆ parser_callback_t

typedef int(* parser_callback_t) (struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err)

Prototype for a function to parse color config.

Parameters
[in]bufTemporary Buffer space
[in]sBuffer containing string to be parsed
[out]fgForeground colour (set to -1)
[out]bgBackground colour (set to -1)
[out]attrAttribute flags
[out]errBuffer for error messages
Return values
0Success
-1Error

Definition at line 123 of file color.c.

Function Documentation

◆ get_color_line_list()

static struct ColorLineList* get_color_line_list ( struct ColorLineList *  cll)
static

Sanitize and return a ColorLineList.

Parameters
cllA ColorLineList
Return values
cllThe ColorLineList

Definition at line 103 of file color.c.

104 {
105  if (cll->stqh_last == NULL)
106  {
107  STAILQ_INIT(cll);
108  }
109  return cll;
110 }
#define STAILQ_INIT(head)
Definition: queue.h:369
+ Here is the caller graph for this function:

◆ defs_init()

static void defs_init ( void  )
static

Initialise the simple colour definitions.

Definition at line 216 of file color.c.

217 {
218  memset(Colors.defs, A_NORMAL, MT_COLOR_MAX * sizeof(int));
219 
220  // Set some defaults
221  Colors.defs[MT_COLOR_INDICATOR] = A_REVERSE;
222  Colors.defs[MT_COLOR_MARKERS] = A_REVERSE;
223  Colors.defs[MT_COLOR_SEARCH] = A_REVERSE;
224 #ifdef USE_SIDEBAR
225  Colors.defs[MT_COLOR_SIDEBAR_HIGHLIGHT] = A_UNDERLINE;
226 #endif
227  Colors.defs[MT_COLOR_STATUS] = A_REVERSE;
228 }
Select cursor.
Definition: color.h:67
Pager: markers, line continuation.
Definition: color.h:55
Status bar (takes a pattern)
Definition: color.h:75
Selected item in list.
Definition: color.h:54
Pager: search matches.
Definition: color.h:63
static struct @2 Colors
Wrapper for all the colours.
+ Here is the caller graph for this function:

◆ defs_clear()

static void defs_clear ( void  )
static

Reset the simple colour definitions.

Definition at line 233 of file color.c.

234 {
235  memset(Colors.defs, A_NORMAL, MT_COLOR_MAX * sizeof(int));
236 }
static struct @2 Colors
Wrapper for all the colours.
+ Here is the caller graph for this function:

◆ quotes_init()

static void quotes_init ( void  )
static

Initialise the quoted-email colours.

Definition at line 241 of file color.c.

242 {
243  memset(Colors.quotes, A_NORMAL, COLOR_QUOTES_MAX * sizeof(int));
244  Colors.quotes_used = 0;
245 }
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: color.c:53
static struct @2 Colors
Wrapper for all the colours.
+ Here is the caller graph for this function:

◆ quotes_clear()

static void quotes_clear ( void  )
static

Reset the quoted-email colours.

Definition at line 250 of file color.c.

251 {
252  memset(Colors.quotes, A_NORMAL, COLOR_QUOTES_MAX * sizeof(int));
253  Colors.quotes_used = 0;
254 }
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: color.c:53
static struct @2 Colors
Wrapper for all the colours.
+ Here is the caller graph for this function:

◆ color_list_free()

static void color_list_free ( struct ColorList **  ptr)
static

Free the list of curses colours.

Parameters
ptrColours

Definition at line 260 of file color.c.

261 {
262  if (!ptr || !*ptr)
263  return;
264 
265  struct ColorList *cl = *ptr;
266  struct ColorList *next = NULL;
267 
268  while (cl)
269  {
270  next = cl->next;
271  FREE(&cl);
272  cl = next;
273  }
274  *ptr = NULL;
275 }
struct ColorList * next
Definition: color.c:67
A set of colors.
Definition: color.c:59
#define FREE(x)
Definition: memory.h:40
+ 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 284 of file color.c.

285 {
286  struct ColorList *q = NULL;
287 
288  struct ColorList *p = Colors.user_colors;
289  while (p)
290  {
291  if ((p->fg == fg) && (p->bg == bg))
292  {
293  (p->count)--;
294  if (p->count > 0)
295  return;
296 
297  Colors.num_user_colors--;
298  mutt_debug(LL_DEBUG1, "Color pairs used so far: %d\n", Colors.num_user_colors);
299 
300  if (p == Colors.user_colors)
301  {
302  Colors.user_colors = Colors.user_colors->next;
303  FREE(&p);
304  return;
305  }
306  q = Colors.user_colors;
307  while (q)
308  {
309  if (q->next == p)
310  {
311  q->next = p->next;
312  FREE(&p);
313  return;
314  }
315  q = q->next;
316  }
317  /* can't get here */
318  }
319  p = p->next;
320  }
321 }
short count
Definition: color.c:66
uint32_t bg
Definition: color.c:64
struct ColorList * next
Definition: color.c:67
uint32_t fg
Definition: color.c:63
Log at debug level 1.
Definition: logging.h:40
A set of colors.
Definition: color.c:59
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
static struct @2 Colors
Wrapper for all the colours.
+ Here is the caller graph for this function:

◆ color_line_free()

static void color_line_free ( struct ColorLine **  ptr,
bool  free_colors 
)
static

Free a ColorLine.

Parameters
ptrColorLine to free
free_colorsIf true, free its colours too

Definition at line 328 of file color.c.

329 {
330  if (!ptr || !*ptr)
331  return;
332 
333  struct ColorLine *cl = *ptr;
334 
335 #ifdef HAVE_COLOR
336  if (free_colors && (cl->fg != COLOR_UNSET) && (cl->bg != COLOR_UNSET))
337  mutt_color_free(cl->fg, cl->bg);
338 #endif
339 
340  regfree(&cl->regex);
342  FREE(&cl->pattern);
343  FREE(ptr);
344 }
#define COLOR_UNSET
Definition: color.c:52
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: color.h:104
char * pattern
Pattern to match.
Definition: color.h:103
uint32_t fg
Foreground colour.
Definition: color.h:105
uint32_t bg
Background colour.
Definition: color.h:106
regex_t regex
Compiled regex.
Definition: color.h:101
#define FREE(x)
Definition: memory.h:40
void mutt_color_free(uint32_t fg, uint32_t bg)
Free a colour.
Definition: color.c:284
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition: compile.c:1038
A regular expression and a color to highlight a line.
Definition: color.h:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ color_line_list_clear()

static void color_line_list_clear ( struct ColorLineList *  list)
static

Clear a list of colours.

Parameters
listColorLine List

Definition at line 350 of file color.c.

351 {
352  struct ColorLine *np = NULL, *tmp = NULL;
353  STAILQ_FOREACH_SAFE(np, list, entries, tmp)
354  {
355  STAILQ_REMOVE(list, np, ColorLine, entries);
356  color_line_free(&np, true);
357  }
358 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
static void color_line_free(struct ColorLine **ptr, bool free_colors)
Free a ColorLine.
Definition: color.c:328
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
A regular expression and a color to highlight a line.
Definition: color.h:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ colors_clear()

static void colors_clear ( void  )
static

Reset all the colours.

Definition at line 363 of file color.c.

364 {
374 
375  defs_clear();
376  quotes_clear();
377 
378  color_list_free(&Colors.user_colors);
379 }
struct ColorLineList * mutt_color_index_subject(void)
Return the ColorLineList for subject in the index.
Definition: color.c:1465
struct ColorLineList * mutt_color_index_flags(void)
Return the ColorLineList for flags in the index.
Definition: color.c:1456
struct ColorLineList * mutt_color_index(void)
Return the ColorLineList for the index.
Definition: color.c:1411
struct ColorLineList * mutt_color_index_tags(void)
Return the ColorLineList for tags in the index.
Definition: color.c:1474
static void quotes_clear(void)
Reset the quoted-email colours.
Definition: color.c:250
struct ColorLineList * mutt_color_attachments(void)
Return the ColorLineList for the attachments.
Definition: color.c:1438
struct ColorLineList * mutt_color_index_author(void)
Return the ColorLineList for author in the index.
Definition: color.c:1447
struct ColorLineList * mutt_color_body(void)
Return the ColorLineList for the body.
Definition: color.c:1429
static void defs_clear(void)
Reset the simple colour definitions.
Definition: color.c:233
struct ColorLineList * mutt_color_status_line(void)
Return the ColorLineList for the status_line.
Definition: color.c:1402
struct ColorLineList * mutt_color_headers(void)
Return the ColorLineList for headers.
Definition: color.c:1420
static void color_line_list_clear(struct ColorLineList *list)
Clear a list of colours.
Definition: color.c:350
static struct @2 Colors
Wrapper for all the colours.
static void color_list_free(struct ColorList **ptr)
Free the list of curses colours.
Definition: color.c:260
+ 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 384 of file color.c.

385 {
386  colors_clear();
387  notify_free(&Colors.notify);
388 }
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
static void colors_clear(void)
Reset all the colours.
Definition: color.c:363
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_colors_init()

void mutt_colors_init ( void  )

Initialize colours.

Definition at line 393 of file color.c.

394 {
395  Colors.notify = notify_new();
396 
397  quotes_init();
398  defs_init();
399 
400 #ifdef HAVE_COLOR
401  start_color();
402 #endif
403 
405 }
static void defs_init(void)
Initialise the simple colour definitions.
Definition: color.c:216
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
static void quotes_init(void)
Initialise the quoted-email colours.
Definition: color.c:241
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ color_line_new()

static struct ColorLine* color_line_new ( void  )
static

Create a new ColorLine.

Return values
ptrNewly allocated ColorLine

Definition at line 411 of file color.c.

412 {
413  struct ColorLine *cl = mutt_mem_calloc(1, sizeof(struct ColorLine));
414 
415  cl->fg = COLOR_UNSET;
416  cl->bg = COLOR_UNSET;
417 
418  return cl;
419 }
#define COLOR_UNSET
Definition: color.c:52
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
uint32_t fg
Foreground colour.
Definition: color.h:105
uint32_t bg
Background colour.
Definition: color.h:106
A regular expression and a color to highlight a line.
Definition: color.h:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 478 of file color.c.

479 {
480 #ifdef USE_SLANG_CURSES
481  char fgc[128], bgc[128];
482 #endif
483  struct ColorList *p = Colors.user_colors;
484 
485  /* check to see if this color is already allocated to save space */
486  while (p)
487  {
488  if ((p->fg == fg) && (p->bg == bg))
489  {
490  (p->count)++;
491  return COLOR_PAIR(p->index);
492  }
493  p = p->next;
494  }
495 
496  /* check to see if there are colors left */
497  if (++Colors.num_user_colors > COLOR_PAIRS)
498  return A_NORMAL;
499 
500  /* find the smallest available index (object) */
501  int i = 1;
502  while (true)
503  {
504  p = Colors.user_colors;
505  while (p)
506  {
507  if (p->index == i)
508  break;
509  p = p->next;
510  }
511  if (!p)
512  break;
513  i++;
514  }
515 
516  p = mutt_mem_malloc(sizeof(struct ColorList));
517  p->next = Colors.user_colors;
518  Colors.user_colors = p;
519 
520  p->index = i;
521  p->count = 1;
522  p->bg = bg;
523  p->fg = fg;
524 
525 #ifdef USE_SLANG_CURSES
526  /*
527  * If using s-lang always use SLtt_set_color which allows using truecolor
528  * values. Note that I couldn't figure out if s-lang somehow reports
529  * truecolor support.
530  */
531  SLtt_set_color(i, NULL, get_color_name(fgc, sizeof(fgc), fg),
532  get_color_name(bgc, sizeof(bgc), bg));
533 #else
534 #ifdef HAVE_USE_DEFAULT_COLORS
535  if (fg == COLOR_DEFAULT)
536  fg = COLOR_UNSET;
537  if (bg == COLOR_DEFAULT)
538  bg = COLOR_UNSET;
539 #endif
540  init_pair(i, fg, bg);
541 #endif
542 
543  mutt_debug(LL_DEBUG3, "Color pairs used so far: %d\n", Colors.num_user_colors);
544 
545  return COLOR_PAIR(p->index);
546 }
#define COLOR_UNSET
Definition: color.c:52
#define COLOR_DEFAULT
Definition: color.c:128
short count
Definition: color.c:66
short index
Definition: color.c:65
uint32_t bg
Definition: color.c:64
struct ColorList * next
Definition: color.c:67
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
uint32_t fg
Definition: color.c:63
A set of colors.
Definition: color.c:59
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
Log at debug level 3.
Definition: logging.h:42
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_lookup_color()

static int mutt_lookup_color ( short  pair,
uint32_t *  fg,
uint32_t *  bg 
)
static

Get the colours from a colour pair.

Parameters
[in]pairColour pair
[out]fgForeground colour (OPTIONAL)
[out]bgBackground colour (OPTIONAL)
Return values
0Success
-1Error

Definition at line 556 of file color.c.

557 {
558  struct ColorList *p = Colors.user_colors;
559 
560  while (p)
561  {
562  if (COLOR_PAIR(p->index) == pair)
563  {
564  if (fg)
565  *fg = p->fg;
566  if (bg)
567  *bg = p->bg;
568  return 0;
569  }
570  p = p->next;
571  }
572  return -1;
573 }
short index
Definition: color.c:65
uint32_t bg
Definition: color.c:64
struct ColorList * next
Definition: color.c:67
uint32_t fg
Definition: color.c:63
A set of colors.
Definition: color.c:59
static struct @2 Colors
Wrapper for all the colours.
+ 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 581 of file color.c.

582 {
583  uint32_t fg = COLOR_DEFAULT;
584  uint32_t bg = COLOR_DEFAULT;
585 
586  mutt_lookup_color(fg_attr, &fg, NULL);
587  mutt_lookup_color(bg_attr, NULL, &bg);
588 
589  if ((fg == COLOR_DEFAULT) && (bg == COLOR_DEFAULT))
590  return A_NORMAL;
591  return mutt_color_alloc(fg, bg);
592 }
#define COLOR_DEFAULT
Definition: color.c:128
int mutt_color_alloc(uint32_t fg, uint32_t bg)
Allocate a colour pair.
Definition: color.c:478
static int mutt_lookup_color(short pair, uint32_t *fg, uint32_t *bg)
Get the colours from a colour pair.
Definition: color.c:556
uint32_t bg
Definition: color.c:64
uint32_t fg
Definition: color.c:63
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_color_name()

static enum CommandResult parse_color_name ( const char *  s,
uint32_t *  col,
int *  attr,
bool  is_fg,
struct Buffer err 
)
static

Parse a colour name.

Parameters
[in]sString to parse
[out]colNumber for 'colorNNN' colours
[out]attrAttribute flags, e.g. A_BOLD
[in]is_fgtrue if this is a foreground colour
[out]errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Parse a colour name, such as "red", "brightgreen", "color123".

Definition at line 607 of file color.c.

609 {
610  char *eptr = NULL;
611  bool is_alert = false, is_bright = false, is_light = false;
612  int clen;
613 
614  if ((clen = mutt_istr_startswith(s, "bright")))
615  {
616  is_bright = true;
617  s += clen;
618  }
619  else if ((clen = mutt_istr_startswith(s, "alert")))
620  {
621  is_alert = true;
622  is_bright = true;
623  s += clen;
624  }
625  else if ((clen = mutt_istr_startswith(s, "light")))
626  {
627  is_light = true;
628  s += clen;
629  }
630 
631  /* allow aliases for xterm color resources */
632  if ((clen = mutt_istr_startswith(s, "color")))
633  {
634  s += clen;
635  *col = strtoul(s, &eptr, 10);
636  if ((*s == '\0') || (*eptr != '\0') || ((*col >= COLORS) && !OptNoCurses && has_colors()))
637  {
638  mutt_buffer_printf(err, _("%s: color not supported by term"), s);
639  return MUTT_CMD_ERROR;
640  }
641  }
642 #ifdef HAVE_DIRECTCOLOR
643  else if (*s == '#')
644  {
645  s += 1;
646  *col = strtoul(s, &eptr, 16);
647  if ((*s == '\0') || (*eptr != '\0') || ((*col == COLOR_UNSET) && !OptNoCurses && has_colors()))
648  {
649  snprintf(err->data, err->dsize, _("%s: color not supported by term"), s);
650  return MUTT_CMD_ERROR;
651  }
652  *col |= RGB24;
653  }
654 #endif
655  else if ((*col = mutt_map_get_value(s, ColorNames)) == -1)
656  {
657  mutt_buffer_printf(err, _("%s: no such color"), s);
658  return MUTT_CMD_WARNING;
659  }
660 
661  if (is_bright || is_light)
662  {
663  if (is_alert)
664  {
665  *attr |= A_BOLD;
666  *attr |= A_BLINK;
667  }
668  else if (is_fg)
669  {
670  if ((COLORS >= 16) && is_light)
671  {
672  if (*col <= 7)
673  {
674  /* Advance the color 0-7 by 8 to get the light version */
675  *col += 8;
676  }
677  }
678  else
679  {
680  *attr |= A_BOLD;
681  }
682  }
683  else if (!(*col & RGB24))
684  {
685  if (COLORS >= 16)
686  {
687  if (*col <= 7)
688  {
689  /* Advance the color 0-7 by 8 to get the light version */
690  *col += 8;
691  }
692  }
693  }
694  }
695 
696  return MUTT_CMD_SUCCESS;
697 }
#define COLOR_UNSET
Definition: color.c:52
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define _(a)
Definition: message.h:28
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define RGB24
Definition: color.c:135
size_t dsize
Length of data.
Definition: buffer.h:37
static const struct Mapping ColorNames[]
Definition: color.c:138
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_object()

static enum CommandResult parse_object ( struct Buffer buf,
struct Buffer s,
enum ColorId obj,
int *  ql,
struct Buffer err 
)
static

Identify a colour object.

Parameters
[in]bufTemporary Buffer space
[in]sBuffer containing string to be parsed
[out]objObject type, e.g. MT_COLOR_TILDE
[out]qlQuote level, if type MT_COLOR_QUOTED
[out]errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 709 of file color.c.

711 {
712  int rc;
713 
714  if (mutt_str_startswith(buf->data, "quoted") != 0)
715  {
716  int val = 0;
717  if (buf->data[6] != '\0')
718  {
719  rc = mutt_str_atoi(buf->data + 6, &val);
720  if ((rc != 0) || (val > COLOR_QUOTES_MAX))
721  {
722  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
723  return MUTT_CMD_WARNING;
724  }
725  }
726 
727  *ql = val;
728  *obj = MT_COLOR_QUOTED;
729  return MUTT_CMD_SUCCESS;
730  }
731 
732  if (mutt_istr_equal(buf->data, "compose"))
733  {
734  if (!MoreArgs(s))
735  {
736  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
737  return MUTT_CMD_WARNING;
738  }
739 
741 
743  if (rc == -1)
744  {
745  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
746  return MUTT_CMD_WARNING;
747  }
748 
749  *obj = rc;
750  return MUTT_CMD_SUCCESS;
751  }
752 
753  rc = mutt_map_get_value(buf->data, Fields);
754  if (rc == -1)
755  {
756  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
757  return MUTT_CMD_WARNING;
758  }
759 
760  *obj = rc;
761  return MUTT_CMD_SUCCESS;
762 }
int mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: string.c:252
const struct Mapping ComposeFields[]
Definition: color.c:203
#define _(a)
Definition: message.h:28
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: color.c:53
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Pager: quoted text.
Definition: color.h:62
#define MoreArgs(buf)
Definition: buffer.h:40
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:160
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
const struct Mapping Fields[]
Definition: color.c:156
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_uncolor()

static bool do_uncolor ( struct Buffer buf,
struct Buffer s,
struct ColorLineList *  cl,
bool  uncolor 
)
static

Parse the 'uncolor' or 'unmono' command.

Parameters
bufBuffer for temporary storage
sBuffer containing the uncolor command
clList of existing colours
uncolorIf true, 'uncolor', else 'unmono'
Return values
trueA colour was freed

Definition at line 772 of file color.c.

774 {
775  struct ColorLine *np = NULL, *prev = NULL;
776  bool rc = false;
777 
778  do
779  {
781  if (mutt_str_equal("*", buf->data))
782  {
783  rc = STAILQ_FIRST(cl);
785  return rc;
786  }
787 
788  prev = NULL;
789  STAILQ_FOREACH(np, cl, entries)
790  {
791  if (mutt_str_equal(buf->data, np->pattern))
792  {
793  rc = true;
794 
795  mutt_debug(LL_DEBUG1, "Freeing pattern \"%s\" from user_colors\n", buf->data);
796  if (prev)
797  STAILQ_REMOVE_AFTER(cl, prev, entries);
798  else
799  STAILQ_REMOVE_HEAD(cl, entries);
800  color_line_free(&np, uncolor);
801  break;
802  }
803  prev = np;
804  }
805  } while (MoreArgs(s));
806 
807  return rc;
808 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
char * pattern
Pattern to match.
Definition: color.h:103
#define STAILQ_REMOVE_HEAD(head, field)
Definition: queue.h:419
#define MoreArgs(buf)
Definition: buffer.h:40
static void color_line_free(struct ColorLine **ptr, bool free_colors)
Free a ColorLine.
Definition: color.c:328
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
Log at debug level 1.
Definition: logging.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define STAILQ_FIRST(head)
Definition: queue.h:347
#define STAILQ_REMOVE_AFTER(head, elm, field)
Definition: queue.h:413
A regular expression and a color to highlight a line.
Definition: color.h:99
static void color_line_list_clear(struct ColorLineList *list)
Clear a list of colours.
Definition: color.c:350
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_uncolor()

static enum CommandResult parse_uncolor ( struct Buffer buf,
struct Buffer s,
struct Buffer err,
bool  uncolor 
)
static

Parse an 'uncolor' command.

Parameters
bufTemporary Buffer space
sBuffer containing string to be parsed
errBuffer for error messages
uncolorIf true, 'uncolor', else 'unmono'
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

usage:

  • uncolor index pattern [pattern...]
  • unmono index pattern [pattern...]

Definition at line 822 of file color.c.

824 {
826 
827  if (mutt_str_equal(buf->data, "*"))
828  {
829  colors_clear();
830  struct EventColor ec = { MT_COLOR_MAX };
831  notify_send(Colors.notify, NT_COLOR, NT_COLOR_RESET, &ec);
832  return MUTT_CMD_SUCCESS;
833  }
834 
835  unsigned int object = MT_COLOR_NONE;
836  int ql = 0;
837  enum CommandResult rc = parse_object(buf, s, &object, &ql, err);
838  if (rc != MUTT_CMD_SUCCESS)
839  return rc;
840 
841  if (object == -1)
842  {
843  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
844  return MUTT_CMD_ERROR;
845  }
846 
847  if (object == MT_COLOR_QUOTED)
848  {
849  Colors.quotes[ql] = A_NORMAL;
850  /* fallthrough to simple case */
851  }
852 
853  if ((object != MT_COLOR_ATTACH_HEADERS) && (object != MT_COLOR_BODY) &&
854  (object != MT_COLOR_HEADER) && (object != MT_COLOR_INDEX) &&
855  (object != MT_COLOR_INDEX_AUTHOR) && (object != MT_COLOR_INDEX_FLAGS) &&
856  (object != MT_COLOR_INDEX_SUBJECT) && (object != MT_COLOR_INDEX_TAG) &&
857  (object != MT_COLOR_STATUS))
858  {
859  // Simple colours
860  Colors.defs[object] = A_NORMAL;
861 
862  struct EventColor ec = { object };
863  notify_send(Colors.notify, NT_COLOR, NT_COLOR_RESET, &ec);
864  return MUTT_CMD_SUCCESS;
865  }
866 
867  if (!MoreArgs(s))
868  {
869  mutt_buffer_printf(err, _("%s: too few arguments"), uncolor ? "uncolor" : "unmono");
870  return MUTT_CMD_WARNING;
871  }
872 
873 #ifdef HAVE_COLOR
874  if (OptNoCurses || // running without curses
875  (uncolor && !has_colors()) || // parsing an uncolor command, and have no colors
876  (!uncolor && has_colors())) // parsing an unmono command, and have colors
877 #else
878  if (uncolor) // We don't even have colors compiled in
879 #endif
880  {
881  do
882  {
883  /* just eat the command, but don't do anything real about it */
885  } while (MoreArgs(s));
886 
887  return MUTT_CMD_SUCCESS;
888  }
889 
890  bool changed = false;
891  if (object == MT_COLOR_ATTACH_HEADERS)
892  changed |= do_uncolor(buf, s, mutt_color_attachments(), uncolor);
893  else if (object == MT_COLOR_BODY)
894  changed |= do_uncolor(buf, s, mutt_color_body(), uncolor);
895  else if (object == MT_COLOR_HEADER)
896  changed |= do_uncolor(buf, s, mutt_color_headers(), uncolor);
897  else if (object == MT_COLOR_INDEX)
898  changed |= do_uncolor(buf, s, mutt_color_index(), uncolor);
899  else if (object == MT_COLOR_INDEX_AUTHOR)
900  changed |= do_uncolor(buf, s, mutt_color_index_author(), uncolor);
901  else if (object == MT_COLOR_INDEX_FLAGS)
902  changed |= do_uncolor(buf, s, mutt_color_index_flags(), uncolor);
903  else if (object == MT_COLOR_INDEX_SUBJECT)
904  changed |= do_uncolor(buf, s, mutt_color_index_subject(), uncolor);
905  else if (object == MT_COLOR_INDEX_TAG)
906  changed |= do_uncolor(buf, s, mutt_color_index_tags(), uncolor);
907  else if (object == MT_COLOR_STATUS)
908  changed |= do_uncolor(buf, s, mutt_color_status_line(), uncolor);
909 
910  if (changed)
911  {
912  struct EventColor ec = { object };
913  notify_send(Colors.notify, NT_COLOR, NT_COLOR_RESET, &ec);
914  }
915 
916  return MUTT_CMD_SUCCESS;
917 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
MIME attachment test (takes a pattern)
Definition: color.h:43
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
An Event that happened to a Colour.
Definition: color.h:122
Pager: highlight body of message (takes a pattern)
Definition: color.h:44
struct ColorLineList * mutt_color_index_subject(void)
Return the ColorLineList for subject in the index.
Definition: color.c:1465
struct ColorLineList * mutt_color_index_flags(void)
Return the ColorLineList for flags in the index.
Definition: color.c:1456
struct ColorLineList * mutt_color_index(void)
Return the ColorLineList for the index.
Definition: color.c:1411
struct ColorLineList * mutt_color_index_tags(void)
Return the ColorLineList for tags in the index.
Definition: color.c:1474
#define _(a)
Definition: message.h:28
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Pager: quoted text.
Definition: color.h:62
Index: author field (takes a pattern)
Definition: color.h:82
#define MoreArgs(buf)
Definition: buffer.h:40
static enum CommandResult parse_object(struct Buffer *buf, struct Buffer *s, enum ColorId *obj, int *ql, struct Buffer *err)
Identify a colour object.
Definition: color.c:709
Message headers (takes a pattern)
Definition: color.h:53
Index: tag field (g, takes a pattern)
Definition: color.h:85
struct ColorLineList * mutt_color_attachments(void)
Return the ColorLineList for the attachments.
Definition: color.c:1438
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
struct ColorLineList * mutt_color_index_author(void)
Return the ColorLineList for author in the index.
Definition: color.c:1447
Status bar (takes a pattern)
Definition: color.h:75
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Color has been reset/removed.
Definition: color.h:135
static void colors_clear(void)
Reset all the colours.
Definition: color.c:363
struct ColorLineList * mutt_color_body(void)
Return the ColorLineList for the body.
Definition: color.c:1429
Success: Command worked.
Definition: mutt_commands.h:38
Index: subject field (takes a pattern)
Definition: color.h:84
Warning: Help given to the user.
Definition: mutt_commands.h:37
struct ColorLineList * mutt_color_status_line(void)
Return the ColorLineList for the status_line.
Definition: color.c:1402
static bool do_uncolor(struct Buffer *buf, struct Buffer *s, struct ColorLineList *cl, bool uncolor)
Parse the &#39;uncolor&#39; or &#39;unmono&#39; command.
Definition: color.c:772
Index: default colour (takes a pattern)
Definition: color.h:81
struct ColorLineList * mutt_color_headers(void)
Return the ColorLineList for headers.
Definition: color.c:1420
Index: flags field (takes a pattern)
Definition: color.h:83
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
static struct @2 Colors
Wrapper for all the colours.
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:156
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_uncolor()

enum CommandResult mutt_parse_uncolor ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'uncolor' command - Implements Command::parse()

Definition at line 923 of file color.c.

925 {
926  if (OptNoCurses || !has_colors())
927  {
928  *s->dptr = '\0'; /* fake that we're done parsing */
929  return MUTT_CMD_SUCCESS;
930  }
931  return parse_uncolor(buf, s, err, true);
932 }
static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, struct Buffer *err, bool uncolor)
Parse an &#39;uncolor&#39; command.
Definition: color.c:822
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
char * dptr
Current read/write position.
Definition: buffer.h:36
Success: Command worked.
Definition: mutt_commands.h:38
+ Here is the call graph for this function:

◆ mutt_parse_unmono()

enum CommandResult mutt_parse_unmono ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'unmono' command - Implements Command::parse()

Definition at line 938 of file color.c.

940 {
941  if (OptNoCurses || !has_colors())
942  {
943  *s->dptr = '\0'; /* fake that we're done parsing */
944  return MUTT_CMD_SUCCESS;
945  }
946  return parse_uncolor(buf, s, err, false);
947 }
static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, struct Buffer *err, bool uncolor)
Parse an &#39;uncolor&#39; command.
Definition: color.c:822
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
char * dptr
Current read/write position.
Definition: buffer.h:36
Success: Command worked.
Definition: mutt_commands.h:38
+ Here is the call graph for this function:

◆ add_pattern()

static enum CommandResult add_pattern ( struct ColorLineList *  top,
const char *  s,
bool  sensitive,
uint32_t  fg,
uint32_t  bg,
int  attr,
struct Buffer err,
bool  is_index,
int  match 
)
static

Associate a colour to a pattern.

Parameters
topList of existing colours
sString to match
sensitivetrue if the pattern case-sensitive
fgForeground colour ID
bgBackground colour ID
attrAttribute flags, e.g. A_BOLD
errBuffer for error messages
is_indextrue of this is for the index
matchNumber of regex subexpression to match (0 for entire pattern)
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

is_index used to store compiled pattern only for 'index' color object when called from mutt_parse_color()

Definition at line 965 of file color.c.

968 {
969  struct ColorLine *tmp = NULL;
970 
971  STAILQ_FOREACH(tmp, top, entries)
972  {
973  if ((sensitive && mutt_str_equal(s, tmp->pattern)) ||
974  (!sensitive && mutt_istr_equal(s, tmp->pattern)))
975  {
976  break;
977  }
978  }
979 
980  if (tmp)
981  {
982 #ifdef HAVE_COLOR
983  if ((fg != COLOR_UNSET) && (bg != COLOR_UNSET))
984  {
985  if ((tmp->fg != fg) || (tmp->bg != bg))
986  {
987  mutt_color_free(tmp->fg, tmp->bg);
988  tmp->fg = fg;
989  tmp->bg = bg;
990  attr |= mutt_color_alloc(fg, bg);
991  }
992  else
993  attr |= (tmp->pair & ~A_BOLD);
994  }
995 #endif /* HAVE_COLOR */
996  tmp->pair = attr;
997  }
998  else
999  {
1000  tmp = color_line_new();
1001  if (is_index)
1002  {
1003  struct Buffer *buf = mutt_buffer_pool_get();
1004  mutt_buffer_strcpy(buf, s);
1005  const char *const c_simple_search =
1006  cs_subset_string(NeoMutt->sub, "simple_search");
1007  mutt_check_simple(buf, NONULL(c_simple_search));
1010  if (!tmp->color_pattern)
1011  {
1012  color_line_free(&tmp, true);
1013  return MUTT_CMD_ERROR;
1014  }
1015  }
1016  else
1017  {
1018  uint16_t flags = 0;
1019  if (sensitive)
1020  flags = mutt_mb_is_lower(s) ? REG_ICASE : 0;
1021  else
1022  flags = REG_ICASE;
1023 
1024  const int r = REG_COMP(&tmp->regex, s, flags);
1025  if (r != 0)
1026  {
1027  regerror(r, &tmp->regex, err->data, err->dsize);
1028  color_line_free(&tmp, true);
1029  return MUTT_CMD_ERROR;
1030  }
1031  }
1032  tmp->pattern = mutt_str_dup(s);
1033  tmp->match = match;
1034 #ifdef HAVE_COLOR
1035  if ((fg != COLOR_UNSET) && (bg != COLOR_UNSET))
1036  {
1037  tmp->fg = fg;
1038  tmp->bg = bg;
1039  attr |= mutt_color_alloc(fg, bg);
1040  }
1041 #endif
1042  tmp->pair = attr;
1043  STAILQ_INSERT_HEAD(top, tmp, entries);
1044  }
1045 
1046  /* force re-caching of index colors */
1047  const struct Mailbox *m = ctx_mailbox(Context);
1048  if (is_index && m)
1049  {
1050  for (int i = 0; i < m->msg_count; i++)
1051  {
1052  struct Email *e = m->emails[i];
1053  if (!e)
1054  break;
1055  e->pair = 0;
1056  }
1057  }
1058 
1059  return MUTT_CMD_SUCCESS;
1060 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
The "current" mailbox.
Definition: context.h:37
#define COLOR_UNSET
Definition: color.c:52
#define NONULL(x)
Definition: string2.h:37
int msg_count
Total number of messages.
Definition: mailbox.h:91
int mutt_color_alloc(uint32_t fg, uint32_t bg)
Allocate a colour pair.
Definition: color.c:478
The envelope/body of an email.
Definition: email.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
struct Mailbox * ctx_mailbox(struct Context *ctx)
wrapper to get the mailbox in a Context, or NULL
Definition: context.c:440
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: color.h:104
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
char * pattern
Pattern to match.
Definition: color.h:103
int pair
Colour pair index.
Definition: color.h:107
String manipulation buffer.
Definition: buffer.h:33
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
static struct ColorLine * color_line_new(void)
Create a new ColorLine.
Definition: color.c:411
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:54
void mutt_check_simple(struct Buffer *s, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:113
Container for Accounts, Notifications.
Definition: neomutt.h:36
int match
Substring to match, 0 for old behaviour.
Definition: color.h:102
size_t dsize
Length of data.
Definition: buffer.h:37
static void color_line_free(struct ColorLine **ptr, bool free_colors)
Free a ColorLine.
Definition: color.c:328
struct Menu * menu
Needed for pattern compilation.
Definition: context.h:45
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
struct PatternList * mutt_pattern_comp(struct Mailbox *m, struct Menu *menu, const char *s, PatternCompFlags flags, struct Buffer *err)
Create a Pattern.
Definition: compile.c:1092
uint32_t fg
Foreground colour.
Definition: color.h:105
A mailbox.
Definition: mailbox.h:81
uint32_t bg
Background colour.
Definition: color.h:106
char * data
Pointer to data.
Definition: buffer.h:35
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:295
#define STAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:380
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
regex_t regex
Compiled regex.
Definition: color.h:101
Success: Command worked.
Definition: mutt_commands.h:38
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
void mutt_color_free(uint32_t fg, uint32_t bg)
Free a colour.
Definition: color.c:284
#define MUTT_PC_FULL_MSG
Enable body and header matching.
Definition: lib.h:61
bool mutt_mb_is_lower(const char *s)
Does a multi-byte string contain only lowercase characters?
Definition: mbyte.c:357
int pair
Color-pair to use when displaying in the index.
Definition: email.h:80
A regular expression and a color to highlight a line.
Definition: color.h:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_color_pair()

static enum CommandResult parse_color_pair ( struct Buffer buf,
struct Buffer s,
uint32_t *  fg,
uint32_t *  bg,
int *  attr,
struct Buffer err 
)
static

Parse a pair of colours - Implements parser_callback_t.

Definition at line 1066 of file color.c.

1069 {
1070  while (true)
1071  {
1072  if (!MoreArgs(s))
1073  {
1074  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
1075  return MUTT_CMD_WARNING;
1076  }
1077 
1079 
1080  if (mutt_istr_equal("bold", buf->data))
1081  *attr |= A_BOLD;
1082  else if (mutt_istr_equal("none", buf->data))
1083  *attr = A_NORMAL; // Use '=' to clear other bits
1084  else if (mutt_istr_equal("normal", buf->data))
1085  *attr = A_NORMAL; // Use '=' to clear other bits
1086  else if (mutt_istr_equal("reverse", buf->data))
1087  *attr |= A_REVERSE;
1088  else if (mutt_istr_equal("standout", buf->data))
1089  *attr |= A_STANDOUT;
1090  else if (mutt_istr_equal("underline", buf->data))
1091  *attr |= A_UNDERLINE;
1092  else
1093  {
1094  enum CommandResult rc = parse_color_name(buf->data, fg, attr, true, err);
1095  if (rc != MUTT_CMD_SUCCESS)
1096  return rc;
1097  break;
1098  }
1099  }
1100 
1101  if (!MoreArgs(s))
1102  {
1103  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
1104  return MUTT_CMD_WARNING;
1105  }
1106 
1108 
1109  return parse_color_name(buf->data, bg, attr, false, err);
1110 }
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:40
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
static enum CommandResult parse_color_name(const char *s, uint32_t *col, int *attr, bool is_fg, struct Buffer *err)
Parse a colour name.
Definition: color.c:607
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_attr_spec()

static enum CommandResult parse_attr_spec ( struct Buffer buf,
struct Buffer s,
uint32_t *  fg,
uint32_t *  bg,
int *  attr,
struct Buffer err 
)
static

Parse an attribute description - Implements parser_callback_t.

Definition at line 1116 of file color.c.

1119 {
1120  if (fg)
1121  *fg = COLOR_UNSET;
1122  if (bg)
1123  *bg = COLOR_UNSET;
1124 
1125  if (!MoreArgs(s))
1126  {
1127  mutt_buffer_printf(err, _("%s: too few arguments"), "mono");
1128  return MUTT_CMD_WARNING;
1129  }
1130 
1132 
1133  if (mutt_istr_equal("bold", buf->data))
1134  *attr |= A_BOLD;
1135  else if (mutt_istr_equal("none", buf->data))
1136  *attr = A_NORMAL; // Use '=' to clear other bits
1137  else if (mutt_istr_equal("normal", buf->data))
1138  *attr = A_NORMAL; // Use '=' to clear other bits
1139  else if (mutt_istr_equal("reverse", buf->data))
1140  *attr |= A_REVERSE;
1141  else if (mutt_istr_equal("standout", buf->data))
1142  *attr |= A_STANDOUT;
1143  else if (mutt_istr_equal("underline", buf->data))
1144  *attr |= A_UNDERLINE;
1145  else
1146  {
1147  mutt_buffer_printf(err, _("%s: no such attribute"), buf->data);
1148  return MUTT_CMD_WARNING;
1149  }
1150 
1151  return MUTT_CMD_SUCCESS;
1152 }
#define COLOR_UNSET
Definition: color.c:52
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:40
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fgbgattr_to_color()

static int fgbgattr_to_color ( int  fg,
int  bg,
int  attr 
)
static

Convert a foreground, background, attribute triplet into a colour.

Parameters
fgForeground colour ID
bgBackground colour ID
attrAttribute flags, e.g. A_BOLD
Return values
numCombined colour pair

Definition at line 1161 of file color.c.

1162 {
1163 #ifdef HAVE_COLOR
1164  if ((fg != COLOR_UNSET) && (bg != COLOR_UNSET))
1165  return attr | mutt_color_alloc(fg, bg);
1166 #endif
1167  return attr;
1168 }
#define COLOR_UNSET
Definition: color.c:52
int mutt_color_alloc(uint32_t fg, uint32_t bg)
Allocate a colour pair.
Definition: color.c:478
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_color()

static enum CommandResult parse_color ( struct Buffer buf,
struct Buffer s,
struct Buffer err,
parser_callback_t  callback,
bool  dry_run,
bool  color 
)
static

Parse a 'color' command.

Parameters
bufTemporary Buffer space
sBuffer containing string to be parsed
errBuffer for error messages
callbackFunction to handle command - Implements parser_callback_t
dry_runIf true, test the command, but don't apply it
colorIf true "color", else "mono"
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

usage: color OBJECT FG BG [ REGEX ] mono OBJECT ATTR [ REGEX ]

Definition at line 1183 of file color.c.

1186 {
1187  int attr = 0, q_level = 0;
1188  uint32_t fg = 0, bg = 0, match = 0;
1189  enum ColorId object = MT_COLOR_NONE;
1190  enum CommandResult rc;
1191 
1192  if (!MoreArgs(s))
1193  {
1194  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
1195  return MUTT_CMD_WARNING;
1196  }
1197 
1199 
1200  rc = parse_object(buf, s, &object, &q_level, err);
1201  if (rc != MUTT_CMD_SUCCESS)
1202  return rc;
1203 
1204  rc = callback(buf, s, &fg, &bg, &attr, err);
1205  if (rc != MUTT_CMD_SUCCESS)
1206  return rc;
1207 
1208  /* extract a regular expression if needed */
1209 
1210  if ((object == MT_COLOR_ATTACH_HEADERS) || (object == MT_COLOR_BODY) ||
1211  (object == MT_COLOR_HEADER) || (object == MT_COLOR_INDEX) ||
1212  (object == MT_COLOR_INDEX_AUTHOR) || (object == MT_COLOR_INDEX_FLAGS) ||
1213  (object == MT_COLOR_INDEX_SUBJECT) || (object == MT_COLOR_INDEX_TAG))
1214  {
1215  if (!MoreArgs(s))
1216  {
1217  mutt_buffer_printf(err, _("%s: too few arguments"), color ? "color" : "mono");
1218  return MUTT_CMD_WARNING;
1219  }
1220 
1222  }
1223 
1224  if (MoreArgs(s) && (object != MT_COLOR_STATUS))
1225  {
1226  mutt_buffer_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
1227  return MUTT_CMD_WARNING;
1228  }
1229 
1230  if (dry_run)
1231  {
1232  *s->dptr = '\0'; /* fake that we're done parsing */
1233  return MUTT_CMD_SUCCESS;
1234  }
1235 
1236 #ifdef HAVE_COLOR
1237 #ifdef HAVE_USE_DEFAULT_COLORS
1238  if (!OptNoCurses &&
1239  has_colors()
1240  /* delay use_default_colors() until needed, since it initializes things */
1241  && ((fg == COLOR_DEFAULT) || (bg == COLOR_DEFAULT) || (object == MT_COLOR_TREE)) &&
1242  (use_default_colors() != OK))
1243  /* the case of the tree object is special, because a non-default fg color of
1244  * the tree element may be combined dynamically with the default bg color of
1245  * an index line, not necessarily defined in a rc file. */
1246  {
1247  mutt_buffer_strcpy(err, _("default colors not supported"));
1248  return MUTT_CMD_ERROR;
1249  }
1250 #endif /* HAVE_USE_DEFAULT_COLORS */
1251 #endif
1252 
1253  if (object == MT_COLOR_ATTACH_HEADERS)
1254  rc = add_pattern(mutt_color_attachments(), buf->data, true, fg, bg, attr, err, false, match);
1255  else if (object == MT_COLOR_BODY)
1256  rc = add_pattern(mutt_color_body(), buf->data, true, fg, bg, attr, err, false, match);
1257  else if (object == MT_COLOR_HEADER)
1258  rc = add_pattern(mutt_color_headers(), buf->data, false, fg, bg, attr, err, false, match);
1259  else if (object == MT_COLOR_INDEX)
1260  {
1261  rc = add_pattern(mutt_color_index(), buf->data, true, fg, bg, attr, err, true, match);
1262  }
1263  else if (object == MT_COLOR_INDEX_AUTHOR)
1264  {
1265  rc = add_pattern(mutt_color_index_author(), buf->data, true, fg, bg, attr,
1266  err, true, match);
1267  }
1268  else if (object == MT_COLOR_INDEX_FLAGS)
1269  {
1270  rc = add_pattern(mutt_color_index_flags(), buf->data, true, fg, bg, attr, err, true, match);
1271  }
1272  else if (object == MT_COLOR_INDEX_SUBJECT)
1273  {
1274  rc = add_pattern(mutt_color_index_subject(), buf->data, true, fg, bg, attr,
1275  err, true, match);
1276  }
1277  else if (object == MT_COLOR_INDEX_TAG)
1278  {
1279  rc = add_pattern(mutt_color_index_tags(), buf->data, true, fg, bg, attr, err, true, match);
1280  }
1281  else if (object == MT_COLOR_QUOTED)
1282  {
1283  if (q_level >= COLOR_QUOTES_MAX)
1284  {
1285  mutt_buffer_printf(err, _("Maximum quoting level is %d"), COLOR_QUOTES_MAX - 1);
1286  return MUTT_CMD_WARNING;
1287  }
1288 
1289  if (q_level >= Colors.quotes_used)
1290  Colors.quotes_used = q_level + 1;
1291  if (q_level == 0)
1292  {
1293  Colors.defs[MT_COLOR_QUOTED] = fgbgattr_to_color(fg, bg, attr);
1294 
1295  Colors.quotes[0] = Colors.defs[MT_COLOR_QUOTED];
1296  for (q_level = 1; q_level < Colors.quotes_used; q_level++)
1297  {
1298  if (Colors.quotes[q_level] == A_NORMAL)
1299  Colors.quotes[q_level] = Colors.defs[MT_COLOR_QUOTED];
1300  }
1301  }
1302  else
1303  {
1304  Colors.quotes[q_level] = fgbgattr_to_color(fg, bg, attr);
1305  }
1306  rc = MUTT_CMD_SUCCESS;
1307  }
1308  else if ((object == MT_COLOR_STATUS) && MoreArgs(s))
1309  {
1310  /* 'color status fg bg' can have up to 2 arguments:
1311  * 0 arguments: sets the default status color (handled below by else part)
1312  * 1 argument : colorize pattern on match
1313  * 2 arguments: colorize nth submatch of pattern */
1315 
1316  if (MoreArgs(s))
1317  {
1318  struct Buffer tmp = mutt_buffer_make(0);
1320  if (mutt_str_atoui(tmp.data, &match) < 0)
1321  {
1322  mutt_buffer_printf(err, _("%s: invalid number: %s"),
1323  color ? "color" : "mono", tmp.data);
1324  mutt_buffer_dealloc(&tmp);
1325  return MUTT_CMD_WARNING;
1326  }
1327  mutt_buffer_dealloc(&tmp);
1328  }
1329 
1330  if (MoreArgs(s))
1331  {
1332  mutt_buffer_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
1333  return MUTT_CMD_WARNING;
1334  }
1335 
1336  rc = add_pattern(mutt_color_status_line(), buf->data, true, fg, bg, attr, err, false, match);
1337  }
1338  else // Remaining simple colours
1339  {
1340  Colors.defs[object] = fgbgattr_to_color(fg, bg, attr);
1341  rc = MUTT_CMD_SUCCESS;
1342  }
1343 
1344  if (rc == MUTT_CMD_SUCCESS)
1345  {
1346  struct EventColor ec = { object };
1347  notify_send(Colors.notify, NT_COLOR, NT_COLOR_SET, &ec);
1348  }
1349 
1350  return rc;
1351 }
MIME attachment test (takes a pattern)
Definition: color.h:43
#define COLOR_DEFAULT
Definition: color.c:128
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
An Event that happened to a Colour.
Definition: color.h:122
Pager: highlight body of message (takes a pattern)
Definition: color.h:44
struct ColorLineList * mutt_color_index_subject(void)
Return the ColorLineList for subject in the index.
Definition: color.c:1465
struct ColorLineList * mutt_color_index_flags(void)
Return the ColorLineList for flags in the index.
Definition: color.c:1456
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
struct ColorLineList * mutt_color_index(void)
Return the ColorLineList for the index.
Definition: color.c:1411
String manipulation buffer.
Definition: buffer.h:33
struct ColorLineList * mutt_color_index_tags(void)
Return the ColorLineList for tags in the index.
Definition: color.c:1474
#define _(a)
Definition: message.h:28
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: color.c:53
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Pager: quoted text.
Definition: color.h:62
Index: author field (takes a pattern)
Definition: color.h:82
#define MoreArgs(buf)
Definition: buffer.h:40
static enum CommandResult parse_object(struct Buffer *buf, struct Buffer *s, enum ColorId *obj, int *ql, struct Buffer *err)
Identify a colour object.
Definition: color.c:709
Message headers (takes a pattern)
Definition: color.h:53
Index: tag field (g, takes a pattern)
Definition: color.h:85
ColorId
List of all colored objects.
Definition: color.h:39
static enum CommandResult add_pattern(struct ColorLineList *top, const char *s, bool sensitive, uint32_t fg, uint32_t bg, int attr, struct Buffer *err, bool is_index, int match)
Associate a colour to a pattern.
Definition: color.c:965
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
Index: tree-drawing characters.
Definition: color.h:77
struct ColorLineList * mutt_color_attachments(void)
Return the ColorLineList for the attachments.
Definition: color.c:1438
A new Color has been set.
Definition: color.h:134
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
struct ColorLineList * mutt_color_index_author(void)
Return the ColorLineList for author in the index.
Definition: color.c:1447
Status bar (takes a pattern)
Definition: color.h:75
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
int mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: string.c:282
static int fgbgattr_to_color(int fg, int bg, int attr)
Convert a foreground, background, attribute triplet into a colour.
Definition: color.c:1161
struct ColorLineList * mutt_color_body(void)
Return the ColorLineList for the body.
Definition: color.c:1429
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Success: Command worked.
Definition: mutt_commands.h:38
Index: subject field (takes a pattern)
Definition: color.h:84
Warning: Help given to the user.
Definition: mutt_commands.h:37
struct ColorLineList * mutt_color_status_line(void)
Return the ColorLineList for the status_line.
Definition: color.c:1402
Index: default colour (takes a pattern)
Definition: color.h:81
struct ColorLineList * mutt_color_headers(void)
Return the ColorLineList for headers.
Definition: color.c:1420
Index: flags field (takes a pattern)
Definition: color.h:83
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
static struct @2 Colors
Wrapper for all the colours.
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:156
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_color()

enum CommandResult mutt_parse_color ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'color' command - Implements Command::parse()

Definition at line 1357 of file color.c.

1359 {
1360  bool dry_run = false;
1361 
1362  if (OptNoCurses || !has_colors())
1363  dry_run = true;
1364 
1365  return parse_color(buf, s, err, parse_color_pair, dry_run, true);
1366 }
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
static enum CommandResult parse_color(struct Buffer *buf, struct Buffer *s, struct Buffer *err, parser_callback_t callback, bool dry_run, bool color)
Parse a &#39;color&#39; command.
Definition: color.c:1183
static enum CommandResult parse_color_pair(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err)
Parse a pair of colours - Implements parser_callback_t.
Definition: color.c:1066
+ Here is the call graph for this function:

◆ mutt_parse_mono()

enum CommandResult mutt_parse_mono ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'mono' command - Implements Command::parse()

Definition at line 1372 of file color.c.

1374 {
1375  bool dry_run = false;
1376 
1377 #ifdef HAVE_COLOR
1378  if (OptNoCurses || has_colors())
1379  dry_run = true;
1380 #else
1381  if (OptNoCurses)
1382  dry_run = true;
1383 #endif
1384 
1385  return parse_color(buf, s, err, parse_attr_spec, dry_run, false);
1386 }
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
static enum CommandResult parse_attr_spec(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err)
Parse an attribute description - Implements parser_callback_t.
Definition: color.c:1116
static enum CommandResult parse_color(struct Buffer *buf, struct Buffer *s, struct Buffer *err, parser_callback_t callback, bool dry_run, bool color)
Parse a &#39;color&#39; command.
Definition: color.c:1183
+ Here is the call graph for this function:

◆ mutt_color()

int mutt_color ( enum ColorId  id)

Return the color of an object.

Parameters
idObject id
Return values
numColor ID, e.g. MT_COLOR_HEADER

Definition at line 1393 of file color.c.

1394 {
1395  return Colors.defs[id];
1396 }
static struct @2 Colors
Wrapper for all the colours.
+ Here is the caller graph for this function:

◆ mutt_color_status_line()

struct ColorLineList* mutt_color_status_line ( void  )

Return the ColorLineList for the status_line.

Return values
ptrColorLineList

Definition at line 1402 of file color.c.

1403 {
1404  return get_color_line_list(&Colors.status_list);
1405 }
static struct ColorLineList * get_color_line_list(struct ColorLineList *cll)
Sanitize and return a ColorLineList.
Definition: color.c:103
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_index()

struct ColorLineList* mutt_color_index ( void  )

Return the ColorLineList for the index.

Return values
ptrColorLineList

Definition at line 1411 of file color.c.

1412 {
1413  return get_color_line_list(&Colors.index_list);
1414 }
static struct ColorLineList * get_color_line_list(struct ColorLineList *cll)
Sanitize and return a ColorLineList.
Definition: color.c:103
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_headers()

struct ColorLineList* mutt_color_headers ( void  )

Return the ColorLineList for headers.

Return values
ptrColorLineList

Definition at line 1420 of file color.c.

1421 {
1422  return get_color_line_list(&Colors.hdr_list);
1423 }
static struct ColorLineList * get_color_line_list(struct ColorLineList *cll)
Sanitize and return a ColorLineList.
Definition: color.c:103
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_body()

struct ColorLineList* mutt_color_body ( void  )

Return the ColorLineList for the body.

Return values
ptrColorLineList

Definition at line 1429 of file color.c.

1430 {
1431  return get_color_line_list(&Colors.body_list);
1432 }
static struct ColorLineList * get_color_line_list(struct ColorLineList *cll)
Sanitize and return a ColorLineList.
Definition: color.c:103
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_attachments()

struct ColorLineList* mutt_color_attachments ( void  )

Return the ColorLineList for the attachments.

Return values
ptrColorLineList

Definition at line 1438 of file color.c.

1439 {
1440  return get_color_line_list(&Colors.attach_list);
1441 }
static struct ColorLineList * get_color_line_list(struct ColorLineList *cll)
Sanitize and return a ColorLineList.
Definition: color.c:103
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_index_author()

struct ColorLineList* mutt_color_index_author ( void  )

Return the ColorLineList for author in the index.

Return values
ptrColorLineList

Definition at line 1447 of file color.c.

1448 {
1449  return get_color_line_list(&Colors.index_author_list);
1450 }
static struct ColorLineList * get_color_line_list(struct ColorLineList *cll)
Sanitize and return a ColorLineList.
Definition: color.c:103
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_index_flags()

struct ColorLineList* mutt_color_index_flags ( void  )

Return the ColorLineList for flags in the index.

Return values
ptrColorLineList

Definition at line 1456 of file color.c.

1457 {
1458  return get_color_line_list(&Colors.index_flags_list);
1459 }
static struct ColorLineList * get_color_line_list(struct ColorLineList *cll)
Sanitize and return a ColorLineList.
Definition: color.c:103
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_index_subject()

struct ColorLineList* mutt_color_index_subject ( void  )

Return the ColorLineList for subject in the index.

Return values
ptrColorLineList

Definition at line 1465 of file color.c.

1466 {
1467  return get_color_line_list(&Colors.index_subject_list);
1468 }
static struct ColorLineList * get_color_line_list(struct ColorLineList *cll)
Sanitize and return a ColorLineList.
Definition: color.c:103
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_index_tags()

struct ColorLineList* mutt_color_index_tags ( void  )

Return the ColorLineList for tags in the index.

Return values
ptrColorLineList

Definition at line 1474 of file color.c.

1475 {
1476  return get_color_line_list(&Colors.index_tag_list);
1477 }
static struct ColorLineList * get_color_line_list(struct ColorLineList *cll)
Sanitize and return a ColorLineList.
Definition: color.c:103
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_quote()

int mutt_color_quote ( int  q)

Return the color of a quote, cycling through the used quotes.

Parameters
qQuote number
Return values
numColor ID, e.g. MT_COLOR_QUOTED

Definition at line 1484 of file color.c.

1485 {
1486  const int used = Colors.quotes_used;
1487  if (used == 0)
1488  return 0;
1489  return Colors.quotes[q % used];
1490 }
static struct @2 Colors
Wrapper for all the colours.
+ Here is the caller graph for this function:

◆ mutt_color_quotes_used()

int mutt_color_quotes_used ( void  )

Return the number of used quotes.

Return values
numNumber of used quotes

Definition at line 1496 of file color.c.

1497 {
1498  return Colors.quotes_used;
1499 }
static struct @2 Colors
Wrapper for all the colours.
+ Here is the caller graph for this function:

◆ mutt_color_observer_add()

void mutt_color_observer_add ( observer_t  callback,
void *  global_data 
)

Add an observer.

Parameters
callbackThe callback
global_dataThe data

Definition at line 1506 of file color.c.

1507 {
1508  notify_observer_add(Colors.notify, NT_COLOR, callback, global_data);
1509 }
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:173
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_observer_remove()

void mutt_color_observer_remove ( observer_t  callback,
void *  global_data 
)

Remove an observer.

Parameters
callbackThe callback
global_dataThe data

Definition at line 1516 of file color.c.

1517 {
1518  notify_observer_remove(Colors.notify, callback, global_data);
1519 }
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:212
static struct @2 Colors
Wrapper for all the colours.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_is_header()

bool mutt_color_is_header ( enum ColorId  color_id)

Colour is for an Email header.

Parameters
color_idColour, e.g. MT_COLOR_HEADER
Return values
trueColour is for an Email header

Definition at line 1526 of file color.c.

1527 {
1528  return (color_id == MT_COLOR_HEADER) || (color_id == MT_COLOR_HDRDEFAULT);
1529 }
Header default colour.
Definition: color.h:52
Message headers (takes a pattern)
Definition: color.h:53
+ Here is the caller graph for this function:

Variable Documentation

◆ defs

int defs[MT_COLOR_MAX]

Array of all fixed colours, see enum ColorId.

Definition at line 75 of file color.c.

◆ attach_list

struct ColorLineList attach_list

List of colours applied to the attachment headers.

Definition at line 79 of file color.c.

◆ body_list

struct ColorLineList body_list

List of colours applied to the email body.

Definition at line 80 of file color.c.

◆ hdr_list

struct ColorLineList hdr_list

List of colours applied to the email headers.

Definition at line 81 of file color.c.

◆ index_author_list

struct ColorLineList index_author_list

List of colours applied to the author in the index.

Definition at line 82 of file color.c.

◆ index_flags_list

struct ColorLineList index_flags_list

List of colours applied to the flags in the index.

Definition at line 83 of file color.c.

◆ index_list

struct ColorLineList index_list

List of default colours applied to the index.

Definition at line 84 of file color.c.

◆ index_subject_list

struct ColorLineList index_subject_list

List of colours applied to the subject in the index.

Definition at line 85 of file color.c.

◆ index_tag_list

struct ColorLineList index_tag_list

List of colours applied to tags in the index.

Definition at line 86 of file color.c.

◆ status_list

struct ColorLineList status_list

List of colours applied to the status bar.

Definition at line 87 of file color.c.

◆ quotes

int quotes[COLOR_QUOTES_MAX]

Array of colours for quoted email text.

Definition at line 89 of file color.c.

◆ quotes_used

int quotes_used

Number of colours for quoted email text.

Definition at line 90 of file color.c.

◆ user_colors

struct ColorList* user_colors

Definition at line 92 of file color.c.

◆ num_user_colors

int num_user_colors

Definition at line 93 of file color.c.

◆ notify

struct Notify* notify

Notifications: ColorId, EventColor.

Definition at line 95 of file color.c.

◆ Colors

struct { ... } Colors

Wrapper for all the colours.

◆ ColorNames

const struct Mapping ColorNames[]
static
Initial value:
= {
{ "black", COLOR_BLACK },
{ "blue", COLOR_BLUE },
{ "cyan", COLOR_CYAN },
{ "green", COLOR_GREEN },
{ "magenta", COLOR_MAGENTA },
{ "red", COLOR_RED },
{ "white", COLOR_WHITE },
{ "yellow", COLOR_YELLOW },
{ 0, 0 },
}

Definition at line 138 of file color.c.

◆ Fields

const struct Mapping Fields[]

Definition at line 156 of file color.c.

◆ ComposeFields

const struct Mapping ComposeFields[]
Initial value:
= {
{ "header", MT_COLOR_COMPOSE_HEADER },
{ "security_encrypt", MT_COLOR_COMPOSE_SECURITY_ENCRYPT },
{ "security_sign", MT_COLOR_COMPOSE_SECURITY_SIGN },
{ "security_both", MT_COLOR_COMPOSE_SECURITY_BOTH },
{ "security_none", MT_COLOR_COMPOSE_SECURITY_NONE },
{ NULL, 0 }
}
Mail will be encrypted.
Definition: color.h:48
Header labels, e.g. From:
Definition: color.h:46
Mail will be signed.
Definition: color.h:50
Mail will be encrypted and signed.
Definition: color.h:47
Mail will not be encrypted or signed.
Definition: color.h:49

Definition at line 203 of file color.c.