NeoMutt  2019-12-07-168-gc45f47
Teaching an old dog new tricks
DOXYGEN
color.c File Reference

Color and attribute parsing. More...

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

Go to the source code of this file.

Macros

#define COLOR_UNSET   UINT32_MAX
 
#define COLOR_QUOTES_MAX   10
 Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent) More...
 

Typedefs

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

Functions

static void defs_free (struct Colors *c)
 Free the simple colour definitions. More...
 
static void defs_init (struct Colors *c)
 Initialise the simple colour definitions. More...
 
static void defs_clear (struct Colors *c)
 Reset the simple colour definitions. More...
 
static void quotes_free (struct Colors *c)
 Free the quoted-email colours. More...
 
static void quotes_init (struct Colors *c)
 Initialise the quoted-email colours. More...
 
static void quotes_clear (struct Colors *c)
 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 (struct Colors *c, uint32_t fg, uint32_t bg)
 Free a colour. More...
 
static void color_line_free (struct Colors *c, struct ColorLine **ptr, bool free_colors)
 Free a ColorLine. More...
 
static void color_line_list_clear (struct Colors *c, struct ColorLineList *list)
 Clear a list of colours. More...
 
static void colors_clear (struct Colors *c)
 Reset all the colours. More...
 
void mutt_colors_free (struct Colors **ptr)
 Free all the colours. More...
 
struct Colorsmutt_colors_new (void)
 Create new colours. More...
 
static struct ColorLinecolor_line_new (void)
 Create a new ColorLine. 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 Colors *c, 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, unsigned long data, struct Buffer *err, bool uncolor)
 Parse an 'uncolor' command. More...
 
