NeoMutt  2019-11-11
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/mutt.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   9
 

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   9

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

159 {
160  FREE(&c->defs);
161 }
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 167 of file color.c.

168 {
169  c->defs = mutt_mem_malloc(MT_COLOR_MAX * sizeof(int));
170  memset(c->defs, A_NORMAL, MT_COLOR_MAX * sizeof(int));
171 
172  // Set some defaults
173  c->defs[MT_COLOR_INDICATOR] = A_REVERSE;
174  c->defs[MT_COLOR_MARKERS] = A_REVERSE;
175  c->defs[MT_COLOR_SEARCH] = A_REVERSE;
176 #ifdef USE_SIDEBAR
177  c->defs[MT_COLOR_SIDEBAR_HIGHLIGHT] = A_UNDERLINE;
178 #endif
179  c->defs[MT_COLOR_STATUS] = A_REVERSE;
180 }
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 186 of file color.c.

187 {
188  memset(c->defs, A_NORMAL, MT_COLOR_MAX * sizeof(int));
189 }
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 195 of file color.c.

196 {
197  FREE(&c->quotes);
198 }
#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 204 of file color.c.

205 {
206  c->quotes = mutt_mem_malloc(COLOR_QUOTES_MAX * sizeof(int));
207  memset(c->quotes, A_NORMAL, COLOR_QUOTES_MAX * sizeof(int));
208  c->quotes_used = 0;
209 }
#define COLOR_QUOTES_MAX
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 215 of file color.c.

216 {
217  memset(c->quotes, A_NORMAL, COLOR_QUOTES_MAX * sizeof(int));
218  c->quotes_used = 0;
219 }
#define COLOR_QUOTES_MAX
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 225 of file color.c.

226 {
227  if (!ptr || !*ptr)
228  return;
229 
230  struct ColorList *cl = *ptr;
231  struct ColorList *next = NULL;
232 
233  while (cl)
234  {
235  next = cl->next;
236  FREE(&cl);
237  cl = next;
238  }
239  *ptr = NULL;
240 }
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 250 of file color.c.

251 {
252  struct ColorList *q = NULL;
253 
254  struct ColorList *p = c->user_colors;
255  while (p)
256  {
257  if ((p->fg == fg) && (p->bg == bg))
258  {
259  (p->count)--;
260  if (p->count > 0)
261  return;
262 
263  c->num_user_colors--;
264  mutt_debug(LL_DEBUG1, "Color pairs used so far: %d\n", c->num_user_colors);
265 
266  if (p == c->user_colors)
267  {
268  c->user_colors = c->user_colors->next;
269  FREE(&p);
270  return;
271  }
272  q = c->user_colors;
273  while (q)
274  {
275  if (q->next == p)
276  {
277  q->next = p->next;
278  FREE(&p);
279  return;
280  }
281  q = q->next;
282  }
283  /* can't get here */
284  }
285  p = p->next;
286  }
287 }
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:56
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 295 of file color.c.

296 {
297  if (!ptr || !*ptr)
298  return;
299 
300  struct ColorLine *cl = *ptr;
301 
302 #ifdef HAVE_COLOR
303  if (free_colors && (cl->fg != COLOR_UNSET) && (cl->bg != COLOR_UNSET))
304  mutt_color_free(c, cl->fg, cl->bg);
305 #endif
306 
307  regfree(&cl->regex);
309  FREE(&cl->pattern);
310  FREE(ptr);
311 }
#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:250
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:1340
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 318 of file color.c.