enum CommandResult mutt_parse_unmono (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unmono' command - Implements command_t. More...
 
static enum CommandResult add_pattern (struct Colors *c, 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_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 (struct Colors *c, int fg, int bg, int attr)
 Convert a foreground, background, attribute triplet into a colour. More...
 
static enum CommandResult parse_color (struct Colors *c, 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_mono (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'mono' command - Implements command_t. More...
 

Variables

static const struct Mapping Fields []
 
static const struct Mapping ComposeFields []
 

Detailed Description

Color and attribute parsing.

Authors
  • Michael R. Elkins

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

◆ COLOR_QUOTES_MAX

#define COLOR_QUOTES_MAX   10

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

Definition at line 65 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)

typedef parser_callback_t - 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 61 of file color.c.

Function Documentation

◆ defs_free()

static void defs_free ( struct Colors c)
static

Free the simple colour definitions.

Parameters
cColours

Definition at line 159 of file color.c.

160 {
161  FREE(&c->defs);
162 }
int * defs
Array of all fixed colours, see enum ColorId.
Definition: color.h:132
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ defs_init()

static void defs_init ( struct Colors c)
static

Initialise the simple colour definitions.

Parameters
cColours

Definition at line 168 of file color.c.

169 {
170  c->defs = mutt_mem_malloc(MT_COLOR_MAX * sizeof(int));
171  memset(c->defs, A_NORMAL, MT_COLOR_MAX * sizeof(int));
172 
173  // Set some defaults
174  c->defs[MT_COLOR_INDICATOR] = A_REVERSE;
175  c->defs[MT_COLOR_MARKERS] = A_REVERSE;
176  c->defs[MT_COLOR_SEARCH] = A_REVERSE;
177 #ifdef USE_SIDEBAR
178  c->defs[MT_COLOR_SIDEBAR_HIGHLIGHT] = A_UNDERLINE;
179 #endif
180  c->defs[MT_COLOR_STATUS] = A_REVERSE;
181 }
int * defs
Array of all fixed colours, see enum ColorId.
Definition: color.h:132
Select cursor.
Definition: color.h:87
Pager: markers, line continuation.
Definition: color.h:75
Status bar (takes a pattern)
Definition: color.h:95
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
Selected item in list.
Definition: color.h:74
Pager: search matches.
Definition: color.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ defs_clear()

static void defs_clear ( struct Colors c)
static

Reset the simple colour definitions.

Parameters
cColours

Definition at line 187 of file color.c.

188 {
189  memset(c->defs, A_NORMAL, MT_COLOR_MAX * sizeof(int));
190 }
int * defs
Array of all fixed colours, see enum ColorId.
Definition: color.h:132
+ Here is the caller graph for this function:

◆ quotes_free()

static void quotes_free ( struct Colors c)
static

Free the quoted-email colours.

Parameters
cColours

Definition at line 196 of file color.c.

197 {
198  FREE(&c->quotes);
199 }
#define FREE(x)
Definition: memory.h:40
int * quotes
Array of colours for quoted email text.
Definition: color.h:144
+ Here is the caller graph for this function:

◆ quotes_init()

static void quotes_init ( struct Colors c)
static

Initialise the quoted-email colours.

Parameters
cColours

Definition at line 205 of file color.c.

206 {
207  c->quotes = mutt_mem_malloc(COLOR_QUOTES_MAX * sizeof(int));
208  memset(c->quotes, A_NORMAL, COLOR_QUOTES_MAX * sizeof(int));
209  c->quotes_used = 0;
210 }
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: color.c:65
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
int quotes_used
Number of colours for quoted email text.
Definition: color.h:145
int * quotes
Array of colours for quoted email text.
Definition: color.h:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quotes_clear()

static void quotes_clear ( struct Colors c)
static

Reset the quoted-email colours.

Parameters
cColours

Definition at line 216 of file color.c.

217 {
218  memset(c->quotes, A_NORMAL, COLOR_QUOTES_MAX * sizeof(int));
219  c->quotes_used = 0;
220 }
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: color.c:65
int quotes_used
Number of colours for quoted email text.
Definition: color.h:145
int * quotes
Array of colours for quoted email text.
Definition: color.h:144
+ 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 226 of file color.c.

227 {
228  if (!ptr || !*ptr)
229  return;
230 
231  struct ColorList *cl = *ptr;
232  struct ColorList *next = NULL;
233 
234  while (cl)
235  {
236  next = cl->next;
237  FREE(&cl);
238  cl = next;
239  }
240  *ptr = NULL;
241 }
struct ColorList * next
Definition: color.h:127
A set of colors.
Definition: color.h:119
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ mutt_color_free()

void mutt_color_free ( struct Colors c,
uint32_t  fg,
uint32_t  bg 
)

Free a colour.

Parameters
cColours
fgForeground colour ID
bgBackground colour ID

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

Definition at line 251 of file color.c.

252 {
253  struct ColorList *q = NULL;
254 
255  struct ColorList *p = c->user_colors;
256  while (p)
257  {
258  if ((p->fg == fg) && (p->bg == bg))
259  {
260  (p->count)--;
261  if (p->count > 0)
262  return;
263 
264  c->num_user_colors--;
265  mutt_debug(LL_DEBUG1, "Color pairs used so far: %d\n", c->num_user_colors);
266 
267  if (p == c->user_colors)
268  {
269  c->user_colors = c->user_colors->next;
270  FREE(&p);
271  return;
272  }
273  q = c->user_colors;
274  while (q)
275  {
276  if (q->next == p)
277  {
278  q->next = p->next;
279  FREE(&p);
280  return;
281  }
282  q = q->next;
283  }
284  /* can't get here */
285  }
286  p = p->next;
287  }
288 }
int num_user_colors
Definition: color.h:148
short count
Definition: color.h:126
uint32_t bg
Definition: color.h:124
struct ColorList * next
Definition: color.h:127
struct ColorList * user_colors
Definition: color.h:147
uint32_t fg
Definition: color.h:123
Log at debug level 1.
Definition: logging.h:40
A set of colors.
Definition: color.h:119
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the caller graph for this function:

◆ color_line_free()

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

Free a ColorLine.

Parameters
cColours
ptrColorLine to free
free_colorsIf true, free its colours too

Definition at line 296 of file color.c.

297 {
298  if (!ptr || !*ptr)
299  return;
300 
301  struct ColorLine *cl = *ptr;
302 
303 #ifdef HAVE_COLOR
304  if (free_colors && (cl->fg != COLOR_UNSET) && (cl->bg != COLOR_UNSET))
305  mutt_color_free(c, cl->fg, cl->bg);
306 #endif
307 
308  regfree(&cl->regex);
310  FREE(&cl->pattern);
311  FREE(ptr);
312 }
#define COLOR_UNSET
Definition: color.c:64
void mutt_color_free(struct Colors *c, uint32_t fg, uint32_t bg)
Free a colour.
Definition: color.c:251
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: color.h:41
char * pattern
Pattern to match.
Definition: color.h:40
uint32_t fg
Foreground colour.
Definition: color.h:42
uint32_t bg
Background colour.
Definition: color.h:43
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition: pattern.c:1386
regex_t regex
Compiled regex.
Definition: color.h:38
#define FREE(x)
Definition: memory.h:40
A regular expression and a color to highlight a line.
Definition: color.h:36
+ 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 Colors c,
struct ColorLineList *  list 
)
static

Clear a list of colours.

Parameters
cColours
listColorLine List

Definition at line 319 of file color.c.

320 {
321  struct ColorLine *np = NULL, *tmp = NULL;
322  STAILQ_FOREACH_SAFE(np, list, entries, tmp)
323  {
324  STAILQ_REMOVE(list, np, ColorLine, entries);
325  color_line_free(c, &np, true);
326  }
327 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
static void color_line_free(struct Colors *c, struct ColorLine **ptr, bool free_colors)
Free a ColorLine.
Definition: color.c:296
A regular expression and a color to highlight a line.
Definition: color.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ colors_clear()

static void colors_clear ( struct Colors c)
static

Reset all the colours.

Parameters
cColours

Definition at line 333 of file color.c.

334 {
344 
345  defs_clear(c);
346  quotes_clear(c);
347 
349 }
struct ColorLineList status_list
List of colours applied to the status bar.
Definition: color.h:142
struct ColorLineList index_tag_list
List of colours applied to tags in the index.
Definition: color.h:141
struct ColorLineList body_list
List of colours applied to the email body.
Definition: color.h:135
struct ColorLineList index_flags_list
List of colours applied to the flags in the index.
Definition: color.h:138
struct ColorLineList index_subject_list
List of colours applied to the subject in the index.
Definition: color.h:140
static void color_line_list_clear(struct Colors *c, struct ColorLineList *list)
Clear a list of colours.
Definition: color.c:319
static void quotes_clear(struct Colors *c)
Reset the quoted-email colours.
Definition: color.c:216
struct ColorLineList hdr_list
List of colours applied to the email headers.
Definition: color.h:136
struct ColorLineList index_author_list
List of colours applied to the author in the index.
Definition: color.h:137
struct ColorList * user_colors
Definition: color.h:147
struct ColorLineList index_list
List of default colours applied to the index.
Definition: color.h:139
static void defs_clear(struct Colors *c)
Reset the simple colour definitions.
Definition: color.c:187
struct ColorLineList attach_list
List of colours applied to the attachment headers.
Definition: color.h:134
static void color_list_free(struct ColorList **ptr)
Free the list of curses colours.
Definition: color.c:226
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_colors_free()

void mutt_colors_free ( struct Colors **  ptr)

Free all the colours.

Parameters
ptrColours

Definition at line 355 of file color.c.

356 {
357  if (!ptr || !*ptr)
358  return;
359 
360  struct Colors *c = *ptr;
361 
362  colors_clear(c);
363  defs_free(c);
364  quotes_free(c);
365  notify_free(&c->notify);
366  FREE(ptr);
367 }
struct Notify * notify
Notifications system.
Definition: color.h:150
static void colors_clear(struct Colors *c)
Reset all the colours.
Definition: color.c:333
Definition: color.h:130
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:63
#define FREE(x)
Definition: memory.h:40
static void quotes_free(struct Colors *c)
Free the quoted-email colours.
Definition: color.c:196
static void defs_free(struct Colors *c)
Free the simple colour definitions.
Definition: color.c:159
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_colors_new()

struct Colors* mutt_colors_new ( void  )

Create new colours.

Return values
ptrNew Colors

Definition at line 373 of file color.c.

374 {
375  struct Colors *c = mutt_mem_calloc(1, sizeof(*c));
376  c->notify = notify_new();
377 
378  quotes_init(c);
379  defs_init(c);
380 
382  STAILQ_INIT(&c->body_list);
383  STAILQ_INIT(&c->hdr_list);
386  STAILQ_INIT(&c->index_list);
390 
391 #ifdef HAVE_COLOR
392  start_color();
393 #endif
394 
396  return c;
397 }
struct ColorLineList status_list
List of colours applied to the status bar.
Definition: color.h:142
struct ColorLineList index_tag_list
List of colours applied to tags in the index.
Definition: color.h:141
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Notify * notify
Notifications system.
Definition: color.h:150
struct ColorLineList body_list
List of colours applied to the email body.
Definition: color.h:135
struct ColorLineList index_flags_list
List of colours applied to the flags in the index.
Definition: color.h:138
struct ColorLineList index_subject_list
List of colours applied to the subject in the index.
Definition: color.h:140
Container for Accounts, Notifications.
Definition: neomutt.h:35
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:83
#define STAILQ_INIT(head)
Definition: queue.h:369
static void quotes_init(struct Colors *c)
Initialise the quoted-email colours.
Definition: color.c:205
struct ColorLineList hdr_list
List of colours applied to the email headers.
Definition: color.h:136
struct ColorLineList index_author_list
List of colours applied to the author in the index.
Definition: color.h:137
struct Notify * notify
Notifications handler.
Definition: neomutt.h:37
Definition: color.h:130
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:50
struct ColorLineList index_list
List of default colours applied to the index.
Definition: color.h:139
struct ColorLineList attach_list
List of colours applied to the attachment headers.
Definition: color.h:134
static void defs_init(struct Colors *c)
Initialise the simple colour definitions.
Definition: color.c:168
+ 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 403 of file color.c.

404 {
405  struct ColorLine *cl = mutt_mem_calloc(1, sizeof(struct ColorLine));
406 
407  cl->fg = COLOR_UNSET;
408  cl->bg = COLOR_UNSET;
409 
410  return cl;
411 }
#define COLOR_UNSET
Definition: color.c:64
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:42
uint32_t bg
Background colour.
Definition: color.h:43
A regular expression and a color to highlight a line.
Definition: color.h:36
+ 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 704 of file color.c.

706 {
707  int rc;
708 
709  if (mutt_str_startswith(buf->data, "quoted", CASE_MATCH) != 0)
710  {
711  int val = 0;
712  if (buf->data[6] != '\0')
713  {
714  rc = mutt_str_atoi(buf->data + 6, &val);
715  if ((rc != 0) || (val > COLOR_QUOTES_MAX))
716  {
717  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
718  return MUTT_CMD_WARNING;
719  }
720  }
721 
722  *ql = val;
723  *obj = MT_COLOR_QUOTED;
724  return MUTT_CMD_SUCCESS;
725  }
726 
727  if (mutt_str_strcasecmp(buf->data, "compose") == 0)
728  {
729  if (!MoreArgs(s))
730  {
731  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
732  return MUTT_CMD_WARNING;
733  }
734 
736 
738  if (rc == -1)
739  {
740  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
741  return MUTT_CMD_WARNING;
742  }
743 
744  *obj = rc;
745  return MUTT_CMD_SUCCESS;
746  }
747 
748  rc = mutt_map_get_value(buf->data, Fields);
749  if (rc == -1)
750  {
751  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
752  return MUTT_CMD_WARNING;
753  }
754 
755  *obj = rc;
756  return MUTT_CMD_SUCCESS;
757 }
int mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: string.c:262
static const struct Mapping ComposeFields[]
Definition: color.c:145
#define _(a)
Definition: message.h:28
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: color.c:65
Match case when comparing strings.
Definition: string2.h:67
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:82
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:426
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:651
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:61
static const struct Mapping Fields[]
Definition: color.c:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_uncolor()

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

Parse the 'uncolor' or 'unmono' command.

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

Definition at line 768 of file color.c.

770 {
771  struct ColorLine *np = NULL, *prev = NULL;
772  bool rc = false;
773 
774  do
775  {
777  if (mutt_str_strcmp("*", buf->data) == 0)
778  {
779  rc = STAILQ_FIRST(cl);
780  color_line_list_clear(c, cl);
781  return rc;
782  }
783 
784  prev = NULL;
785  STAILQ_FOREACH(np, cl, entries)
786  {
787  if (mutt_str_strcmp(buf->data, np->pattern) == 0)
788  {
789  rc = true;
790 
791  mutt_debug(LL_DEBUG1, "Freeing pattern \"%s\" from user_colors\n", buf->data);
792  if (prev)
793  STAILQ_REMOVE_AFTER(cl, prev, entries);
794  else
795  STAILQ_REMOVE_HEAD(cl, entries);
796  color_line_free(c, &np, uncolor);
797  break;
798  }
799  prev = np;
800  }
801  } while (MoreArgs(s));
802 
803  return rc;
804 }
char * pattern
Pattern to match.
Definition: color.h:40
static void color_line_list_clear(struct Colors *c, struct ColorLineList *list)
Clear a list of colours.
Definition: color.c:319
#define STAILQ_REMOVE_HEAD(head, field)
Definition: queue.h:419
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:426
char * data
Pointer to data.
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
static void color_line_free(struct Colors *c, struct ColorLine **ptr, bool free_colors)
Free a ColorLine.
Definition: color.c:296
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
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:638
A regular expression and a color to highlight a line.
Definition: color.h:36
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ 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,
unsigned long  data,
struct Buffer err,
bool  uncolor 
)
static

Parse an 'uncolor' command.

Parameters
bufTemporary Buffer space
sBuffer containing string to be parsed
dataFlags associated with the command
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 819 of file color.c.

821 {
822  struct Colors *c = *(struct Colors **) data;
823 
825 
826  if (mutt_str_strcmp(buf->data, "*") == 0)
827  {
828  colors_clear(c);
829  struct EventColor ec = { false }; // Color reset/removed
831  return MUTT_CMD_SUCCESS;
832  }
833 
834  unsigned int object = MT_COLOR_NONE;
835  int ql = 0;
836  enum CommandResult rc = parse_object(buf, s, &object, &ql, err);
837  if (rc != MUTT_CMD_SUCCESS)
838  return rc;
839 
840  if (object == -1)
841  {
842  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
843  return MUTT_CMD_ERROR;
844  }
845 
846  if (object == MT_COLOR_QUOTED)
847  {
848  c->quotes[ql] = A_NORMAL;
849  /* fallthrough to simple case */
850  }
851 
852  if ((object != MT_COLOR_ATTACH_HEADERS) && (object != MT_COLOR_BODY) &&
853  (object != MT_COLOR_HEADER) && (object != MT_COLOR_INDEX) &&
854  (object != MT_COLOR_INDEX_AUTHOR) && (object != MT_COLOR_INDEX_FLAGS) &&
855  (object != MT_COLOR_INDEX_SUBJECT) && (object != MT_COLOR_INDEX_TAG) &&
856  (object != MT_COLOR_STATUS))
857  {
858  // Simple colours
859  c->defs[object] = A_NORMAL;
860 
861  struct EventColor ec = { false }; // Color reset/removed
862  notify_send(c->notify, NT_COLOR, object, &ec);
863  return MUTT_CMD_SUCCESS;
864  }
865 
866  if (!MoreArgs(s))
867  {
868  mutt_buffer_printf(err, _("%s: too few arguments"), uncolor ? "uncolor" : "unmono");
869  return MUTT_CMD_WARNING;
870  }
871 
872 #ifdef HAVE_COLOR
873  if (OptNoCurses || // running without curses
874  (uncolor && !has_colors()) || // parsing an uncolor command, and have no colors
875  (!uncolor && has_colors())) // parsing an unmono command, and have colors
876 #else
877  if (uncolor) // We don't even have colors compiled in
878 #endif
879  {
880  do
881  {
882  /* just eat the command, but don't do anything real about it */
884  } while (MoreArgs(s));
885 
886  return MUTT_CMD_SUCCESS;
887  }
888 
889  bool changed = false;
890  if (object == MT_COLOR_ATTACH_HEADERS)
891  changed |= do_uncolor(c, buf, s, &c->attach_list, uncolor);
892  else if (object == MT_COLOR_BODY)
893  changed |= do_uncolor(c, buf, s, &c->body_list, uncolor);
894  else if (object == MT_COLOR_HEADER)
895  changed |= do_uncolor(c, buf, s, &c->hdr_list, uncolor);
896  else if (object == MT_COLOR_INDEX)
897  changed |= do_uncolor(c, buf, s, &c->index_list, uncolor);
898  else if (object == MT_COLOR_INDEX_AUTHOR)
899  changed |= do_uncolor(c, buf, s, &c->index_author_list, uncolor);
900  else if (object == MT_COLOR_INDEX_FLAGS)
901  changed |= do_uncolor(c, buf, s, &c->index_flags_list, uncolor);
902  else if (object == MT_COLOR_INDEX_SUBJECT)
903  changed |= do_uncolor(c, buf, s, &c->index_subject_list, uncolor);
904  else if (object == MT_COLOR_INDEX_TAG)
905  changed |= do_uncolor(c, buf, s, &c->index_tag_list, uncolor);
906  else if (object == MT_COLOR_STATUS)
907  changed |= do_uncolor(c, buf, s, &c->status_list, uncolor);
908 
909  if (changed)
910  {
911  struct EventColor ec = { false }; // Color reset/removed
912  notify_send(c->notify, NT_COLOR, object, &ec);
913  }
914 
915  return MUTT_CMD_SUCCESS;
916 }
struct ColorLineList status_list
List of colours applied to the status bar.
Definition: color.h:142
struct ColorLineList index_tag_list
List of colours applied to tags in the index.
Definition: color.h:141
MIME attachment test (takes a pattern)
Definition: color.h:63
static bool do_uncolor(struct Colors *c, struct Buffer *buf, struct Buffer *s, struct ColorLineList *cl, bool uncolor)
Parse the &#39;uncolor&#39; or &#39;unmono&#39; command.
Definition: color.c:768
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
struct Notify * notify
Notifications system.
Definition: color.h:150
struct ColorLineList body_list
List of colours applied to the email body.
Definition: color.h:135
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
An Event that happened to an Colour.
Definition: color.h:159
Pager: highlight body of message (takes a pattern)
Definition: color.h:64
int * defs
Array of all fixed colours, see enum ColorId.
Definition: color.h:132
struct ColorLineList index_flags_list
List of colours applied to the flags in the index.
Definition: color.h:138
struct ColorLineList index_subject_list
List of colours applied to the subject in the index.
Definition: color.h:140
#define _(a)
Definition: message.h:28
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:47
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:82
Index: author field (takes a pattern)
Definition: color.h:102
#define MoreArgs(buf)
Definition: buffer.h:43
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:704
Message headers (takes a pattern)
Definition: color.h:73
Index: tag field (g, takes a pattern)
Definition: color.h:105
struct ColorLineList hdr_list
List of colours applied to the email headers.
Definition: color.h:136
static void colors_clear(struct Colors *c)
Reset all the colours.
Definition: color.c:333
Colour has changed.
Definition: notify_type.h:32
Status bar (takes a pattern)
Definition: color.h:95
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:426
struct ColorLineList index_author_list
List of colours applied to the author in the index.
Definition: color.h:137
char * data
Pointer to data.
Definition: buffer.h:35
Definition: color.h:130
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:138
Success: Command worked.
Definition: mutt_commands.h:37
Index: subject field (takes a pattern)
Definition: color.h:104
Warning: Help given to the user.
Definition: mutt_commands.h:36
struct ColorLineList index_list
List of default colours applied to the index.
Definition: color.h:139
struct ColorLineList attach_list
List of colours applied to the attachment headers.
Definition: color.h:134
Index: default colour (takes a pattern)
Definition: color.h:101
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:638
Index: flags field (takes a pattern)
Definition: color.h:103
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
int * quotes
Array of colours for quoted email text.
Definition: color.h:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_unmono()

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

Parse the 'unmono' command - Implements command_t.

Definition at line 932 of file color.c.

934 {
935  return parse_uncolor(buf, s, data, err, false);
936 }
static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err, bool uncolor)
Parse an &#39;uncolor&#39; command.
Definition: color.c:819
+ Here is the call graph for this function:

◆ add_pattern()

static enum CommandResult add_pattern ( struct Colors c,
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
cColours
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 955 of file color.c.

958 {
959  struct ColorLine *tmp = NULL;
960 
961  STAILQ_FOREACH(tmp, top, entries)
962  {
963  if (sensitive)
964  {
965  if (mutt_str_strcmp(s, tmp->pattern) == 0)
966  break;
967  }
968  else
969  {
970  if (mutt_str_strcasecmp(s, tmp->pattern) == 0)
971  break;
972  }
973  }
974 
975  if (tmp)
976  {
977 #ifdef HAVE_COLOR
978  if ((fg != COLOR_UNSET) && (bg != COLOR_UNSET))
979  {
980  if ((tmp->fg != fg) || (tmp->bg != bg))
981  {
982  mutt_color_free(c, tmp->fg, tmp->bg);
983  tmp->fg = fg;
984  tmp->bg = bg;
985  attr |= mutt_color_alloc(c, fg, bg);
986  }
987  else
988  attr |= (tmp->pair & ~A_BOLD);
989  }
990 #endif /* HAVE_COLOR */
991  tmp->pair = attr;
992  }
993  else
994  {
995  tmp = color_line_new();
996  if (is_index)
997  {
998  struct Buffer *buf = mutt_buffer_pool_get();
999  mutt_buffer_strcpy(buf, s);
1003  if (!tmp->color_pattern)
1004  {
1005  color_line_free(c, &tmp, true);
1006  return MUTT_CMD_ERROR;
1007  }
1008  }
1009  else
1010  {
1011  int flags = 0;
1012  if (sensitive)
1013  flags = mutt_mb_is_lower(s) ? REG_ICASE : 0;
1014  else
1015  flags = REG_ICASE;
1016 
1017  const int r = REG_COMP(&tmp->regex, s, flags);
1018  if (r != 0)
1019  {
1020  regerror(r, &tmp->regex, err->data, err->dsize);
1021  color_line_free(c, &tmp, true);
1022  return MUTT_CMD_ERROR;
1023  }
1024  }
1025  tmp->pattern = mutt_str_strdup(s);
1026  tmp->match = match;
1027 #ifdef HAVE_COLOR
1028  if ((fg != COLOR_UNSET) && (bg != COLOR_UNSET))
1029  {
1030  tmp->fg = fg;
1031  tmp->bg = bg;
1032  attr |= mutt_color_alloc(c, fg, bg);
1033  }
1034 #endif
1035  tmp->pair = attr;
1036  STAILQ_INSERT_HEAD(top, tmp, entries);
1037  }
1038 
1039  /* force re-caching of index colors */
1040  if (is_index && Context && Context->mailbox)
1041  {
1042  const struct Mailbox *m = Context->mailbox;
1043  for (int i = 0; i < m->msg_count; i++)
1044  {
1045  struct Email *e = m->emails[i];
1046  if (!e)
1047  break;
1048  e->pair = 0;
1049  }
1050  }
1051 
1052  return MUTT_CMD_SUCCESS;
1053 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:98
The "current" mailbox.
Definition: context.h:36
#define COLOR_UNSET
Definition: color.c:64
#define NONULL(x)
Definition: string2.h:37
int msg_count
Total number of messages.
Definition: mailbox.h:90
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
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
void mutt_color_free(struct Colors *c, uint32_t fg, uint32_t bg)
Free a colour.
Definition: color.c:251
void mutt_check_simple(struct Buffer *buf, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:2425
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: color.h:41
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:40
int pair
Colour pair index.
Definition: color.h:44
String manipulation buffer.
Definition: buffer.h:33
static struct ColorLine * color_line_new(void)
Create a new ColorLine.
Definition: color.c:403
int match
Substring to match, 0 for old behaviour.
Definition: color.h:39
int mutt_color_alloc(struct Colors *c, uint32_t fg, uint32_t bg)
size_t dsize
Length of data.
Definition: buffer.h:37
struct Mailbox * mailbox
Definition: context.h:50
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:52
struct PatternList * mutt_pattern_comp(const char *s, PatternCompFlags flags, struct Buffer *err)
Create a Pattern.
Definition: pattern.c:1438
uint32_t fg
Foreground colour.
Definition: color.h:42
A mailbox.
Definition: mailbox.h:80
uint32_t bg
Background colour.
Definition: color.h:43
char * data
Pointer to data.
Definition: buffer.h:35
#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
WHERE char * C_SimpleSearch
Config: Pattern to search for when search doesn&#39;t contain ~&#39;s.
Definition: globals.h:140
static void color_line_free(struct Colors *c, struct ColorLine **ptr, bool free_colors)
Free a ColorLine.
Definition: color.c:296
regex_t regex
Compiled regex.
Definition: color.h:38
Success: Command worked.
Definition: mutt_commands.h:37
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:651
#define MUTT_PC_FULL_MSG
Enable body and header matching.
Definition: pattern.h:43
bool mutt_mb_is_lower(const char *s)
Does a multi-byte string contain only lowercase characters?
Definition: mbyte.c:358
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:638
int pair
Color-pair to use when displaying in the index.
Definition: email.h:79
A regular expression and a color to highlight a line.
Definition: color.h:36
+ 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 1111 of file color.c.

1114 {
1115  if (fg)
1116  *fg = COLOR_UNSET;
1117  if (bg)
1118  *bg = COLOR_UNSET;
1119 
1120  if (!MoreArgs(s))
1121  {
1122  mutt_buffer_printf(err, _("%s: too few arguments"), "mono");
1123  return MUTT_CMD_WARNING;
1124  }
1125 
1127 
1128  if (mutt_str_strcasecmp("bold", buf->data) == 0)
1129  *attr |= A_BOLD;
1130  else if (mutt_str_strcasecmp("none", buf->data) == 0)
1131  *attr = A_NORMAL; // Use '=' to clear other bits
1132  else if (mutt_str_strcasecmp("normal", buf->data) == 0)
1133  *attr = A_NORMAL; // Use '=' to clear other bits
1134  else if (mutt_str_strcasecmp("reverse", buf->data) == 0)
1135  *attr |= A_REVERSE;
1136  else if (mutt_str_strcasecmp("standout", buf->data) == 0)
1137  *attr |= A_STANDOUT;
1138  else if (mutt_str_strcasecmp("underline", buf->data) == 0)
1139  *attr |= A_UNDERLINE;
1140  else
1141  {
1142  mutt_buffer_printf(err, _("%s: no such attribute"), buf->data);
1143  return MUTT_CMD_WARNING;
1144  }
1145 
1146  return MUTT_CMD_SUCCESS;
1147 }
#define COLOR_UNSET
Definition: color.c:64
#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:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:426
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:651
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fgbgattr_to_color()

static int fgbgattr_to_color ( struct Colors c,
int  fg,
int  bg,
int  attr 
)
static

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

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

Definition at line 1157 of file color.c.

1158 {
1159 #ifdef HAVE_COLOR
1160  if ((fg != COLOR_UNSET) && (bg != COLOR_UNSET))
1161  return attr | mutt_color_alloc(c, fg, bg);
1162 #endif
1163  return attr;
1164 }
#define COLOR_UNSET
Definition: color.c:64
int mutt_color_alloc(struct Colors *c, uint32_t fg, uint32_t bg)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_color()

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

Parse a 'color' command.

Parameters
cColours
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 1180 of file color.c.

1183 {
1184  int attr = 0, q_level = 0;
1185  uint32_t fg = 0, bg = 0, match = 0;
1186  enum ColorId object = MT_COLOR_NONE;
1187  enum CommandResult rc;
1188 
1189  if (!MoreArgs(s))
1190  {
1191  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
1192  return MUTT_CMD_WARNING;
1193  }
1194 
1196 
1197  rc = parse_object(buf, s, &object, &q_level, err);
1198  if (rc != MUTT_CMD_SUCCESS)
1199  return rc;
1200 
1201  rc = callback(buf, s, &fg, &bg, &attr, err);
1202  if (rc != MUTT_CMD_SUCCESS)
1203  return rc;
1204 
1205  /* extract a regular expression if needed */
1206 
1207  if ((object == MT_COLOR_ATTACH_HEADERS) || (object == MT_COLOR_BODY) ||
1208  (object == MT_COLOR_HEADER) || (object == MT_COLOR_INDEX) ||
1209  (object == MT_COLOR_INDEX_AUTHOR) || (object == MT_COLOR_INDEX_FLAGS) ||
1210  (object == MT_COLOR_INDEX_SUBJECT) || (object == MT_COLOR_INDEX_TAG))
1211  {
1212  if (!MoreArgs(s))
1213  {
1214  mutt_buffer_printf(err, _("%s: too few arguments"), color ? "color" : "mono");
1215  return MUTT_CMD_WARNING;
1216  }
1217 
1219  }
1220 
1221  if (MoreArgs(s) && (object != MT_COLOR_STATUS))
1222  {
1223  mutt_buffer_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
1224  return MUTT_CMD_WARNING;
1225  }
1226 
1227  if (dry_run)
1228  {
1229  *s->dptr = '\0'; /* fake that we're done parsing */
1230  return MUTT_CMD_SUCCESS;
1231  }
1232 
1233 #ifdef HAVE_COLOR
1234 #ifdef HAVE_USE_DEFAULT_COLORS
1235  if (!OptNoCurses &&
1236  has_colors()
1237  /* delay use_default_colors() until needed, since it initializes things */
1238  && ((fg == COLOR_DEFAULT) || (bg == COLOR_DEFAULT) || (object == MT_COLOR_TREE)) &&
1239  (use_default_colors() != OK))
1240  /* the case of the tree object is special, because a non-default fg color of
1241  * the tree element may be combined dynamically with the default bg color of
1242  * an index line, not necessarily defined in a rc file. */
1243  {
1244  mutt_buffer_strcpy(err, _("default colors not supported"));
1245  return MUTT_CMD_ERROR;
1246  }
1247 #endif /* HAVE_USE_DEFAULT_COLORS */
1248 #endif
1249 
1250  if (object == MT_COLOR_ATTACH_HEADERS)
1251  rc = add_pattern(c, &c->attach_list, buf->data, true, fg, bg, attr, err, false, match);
1252  else if (object == MT_COLOR_BODY)
1253  rc = add_pattern(c, &c->body_list, buf->data, true, fg, bg, attr, err, false, match);
1254  else if (object == MT_COLOR_HEADER)
1255  rc = add_pattern(c, &c->hdr_list, buf->data, false, fg, bg, attr, err, false, match);
1256  else if (object == MT_COLOR_INDEX)
1257  {
1258  rc = add_pattern(c, &c->index_list, buf->data, true, fg, bg, attr, err, true, match);
1259  }
1260  else if (object == MT_COLOR_INDEX_AUTHOR)
1261  {
1262  rc = add_pattern(c, &c->index_author_list, buf->data, true, fg, bg, attr,
1263  err, true, match);
1264  }
1265  else if (object == MT_COLOR_INDEX_FLAGS)
1266  {
1267  rc = add_pattern(c, &c->index_flags_list, buf->data, true, fg, bg, attr, err, true, match);
1268  }
1269  else if (object == MT_COLOR_INDEX_SUBJECT)
1270  {
1271  rc = add_pattern(c, &c->index_subject_list, buf->data, true, fg, bg, attr,
1272  err, true, match);
1273  }
1274  else if (object == MT_COLOR_INDEX_TAG)
1275  {
1276  rc = add_pattern(c, &c->index_tag_list, buf->data, true, fg, bg, attr, err, true, match);
1277  }
1278  else if (object == MT_COLOR_QUOTED)
1279  {
1280  if (q_level >= COLOR_QUOTES_MAX)
1281  {
1282  mutt_buffer_printf(err, _("Maximum quoting level is %d"), COLOR_QUOTES_MAX - 1);
1283  return MUTT_CMD_WARNING;
1284  }
1285 
1286  if (q_level >= c->quotes_used)
1287  c->quotes_used = q_level + 1;
1288  if (q_level == 0)
1289  {
1290  c->defs[MT_COLOR_QUOTED] = fgbgattr_to_color(c, fg, bg, attr);
1291 
1292  c->quotes[0] = c->defs[MT_COLOR_QUOTED];
1293  for (q_level = 1; q_level < c->quotes_used; q_level++)
1294  {
1295  if (c->quotes[q_level] == A_NORMAL)
1296  c->quotes[q_level] = c->defs[MT_COLOR_QUOTED];
1297  }
1298  }
1299  else
1300  {
1301  c->quotes[q_level] = fgbgattr_to_color(c, fg, bg, attr);
1302  }
1303  rc = MUTT_CMD_SUCCESS;
1304  }
1305  else if ((object == MT_COLOR_STATUS) && MoreArgs(s))
1306  {
1307  /* 'color status fg bg' can have up to 2 arguments:
1308  * 0 arguments: sets the default status color (handled below by else part)
1309  * 1 argument : colorize pattern on match
1310  * 2 arguments: colorize nth submatch of pattern */
1312 
1313  if (MoreArgs(s))
1314  {
1315  struct Buffer tmp = mutt_buffer_make(0);
1317  if (mutt_str_atoui(tmp.data, &match) < 0)
1318  {
1319  mutt_buffer_printf(err, _("%s: invalid number: %s"),
1320  color ? "color" : "mono", tmp.data);
1321  mutt_buffer_dealloc(&tmp);
1322  return MUTT_CMD_WARNING;
1323  }
1324  mutt_buffer_dealloc(&tmp);
1325  }
1326 
1327  if (MoreArgs(s))
1328  {
1329  mutt_buffer_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
1330  return MUTT_CMD_WARNING;
1331  }
1332 
1333  rc = add_pattern(c, &c->status_list, buf->data, true, fg, bg, attr, err, false, match);
1334  }
1335  else // Remaining simple colours
1336  {
1337  c->defs[object] = fgbgattr_to_color(c, fg, bg, attr);
1338  rc = MUTT_CMD_SUCCESS;
1339  }
1340 
1341  if (rc == MUTT_CMD_SUCCESS)
1342  {
1343  struct EventColor ec = { true }; // Color set/added
1344  notify_send(c->notify, NT_COLOR, object, &ec);
1345  }
1346 
1347  return rc;
1348 }
struct ColorLineList status_list
List of colours applied to the status bar.
Definition: color.h:142
struct ColorLineList index_tag_list
List of colours applied to tags in the index.
Definition: color.h:141
MIME attachment test (takes a pattern)
Definition: color.h:63
static enum CommandResult add_pattern(struct Colors *c, 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:955
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
struct Notify * notify
Notifications system.
Definition: color.h:150
struct ColorLineList body_list
List of colours applied to the email body.
Definition: color.h:135
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
An Event that happened to an Colour.
Definition: color.h:159
Pager: highlight body of message (takes a pattern)
Definition: color.h:64
int * defs
Array of all fixed colours, see enum ColorId.
Definition: color.h:132
struct ColorLineList index_flags_list
List of colours applied to the flags in the index.
Definition: color.h:138
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
struct ColorLineList index_subject_list
List of colours applied to the subject in the index.
Definition: color.h:140
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
static int fgbgattr_to_color(struct Colors *c, int fg, int bg, int attr)
Convert a foreground, background, attribute triplet into a colour.
Definition: color.c:1157
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: color.c:65
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:47
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:82
Index: author field (takes a pattern)
Definition: color.h:102
#define MoreArgs(buf)
Definition: buffer.h:43
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:704
Message headers (takes a pattern)
Definition: color.h:73
Index: tag field (g, takes a pattern)
Definition: color.h:105
ColorId
List of all colored objects.
Definition: color.h:59
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:97
struct ColorLineList hdr_list
List of colours applied to the email headers.
Definition: color.h:136
Colour has changed.
Definition: notify_type.h:32
Status bar (takes a pattern)
Definition: color.h:95
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:426
char * dptr
Current read/write position.
Definition: buffer.h:36
struct ColorLineList index_author_list
List of colours applied to the author in the index.
Definition: color.h:137
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:292
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:138
Success: Command worked.
Definition: mutt_commands.h:37
Index: subject field (takes a pattern)
Definition: color.h:104
Warning: Help given to the user.
Definition: mutt_commands.h:36
struct ColorLineList index_list
List of default colours applied to the index.
Definition: color.h:139
struct ColorLineList attach_list
List of colours applied to the attachment headers.
Definition: color.h:134
Index: default colour (takes a pattern)
Definition: color.h:101
int quotes_used
Number of colours for quoted email text.
Definition: color.h:145
Index: flags field (takes a pattern)
Definition: color.h:103
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
int * quotes
Array of colours for quoted email text.
Definition: color.h:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_mono()

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

Parse the 'mono' command - Implements command_t.

Definition at line 1370 of file color.c.

1372 {
1373  bool dry_run = false;
1374 
1375 #ifdef HAVE_COLOR
1376  if (OptNoCurses || has_colors())
1377  dry_run = true;
1378 #else
1379  if (OptNoCurses)
1380  dry_run = true;
1381 #endif
1382 
1383  struct Colors *c = *(struct Colors **) data;
1384  return parse_color(c, buf, s, err, parse_attr_spec, dry_run, false);
1385 }
static enum CommandResult parse_color(struct Colors *c, 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:1180
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:47
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:1111
Definition: color.h:130
+ Here is the call graph for this function:

Variable Documentation

◆ Fields

const struct Mapping Fields[]
static

Definition at line 98 of file color.c.

◆ ComposeFields

const struct Mapping ComposeFields[]
static
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:68
Header labels, e.g. From:
Definition: color.h:66
Mail will be signed.
Definition: color.h:70
Mail will be encrypted and signed.
Definition: color.h:67
Mail will not be encrypted or signed.
Definition: color.h:69

Definition at line 145 of file color.c.