319 {
320  struct ColorLine *np = NULL, *tmp = NULL;
321  STAILQ_FOREACH_SAFE(np, list, entries, tmp)
322  {
323  STAILQ_REMOVE(list, np, ColorLine, entries);
324  color_line_free(c, &np, true);
325  }
326 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:400
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:360
static void color_line_free(struct Colors *c, struct ColorLine **ptr, bool free_colors)
Free a ColorLine.
Definition: color.c:295
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 332 of file color.c.

333 {
343 
344  defs_clear(c);
345  quotes_clear(c);
346 
348 }
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:318
static void quotes_clear(struct Colors *c)
Reset the quoted-email colours.
Definition: color.c:215
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:186
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:225
+ 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 354 of file color.c.

355 {
356  if (!ptr || !*ptr)
357  return;
358 
359  struct Colors *c = *ptr;
360 
361  colors_clear(c);
362  defs_free(c);
363  quotes_free(c);
364  notify_free(&c->notify);
365  FREE(ptr);
366 }
struct Notify * notify
Notifications system.
Definition: color.h:150
static void colors_clear(struct Colors *c)
Reset all the colours.
Definition: color.c:332
Definition: color.h:130
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:69
#define FREE(x)
Definition: memory.h:40
static void quotes_free(struct Colors *c)
Free the quoted-email colours.
Definition: color.c:195
static void defs_free(struct Colors *c)
Free the simple colour definitions.
Definition: color.c:158
+ 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 372 of file color.c.

373 {
374  struct Colors *c = mutt_mem_calloc(1, sizeof(*c));
375  c->notify = notify_new(c, NT_COLOR);
376 
377  quotes_init(c);
378  defs_init(c);
379 
381  STAILQ_INIT(&c->body_list);
382  STAILQ_INIT(&c->hdr_list);
385  STAILQ_INIT(&c->index_list);
389 
390 #ifdef HAVE_COLOR
391  start_color();
392 #endif
393 
395  return c;
396 }
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:89
struct Notify * notify_new(void *object, enum NotifyType type)
Create a new notifications handler.
Definition: notify.c:54
#define STAILQ_INIT(head)
Definition: queue.h:370
static void quotes_init(struct Colors *c)
Initialise the quoted-email colours.
Definition: color.c:204
struct ColorLineList hdr_list
List of colours applied to the email headers.
Definition: color.h:136
Colour has changed.
Definition: notify_type.h:39
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 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:167
+ 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 402 of file color.c.

403 {
404  struct ColorLine *cl = mutt_mem_calloc(1, sizeof(struct ColorLine));
405 
406  cl->fg = COLOR_UNSET;
407  cl->bg = COLOR_UNSET;
408 
409  return cl;
410 }
#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 703 of file color.c.

705 {
706  int rc;
707 
708  if (mutt_str_startswith(buf->data, "quoted", CASE_MATCH) != 0)
709  {
710  int val = 0;
711  if (buf->data[6] != '\0')
712  {
713  rc = mutt_str_atoi(buf->data + 6, &val);
714  if ((rc != 0) || (val > COLOR_QUOTES_MAX))
715  {
716  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
717  return MUTT_CMD_WARNING;
718  }
719  }
720 
721  *ql = val;
722  *obj = MT_COLOR_QUOTED;
723  return MUTT_CMD_SUCCESS;
724  }
725 
726  if (mutt_str_strcasecmp(buf->data, "compose") == 0)
727  {
728  if (!MoreArgs(s))
729  {
730  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
731  return MUTT_CMD_WARNING;
732  }
733 
735 
737  if (rc == -1)
738  {
739  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
740  return MUTT_CMD_WARNING;
741  }
742 
743  *obj = rc;
744  return MUTT_CMD_SUCCESS;
745  }
746 
747  rc = mutt_map_get_value(buf->data, Fields);
748  if (rc == -1)
749  {
750  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
751  return MUTT_CMD_WARNING;
752  }
753 
754  *obj = rc;
755  return MUTT_CMD_SUCCESS;
756 }
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:144
#define _(a)
Definition: message.h:28
#define COLOR_QUOTES_MAX
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:2655
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:628
#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:97
+ 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 767 of file color.c.

769 {
770  struct ColorLine *np = NULL, *prev = NULL;
771  bool rc = false;
772 
773  do
774  {
776  if (mutt_str_strcmp("*", buf->data) == 0)
777  {
778  rc = STAILQ_FIRST(cl);
779  color_line_list_clear(c, cl);
780  return rc;
781  }
782 
783  prev = NULL;
784  STAILQ_FOREACH(np, cl, entries)
785  {
786  if (mutt_str_strcmp(buf->data, np->pattern) == 0)
787  {
788  rc = true;
789 
790  mutt_debug(LL_DEBUG1, "Freeing pattern \"%s\" from user_colors\n", buf->data);
791  if (prev)
792  STAILQ_REMOVE_AFTER(cl, prev, entries);
793  else
794  STAILQ_REMOVE_HEAD(cl, entries);
795  color_line_free(c, &np, uncolor);
796  break;
797  }
798  prev = np;
799  }
800  } while (MoreArgs(s));
801 
802  return rc;
803 }
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:318
#define STAILQ_REMOVE_HEAD(head, field)
Definition: queue.h:420
#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:2655
char * data
Pointer to data.
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
static void color_line_free(struct Colors *c, struct ColorLine **ptr, bool free_colors)
Free a ColorLine.
Definition: color.c:295
Log at debug level 1.
Definition: logging.h:56
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define STAILQ_FIRST(head)
Definition: queue.h:348
#define STAILQ_REMOVE_AFTER(head, elm, field)
Definition: queue.h:414
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
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 818 of file color.c.

820 {
821  struct Colors *c = *(struct Colors **) data;
822 
824 
825  if (mutt_str_strcmp(buf->data, "*") == 0)
826  {
827  colors_clear(c);
828  struct EventColor ec = { false }; // Color reset/removed
829  notify_send(c->notify, NT_COLOR, MT_COLOR_MAX, (intptr_t) &ec);
830  return MUTT_CMD_SUCCESS;
831  }
832 
833  unsigned int object = MT_COLOR_NONE;
834  int ql = 0;
835  enum CommandResult rc = parse_object(buf, s, &object, &ql, err);
836  if (rc != MUTT_CMD_SUCCESS)
837  return rc;
838 
839  if (object == -1)
840  {
841  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
842  return MUTT_CMD_ERROR;
843  }
844 
845  if (object == MT_COLOR_QUOTED)
846  {
847  c->quotes[ql] = A_NORMAL;
848  /* fallthrough to simple case */
849  }
850 
851  if ((object != MT_COLOR_ATTACH_HEADERS) && (object != MT_COLOR_BODY) &&
852  (object != MT_COLOR_HEADER) && (object != MT_COLOR_INDEX) &&
853  (object != MT_COLOR_INDEX_AUTHOR) && (object != MT_COLOR_INDEX_FLAGS) &&
854  (object != MT_COLOR_INDEX_SUBJECT) && (object != MT_COLOR_INDEX_TAG) &&
855  (object != MT_COLOR_STATUS))
856  {
857  // Simple colours
858  c->defs[object] = A_NORMAL;
859 
860  struct EventColor ec = { false }; // Color reset/removed
861  notify_send(c->notify, NT_COLOR, object, (intptr_t) &ec);
862  return MUTT_CMD_SUCCESS;
863  }
864 
865  if (!MoreArgs(s))
866  {
867  mutt_buffer_printf(err, _("%s: too few arguments"), uncolor ? "uncolor" : "unmono");
868  return MUTT_CMD_WARNING;
869  }
870 
871 #ifdef HAVE_COLOR
872  if (OptNoCurses || // running without curses
873  (uncolor && !has_colors()) || // parsing an uncolor command, and have no colors
874  (!uncolor && has_colors())) // parsing an unmono command, and have colors
875 #else
876  if (uncolor) // We don't even have colors compiled in
877 #endif
878  {
879  do
880  {
881  /* just eat the command, but don't do anything real about it */
883  } while (MoreArgs(s));
884 
885  return MUTT_CMD_SUCCESS;
886  }
887 
888  bool changed = false;
889  if (object == MT_COLOR_ATTACH_HEADERS)
890  changed |= do_uncolor(c, buf, s, &c->attach_list, uncolor);
891  else if (object == MT_COLOR_BODY)
892  changed |= do_uncolor(c, buf, s, &c->body_list, uncolor);
893  else if (object == MT_COLOR_HEADER)
894  changed |= do_uncolor(c, buf, s, &c->hdr_list, uncolor);
895  else if (object == MT_COLOR_INDEX)
896  changed |= do_uncolor(c, buf, s, &c->index_list, uncolor);
897  else if (object == MT_COLOR_INDEX_AUTHOR)
898  changed |= do_uncolor(c, buf, s, &c->index_author_list, uncolor);
899  else if (object == MT_COLOR_INDEX_FLAGS)
900  changed |= do_uncolor(c, buf, s, &c->index_flags_list, uncolor);
901  else if (object == MT_COLOR_INDEX_SUBJECT)
902  changed |= do_uncolor(c, buf, s, &c->index_subject_list, uncolor);
903  else if (object == MT_COLOR_INDEX_TAG)
904  changed |= do_uncolor(c, buf, s, &c->index_tag_list, uncolor);
905  else if (object == MT_COLOR_STATUS)
906  changed |= do_uncolor(c, buf, s, &c->status_list, uncolor);
907 
908  if (changed)
909  {
910  struct EventColor ec = { false }; // Color reset/removed
911  notify_send(c->notify, NT_COLOR, object, (intptr_t) &ec);
912  }
913 
914  return MUTT_CMD_SUCCESS;
915 }
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:767
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:46
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:703
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:332
Colour has changed.
Definition: notify_type.h:39
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:2655
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
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
bool notify_send(struct Notify *notify, int type, int subtype, intptr_t data)
Send out a notification message.
Definition: notify.c:145
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
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 931 of file color.c.

933 {
934  return parse_uncolor(buf, s, data, err, false);
935 }
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:818
+ 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 954 of file color.c.

957 {
958  struct ColorLine *tmp = NULL;
959 
960  STAILQ_FOREACH(tmp, top, entries)
961  {
962  if (sensitive)
963  {
964  if (mutt_str_strcmp(s, tmp->pattern) == 0)
965  break;
966  }
967  else
968  {
969  if (mutt_str_strcasecmp(s, tmp->pattern) == 0)
970  break;
971  }
972  }
973 
974  if (tmp)
975  {
976 #ifdef HAVE_COLOR
977  if ((fg != COLOR_UNSET) && (bg != COLOR_UNSET))
978  {
979  if ((tmp->fg != fg) || (tmp->bg != bg))
980  {
981  mutt_color_free(c, tmp->fg, tmp->bg);
982  tmp->fg = fg;
983  tmp->bg = bg;
984  attr |= mutt_color_alloc(c, fg, bg);
985  }
986  else
987  attr |= (tmp->pair & ~A_BOLD);
988  }
989 #endif /* HAVE_COLOR */
990  tmp->pair = attr;
991  }
992  else
993  {
994  tmp = color_line_new();
995  if (is_index)
996  {
997  struct Buffer *buf = mutt_buffer_pool_get();
998  mutt_buffer_strcpy(buf, s);
1002  if (!tmp->color_pattern)
1003  {
1004  color_line_free(c, &tmp, true);
1005  return MUTT_CMD_ERROR;
1006  }
1007  }
1008  else
1009  {
1010  int flags = 0;
1011  if (sensitive)
1012  flags = mutt_mb_is_lower(s) ? REG_ICASE : 0;
1013  else
1014  flags = REG_ICASE;
1015 
1016  const int r = REG_COMP(&tmp->regex, s, flags);
1017  if (r != 0)
1018  {
1019  regerror(r, &tmp->regex, err->data, err->dsize);
1020  color_line_free(c, &tmp, true);
1021  return MUTT_CMD_ERROR;
1022  }
1023  }
1024  tmp->pattern = mutt_str_strdup(s);
1025  tmp->match = match;
1026 #ifdef HAVE_COLOR
1027  if ((fg != COLOR_UNSET) && (bg != COLOR_UNSET))
1028  {
1029  tmp->fg = fg;
1030  tmp->bg = bg;
1031  attr |= mutt_color_alloc(c, fg, bg);
1032  }
1033 #endif
1034  tmp->pair = attr;
1035  STAILQ_INSERT_HEAD(top, tmp, entries);
1036  }
1037 
1038  /* force re-caching of index colors */
1039  if (is_index)
1040  {
1041  for (int i = 0; Context && i < Context->mailbox->msg_count; i++)
1042  Context->mailbox->emails[i]->pair = 0;
1043  }
1044 
1045  return MUTT_CMD_SUCCESS;
1046 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:110
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:102
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:100
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:250
void mutt_check_simple(struct Buffer *buf, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:2294
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:111
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:402
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:1392
uint32_t fg
Foreground colour.
Definition: color.h:42
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:381
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
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:142
static void color_line_free(struct Colors *c, struct ColorLine **ptr, bool free_colors)
Free a ColorLine.
Definition: color.c:295
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:628
#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:615
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 1104 of file color.c.

1107 {
1108  if (fg)
1109  *fg = COLOR_UNSET;
1110  if (bg)
1111  *bg = COLOR_UNSET;
1112 
1113  if (!MoreArgs(s))
1114  {
1115  mutt_buffer_printf(err, _("%s: too few arguments"), "mono");
1116  return MUTT_CMD_WARNING;
1117  }
1118 
1120 
1121  if (mutt_str_strcasecmp("bold", buf->data) == 0)
1122  *attr |= A_BOLD;
1123  else if (mutt_str_strcasecmp("none", buf->data) == 0)
1124  *attr = A_NORMAL; // Use '=' to clear other bits
1125  else if (mutt_str_strcasecmp("normal", buf->data) == 0)
1126  *attr = A_NORMAL; // Use '=' to clear other bits
1127  else if (mutt_str_strcasecmp("reverse", buf->data) == 0)
1128  *attr |= A_REVERSE;
1129  else if (mutt_str_strcasecmp("standout", buf->data) == 0)
1130  *attr |= A_STANDOUT;
1131  else if (mutt_str_strcasecmp("underline", buf->data) == 0)
1132  *attr |= A_UNDERLINE;
1133  else
1134  {
1135  mutt_buffer_printf(err, _("%s: no such attribute"), buf->data);
1136  return MUTT_CMD_WARNING;
1137  }
1138 
1139  return MUTT_CMD_SUCCESS;
1140 }
#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:2655
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:628
#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 1150 of file color.c.

1151 {
1152 #ifdef HAVE_COLOR
1153  if ((fg != COLOR_UNSET) && (bg != COLOR_UNSET))
1154  return attr | mutt_color_alloc(c, fg, bg);
1155 #endif
1156  return attr;
1157 }
#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 1173 of file color.c.

1176 {
1177  int attr = 0, q_level = 0;
1178  uint32_t fg = 0, bg = 0, match = 0;
1179  enum ColorId object = MT_COLOR_NONE;
1180  enum CommandResult rc;
1181 
1182  if (!MoreArgs(s))
1183  {
1184  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
1185  return MUTT_CMD_WARNING;
1186  }
1187 
1189 
1190  rc = parse_object(buf, s, &object, &q_level, err);
1191  if (rc != MUTT_CMD_SUCCESS)
1192  return rc;
1193 
1194  rc = callback(buf, s, &fg, &bg, &attr, err);
1195  if (rc != MUTT_CMD_SUCCESS)
1196  return rc;
1197 
1198  /* extract a regular expression if needed */
1199 
1200  if ((object == MT_COLOR_ATTACH_HEADERS) || (object == MT_COLOR_BODY) ||
1201  (object == MT_COLOR_HEADER) || (object == MT_COLOR_INDEX) ||
1202  (object == MT_COLOR_INDEX_AUTHOR) || (object == MT_COLOR_INDEX_FLAGS) ||
1203  (object == MT_COLOR_INDEX_SUBJECT) || (object == MT_COLOR_INDEX_TAG))
1204  {
1205  if (!MoreArgs(s))
1206  {
1207  mutt_buffer_printf(err, _("%s: too few arguments"), color ? "color" : "mono");
1208  return MUTT_CMD_WARNING;
1209  }
1210 
1212  }
1213 
1214  if (MoreArgs(s) && (object != MT_COLOR_STATUS))
1215  {
1216  mutt_buffer_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
1217  return MUTT_CMD_WARNING;
1218  }
1219 
1220  if (dry_run)
1221  {
1222  *s->dptr = '\0'; /* fake that we're done parsing */
1223  return MUTT_CMD_SUCCESS;
1224  }
1225 
1226 #ifdef HAVE_COLOR
1227 #ifdef HAVE_USE_DEFAULT_COLORS
1228  if (!OptNoCurses &&
1229  has_colors()
1230  /* delay use_default_colors() until needed, since it initializes things */
1231  && ((fg == COLOR_DEFAULT) || (bg == COLOR_DEFAULT) || (object == MT_COLOR_TREE)) &&
1232  (use_default_colors() != OK))
1233  /* the case of the tree object is special, because a non-default fg color of
1234  * the tree element may be combined dynamically with the default bg color of
1235  * an index line, not necessarily defined in a rc file. */
1236  {
1237  mutt_buffer_strcpy(err, _("default colors not supported"));
1238  return MUTT_CMD_ERROR;
1239  }
1240 #endif /* HAVE_USE_DEFAULT_COLORS */
1241 #endif
1242 
1243  if (object == MT_COLOR_ATTACH_HEADERS)
1244  rc = add_pattern(c, &c->attach_list, buf->data, true, fg, bg, attr, err, false, match);
1245  else if (object == MT_COLOR_BODY)
1246  rc = add_pattern(c, &c->body_list, buf->data, true, fg, bg, attr, err, false, match);
1247  else if (object == MT_COLOR_HEADER)
1248  rc = add_pattern(c, &c->hdr_list, buf->data, false, fg, bg, attr, err, false, match);
1249  else if (object == MT_COLOR_INDEX)
1250  {
1251  rc = add_pattern(c, &c->index_list, buf->data, true, fg, bg, attr, err, true, match);
1252  }
1253  else if (object == MT_COLOR_INDEX_AUTHOR)
1254  {
1255  rc = add_pattern(c, &c->index_author_list, buf->data, true, fg, bg, attr,
1256  err, true, match);
1257  }
1258  else if (object == MT_COLOR_INDEX_FLAGS)
1259  {
1260  rc = add_pattern(c, &c->index_flags_list, buf->data, true, fg, bg, attr, err, true, match);
1261  }
1262  else if (object == MT_COLOR_INDEX_SUBJECT)
1263  {
1264  rc = add_pattern(c, &c->index_subject_list, buf->data, true, fg, bg, attr,
1265  err, true, match);
1266  }
1267  else if (object == MT_COLOR_INDEX_TAG)
1268  {
1269  rc = add_pattern(c, &c->index_tag_list, buf->data, true, fg, bg, attr, err, true, match);
1270  }
1271  else if (object == MT_COLOR_QUOTED)
1272  {
1273  if (q_level >= COLOR_QUOTES_MAX)
1274  {
1275  mutt_buffer_printf(err, _("Maximum quoting level is %d"), COLOR_QUOTES_MAX - 1);
1276  return MUTT_CMD_WARNING;
1277  }
1278 
1279  if (q_level >= c->quotes_used)
1280  c->quotes_used = q_level + 1;
1281  if (q_level == 0)
1282  {
1283  c->defs[MT_COLOR_QUOTED] = fgbgattr_to_color(c, fg, bg, attr);
1284 
1285  c->quotes[0] = c->defs[MT_COLOR_QUOTED];
1286  for (q_level = 1; q_level < c->quotes_used; q_level++)
1287  {
1288  if (c->quotes[q_level] == A_NORMAL)
1289  c->quotes[q_level] = c->defs[MT_COLOR_QUOTED];
1290  }
1291  }
1292  else
1293  {
1294  c->quotes[q_level] = fgbgattr_to_color(c, fg, bg, attr);
1295  }
1296  rc = MUTT_CMD_SUCCESS;
1297  }
1298  else if ((object == MT_COLOR_STATUS) && MoreArgs(s))
1299  {
1300  /* 'color status fg bg' can have up to 2 arguments:
1301  * 0 arguments: sets the default status color (handled below by else part)
1302  * 1 argument : colorize pattern on match
1303  * 2 arguments: colorize nth submatch of pattern */
1305 
1306  if (MoreArgs(s))
1307  {
1308  struct Buffer tmp = mutt_buffer_make(0);
1310  if (mutt_str_atoui(tmp.data, &match) < 0)
1311  {
1312  mutt_buffer_printf(err, _("%s: invalid number: %s"),
1313  color ? "color" : "mono", tmp.data);
1314  mutt_buffer_dealloc(&tmp);
1315  return MUTT_CMD_WARNING;
1316  }
1317  mutt_buffer_dealloc(&tmp);
1318  }
1319 
1320  if (MoreArgs(s))
1321  {
1322  mutt_buffer_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
1323  return MUTT_CMD_WARNING;
1324  }
1325 
1326  rc = add_pattern(c, &c->status_list, buf->data, true, fg, bg, attr, err, false, match);
1327  }
1328  else // Remaining simple colours
1329  {
1330  c->defs[object] = fgbgattr_to_color(c, fg, bg, attr);
1331  rc = MUTT_CMD_SUCCESS;
1332  }
1333 
1334  if (rc == MUTT_CMD_SUCCESS)
1335  {
1336  struct EventColor ec = { true }; // Color set/added
1337  notify_send(c->notify, NT_COLOR, object, (intptr_t) &ec);
1338  }
1339 
1340  return rc;
1341 }
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:954
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:1150
#define COLOR_QUOTES_MAX
Definition: color.c:65
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:46
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:703
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:39
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:2655
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
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
bool notify_send(struct Notify *notify, int type, int subtype, intptr_t data)
Send out a notification message.
Definition: notify.c:145
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 1363 of file color.c.

1365 {
1366  bool dry_run = false;
1367 
1368 #ifdef HAVE_COLOR
1369  if (OptNoCurses || has_colors())
1370  dry_run = true;
1371 #else
1372  if (OptNoCurses)
1373  dry_run = true;
1374 #endif
1375 
1376  struct Colors *c = *(struct Colors **) data;
1377  return parse_color(c, buf, s, err, parse_attr_spec, dry_run, false);
1378 }
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:1173
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:46
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:1104
Definition: color.h:130
+ Here is the call graph for this function:

Variable Documentation

◆ Fields

const struct Mapping Fields[]
static

Definition at line 97 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 144 of file color.c.