NeoMutt  2021-10-29-220-g2b1eec
Teaching an old dog new tricks
DOXYGEN
command.c File Reference

Parse colour commands. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "init.h"
#include "options.h"
+ Include dependency graph for command.c:

Go to the source code of this file.

Functions

static enum CommandResult parse_color_name (const char *s, uint32_t *col, int *attrs, bool is_fg, struct Buffer *err)
 Parse a colour name. More...
 
static enum CommandResult parse_attr_spec (struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attrs, struct Buffer *err)
 Parse an attribute description - Implements parser_callback_t -. More...
 
static enum CommandResult parse_color_pair (struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attrs, struct Buffer *err)
 Parse a pair of colours - Implements parser_callback_t -. More...
 
void get_colorid_name (unsigned int cid, struct Buffer *buf)
 Get the name of a color id. More...
 
static enum CommandResult parse_object (struct Buffer *buf, struct Buffer *s, enum ColorId *cid, int *ql, struct Buffer *err)
 Identify a colour object. More...
 
static bool do_uncolor (struct Buffer *buf, struct Buffer *s, struct RegexColorList *cl, bool uncolor)
 Parse the 'uncolor' or 'unmono' command. More...
 
static enum CommandResult parse_uncolor (struct Buffer *buf, struct Buffer *s, struct Buffer *err, bool uncolor)
 Parse an 'uncolor' command. More...
 
int fgbgattr_to_color (int fg, int bg, int attrs)
 Convert a foreground, background, attribute triplet into a colour. More...
 
static enum CommandResult parse_color (struct Buffer *buf, struct Buffer *s, struct Buffer *err, parser_callback_t callback, bool dry_run, bool color)
 Parse a 'color' command. More...
 
enum CommandResult mutt_parse_uncolor (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'uncolor' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unmono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmono' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_color (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'color' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_mono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'mono' command - Implements Command::parse() -. More...
 

Variables

const struct Mapping ColorFields []
 Mapping of colour names to their IDs. More...
 
const struct Mapping ComposeColorFields []
 Mapping of compose colour names to their IDs. More...
 

Detailed Description

Parse colour commands.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file command.c.

Function Documentation

◆ parse_color_name()

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

Parse a colour name.

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

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

Definition at line 1 of file command.c.

121 {
122  char *eptr = NULL;
123  bool is_alert = false, is_bright = false, is_light = false;
124  int clen;
125 
126  if ((clen = mutt_istr_startswith(s, "bright")))
127  {
128  is_bright = true;
129  s += clen;
130  }
131  else if ((clen = mutt_istr_startswith(s, "alert")))
132  {
133  is_alert = true;
134  is_bright = true;
135  s += clen;
136  }
137  else if ((clen = mutt_istr_startswith(s, "light")))
138  {
139  is_light = true;
140  s += clen;
141  }
142 
143  /* allow aliases for xterm color resources */
144  if ((clen = mutt_istr_startswith(s, "color")))
145  {
146  s += clen;
147  *col = strtoul(s, &eptr, 10);
148  if ((*s == '\0') || (*eptr != '\0') ||
149  ((*col >= COLORS) && !OptNoCurses && has_colors()))
150  {
151  mutt_buffer_printf(err, _("%s: color not supported by term"), s);
152  return MUTT_CMD_ERROR;
153  }
154  }
155  else if ((*col = mutt_map_get_value(s, ColorNames)) == -1)
156  {
157  mutt_buffer_printf(err, _("%s: no such color"), s);
158  return MUTT_CMD_WARNING;
159  }
160 
161  if (is_bright || is_light)
162  {
163  if (is_alert)
164  {
165  *attrs |= A_BOLD;
166  *attrs |= A_BLINK;
167  }
168  else if (is_fg)
169  {
170  if ((COLORS >= 16) && is_light)
171  {
172  if (*col <= 7)
173  {
174  /* Advance the color 0-7 by 8 to get the light version */
175  *col += 8;
176  }
177  }
178  else
179  {
180  *attrs |= A_BOLD;
181  }
182  }
183  else if (!(*col & RGB24))
184  {
185  if (COLORS >= 16)
186  {
187  if (*col <= 7)
188  {
189  /* Advance the color 0-7 by 8 to get the light version */
190  *col += 8;
191  }
192  }
193  }
194  }
195 
196  return MUTT_CMD_SUCCESS;
197 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const struct Mapping ColorNames[]
Definition: color.c:66
#define RGB24
Definition: color.h:101
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:37
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition: command.h:35
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition: command.h:36
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
#define _(a)
Definition: message.h:28
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:170
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:53

◆ get_colorid_name()

void get_colorid_name ( unsigned int  cid,
struct Buffer buf 
)

Get the name of a color id.

Parameters
cidColour, e.g. MT_COLOR_HEADER
bufBuffer for result

Definition at line 308 of file command.c.

309 {
310  const char *name = NULL;
311 
313  {
315  if (name)
316  {
317  mutt_buffer_printf(buf, "compose %s", name);
318  return;
319  }
320  }
321 
322  name = mutt_map_get_name(cid, ColorFields);
323  if (name)
324  mutt_buffer_printf(buf, "%s", name);
325  else
326  mutt_buffer_printf(buf, "UNKNOWN %d", cid);
327 }
const struct Mapping ComposeColorFields[]
Mapping of compose colour names to their IDs.
Definition: command.c:97
const struct Mapping ColorFields[]
Mapping of colour names to their IDs.
Definition: command.c:44
@ MT_COLOR_COMPOSE_SECURITY_SIGN
Mail will be signed.
Definition: color.h:45
@ MT_COLOR_COMPOSE_HEADER
Header labels, e.g. From:
Definition: color.h:41
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
+ Here is the call graph for this function:

◆ parse_object()

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

Identify a colour object.

Parameters
[in]bufTemporary Buffer space
[in]sBuffer containing string to be parsed
[out]cidObject 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

Identify a colour object, e.g. "quoted", "compose header"

Definition at line 308 of file command.c.

342 {
343  int rc;
344 
345  if (mutt_str_startswith(buf->data, "quoted") != 0)
346  {
347  int val = 0;
348  if (buf->data[6] != '\0')
349  {
350  if (!mutt_str_atoi_full(buf->data + 6, &val) || (val > COLOR_QUOTES_MAX))
351  {
352  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
353  return MUTT_CMD_WARNING;
354  }
355  }
356 
357  *ql = val;
358  *cid = MT_COLOR_QUOTED;
359  return MUTT_CMD_SUCCESS;
360  }
361 
362  if (mutt_istr_equal(buf->data, "compose"))
363  {
364  if (!MoreArgs(s))
365  {
366  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
367  return MUTT_CMD_WARNING;
368  }
369 
371 
373  if (rc == -1)
374  {
375  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
376  return MUTT_CMD_WARNING;
377  }
378 
379  *cid = rc;
380  return MUTT_CMD_SUCCESS;
381  }
382 
383  rc = mutt_map_get_value(buf->data, ColorFields);
384  if (rc == -1)
385  {
386  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
387  return MUTT_CMD_WARNING;
388  }
389 
390  *cid = rc;
391  return MUTT_CMD_SUCCESS;
392 }
#define MoreArgs(buf)
Definition: buffer.h:40
@ MT_COLOR_QUOTED
Pager: quoted text.
Definition: color.h:57
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:399
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:727
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:158
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: quoted.h:35
char * data
Pointer to data.
Definition: buffer.h:35

◆ do_uncolor()

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

Parse the 'uncolor' or 'unmono' command.

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

Definition at line 402 of file command.c.

404 {
405  struct RegexColor *np = NULL, *prev = NULL;
406  bool rc = false;
407 
408  do
409  {
411  if (mutt_str_equal("*", buf->data))
412  {
413  rc = STAILQ_FIRST(cl);
415  return rc;
416  }
417 
418  prev = NULL;
419  STAILQ_FOREACH(np, cl, entries)
420  {
421  if (mutt_str_equal(buf->data, np->pattern))
422  {
423  rc = true;
424 
425  mutt_debug(LL_DEBUG1, "Freeing pattern \"%s\" from user_colors\n", buf->data);
426  if (prev)
427  STAILQ_REMOVE_AFTER(cl, prev, entries);
428  else
429  STAILQ_REMOVE_HEAD(cl, entries);
430  regex_color_free(&np, uncolor);
431  break;
432  }
433  prev = np;
434  }
435  } while (MoreArgs(s));
436 
437  return rc;
438 }
void regex_color_free(struct RegexColor **ptr, bool free_colors)
Free a RegexColor.
Definition: regex.c:63
void regex_color_list_clear(struct RegexColorList *rcl)
Clear a list of colours.
Definition: regex.c:83
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:715
#define STAILQ_REMOVE_HEAD(head, field)
Definition: queue.h:422
#define STAILQ_FIRST(head)
Definition: queue.h:350
#define STAILQ_REMOVE_AFTER(head, elm, field)
Definition: queue.h:416
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A regular expression and a color to highlight a line.
Definition: regex4.h:36
char * pattern
Pattern to match.
Definition: regex4.h:37
+ Here is the call graph for this function:

◆ parse_uncolor()

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

Parse an 'uncolor' command.

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

Usage:

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

Definition at line 402 of file command.c.

454 {
456 
457  if (mutt_str_equal(buf->data, "*"))
458  {
459  mutt_debug(LL_NOTIFY, "NT_COLOR_RESET: [ALL]\n");
460  colors_clear();
461  struct EventColor ev_c = { MT_COLOR_MAX };
463  return MUTT_CMD_SUCCESS;
464  }
465 
466  unsigned int cid = MT_COLOR_NONE;
467  int ql = 0;
468  enum CommandResult rc = parse_object(buf, s, &cid, &ql, err);
469  if (rc != MUTT_CMD_SUCCESS)
470  return rc;
471 
472  if (cid == -1)
473  {
474  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
475  return MUTT_CMD_ERROR;
476  }
477 
478  if (cid == MT_COLOR_QUOTED)
479  {
480  QuotedColors[ql] = A_NORMAL;
481  /* fallthrough to simple case */
482  }
483 
484  if ((cid != MT_COLOR_ATTACH_HEADERS) && (cid != MT_COLOR_BODY) &&
488  {
489  // Simple colours
490  SimpleColors[cid] = A_NORMAL;
491 
492  get_colorid_name(cid, buf);
493  mutt_debug(LL_NOTIFY, "NT_COLOR_RESET: %s\n", buf->data);
494  struct EventColor ev_c = { cid };
496  return MUTT_CMD_SUCCESS;
497  }
498 
499  if (!MoreArgs(s))
500  {
501  mutt_buffer_printf(err, _("%s: too few arguments"), uncolor ? "uncolor" : "unmono");
502  return MUTT_CMD_WARNING;
503  }
504 
505  if (OptNoCurses || // running without curses
506  (uncolor && !has_colors()) || // parsing an uncolor command, and have no colors
507  (!uncolor && has_colors())) // parsing an unmono command, and have colors
508  {
509  do
510  {
511  /* just eat the command, but don't do anything real about it */
513  } while (MoreArgs(s));
514 
515  return MUTT_CMD_SUCCESS;
516  }
517 
518  bool changed = false;
520  changed |= do_uncolor(buf, s, regex_colors_get_list(MT_COLOR_ATTACH_HEADERS), uncolor);
521  else if (cid == MT_COLOR_BODY)
522  changed |= do_uncolor(buf, s, regex_colors_get_list(MT_COLOR_BODY), uncolor);
523  else if (cid == MT_COLOR_HEADER)
524  changed |= do_uncolor(buf, s, regex_colors_get_list(MT_COLOR_HEADER), uncolor);
525  else if (cid == MT_COLOR_INDEX)
526  changed |= do_uncolor(buf, s, regex_colors_get_list(MT_COLOR_INDEX), uncolor);
527  else if (cid == MT_COLOR_INDEX_AUTHOR)
528  changed |= do_uncolor(buf, s, regex_colors_get_list(MT_COLOR_INDEX_AUTHOR), uncolor);
529  else if (cid == MT_COLOR_INDEX_FLAGS)
530  changed |= do_uncolor(buf, s, regex_colors_get_list(MT_COLOR_INDEX_FLAGS), uncolor);
531  else if (cid == MT_COLOR_INDEX_SUBJECT)
532  changed |= do_uncolor(buf, s, regex_colors_get_list(MT_COLOR_INDEX_SUBJECT), uncolor);
533  else if (cid == MT_COLOR_INDEX_TAG)
534  changed |= do_uncolor(buf, s, regex_colors_get_list(MT_COLOR_INDEX_TAG), uncolor);
535  else if (cid == MT_COLOR_STATUS)
536  changed |= do_uncolor(buf, s, regex_colors_get_list(MT_COLOR_STATUS), uncolor);
537 
538  if (changed)
539  {
540  get_colorid_name(cid, buf);
541  mutt_debug(LL_NOTIFY, "NT_COLOR_RESET: %s\n", buf->data);
542  struct EventColor ev_c = { cid };
544  }
545 
546  return MUTT_CMD_SUCCESS;
547 }
void get_colorid_name(unsigned int cid, struct Buffer *buf)
Get the name of a color id.
Definition: command.c:308
static enum CommandResult parse_object(struct Buffer *buf, struct Buffer *s, enum ColorId *cid, int *ql, struct Buffer *err)
Identify a colour object.
Definition: command.c:340
static bool do_uncolor(struct Buffer *buf, struct Buffer *s, struct RegexColorList *cl, bool uncolor)
Parse the 'uncolor' or 'unmono' command.
Definition: command.c:402
struct Notify * ColorsNotify
Notifications: ColorId, EventColor.
Definition: notify.c:33
struct RegexColorList * regex_colors_get_list(enum ColorId cid)
Return the RegexColorList for a colour id.
Definition: regex.c:130
int SimpleColors[MT_COLOR_MAX]
Array of all fixed colours, see enum ColorId.
Definition: simple.c:36
void colors_clear(void)
Reset all the colours.
Definition: color.c:151
@ MT_COLOR_INDEX_AUTHOR
Index: author field (takes a pattern)
Definition: color.h:77
@ MT_COLOR_MAX
Definition: color.h:88
@ MT_COLOR_HEADER
Message headers (takes a pattern)
Definition: color.h:48
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:70
@ MT_COLOR_NONE
Definition: color.h:36
@ MT_COLOR_INDEX_SUBJECT
Index: subject field (takes a pattern)
Definition: color.h:79
@ MT_COLOR_BODY
Pager: highlight body of message (takes a pattern)
Definition: color.h:39
@ MT_COLOR_INDEX_TAG
Index: tag field (g, takes a pattern)
Definition: color.h:80
@ MT_COLOR_ATTACH_HEADERS
MIME attachment test (takes a pattern)
Definition: color.h:38
@ MT_COLOR_INDEX
Index: default colour (takes a pattern)
Definition: color.h:76
@ MT_COLOR_INDEX_FLAGS
Index: flags field (takes a pattern)
Definition: color.h:78
CommandResult
Error codes for command_t parse functions.
Definition: command.h:34
@ LL_NOTIFY
Log of notifications.
Definition: logging.h:45
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
@ NT_COLOR_RESET
Color has been reset/removed.
Definition: notify2.h:42
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
int QuotedColors[COLOR_QUOTES_MAX]
Array of colours for quoted email text.
Definition: quoted.c:38
An Event that happened to a Colour.
Definition: notify2.h:53
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:54

◆ fgbgattr_to_color()

int fgbgattr_to_color ( int  fg,
int  bg,
int  attrs 
)

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

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

Definition at line 556 of file command.c.

557 {
558  if ((fg != COLOR_UNSET) && (bg != COLOR_UNSET))
559  return attrs | mutt_color_alloc(fg, bg);
560  return attrs;
561 }
int mutt_color_alloc(uint32_t fg, uint32_t bg)
Allocate a colour pair.
Definition: color.c:188
#define COLOR_UNSET
Definition: color.h:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_color()

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

Parse a 'color' command.

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

Usage:

  • color OBJECT [ ATTRS ] FG BG [ REGEX ]
  • mono OBJECT ATTRS [ REGEX ]

Definition at line 556 of file command.c.

580 {
581  int attrs = 0, q_level = 0;
582  uint32_t fg = 0, bg = 0, match = 0;
583  enum ColorId cid = MT_COLOR_NONE;
584  enum CommandResult rc;
585 
586  if (!MoreArgs(s))
587  {
588  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
589  return MUTT_CMD_WARNING;
590  }
591 
593 
594  rc = parse_object(buf, s, &cid, &q_level, err);
595  if (rc != MUTT_CMD_SUCCESS)
596  return rc;
597 
598  rc = callback(buf, s, &fg, &bg, &attrs, err);
599  if (rc != MUTT_CMD_SUCCESS)
600  return rc;
601 
602  /* extract a regular expression if needed */
603 
604  if ((cid == MT_COLOR_ATTACH_HEADERS) || (cid == MT_COLOR_BODY) ||
605  (cid == MT_COLOR_HEADER) || (cid == MT_COLOR_INDEX) ||
606  (cid == MT_COLOR_INDEX_AUTHOR) || (cid == MT_COLOR_INDEX_FLAGS) ||
607  (cid == MT_COLOR_INDEX_SUBJECT) || (cid == MT_COLOR_INDEX_TAG))
608  {
609  if (!MoreArgs(s))
610  {
611  mutt_buffer_printf(err, _("%s: too few arguments"), color ? "color" : "mono");
612  return MUTT_CMD_WARNING;
613  }
614 
616  }
617 
618  if (MoreArgs(s) && (cid != MT_COLOR_STATUS))
619  {
620  mutt_buffer_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
621  return MUTT_CMD_WARNING;
622  }
623 
624  if (dry_run)
625  {
626  *s->dptr = '\0'; /* fake that we're done parsing */
627  return MUTT_CMD_SUCCESS;
628  }
629 
630  if (!OptNoCurses &&
631  has_colors()
632  /* delay use_default_colors() until needed, since it initializes things */
633  && ((fg == COLOR_DEFAULT) || (bg == COLOR_DEFAULT) || (cid == MT_COLOR_TREE)) &&
634  (use_default_colors() != OK))
635  /* the case of the tree cid is special, because a non-default fg color of
636  * the tree element may be combined dynamically with the default bg color of
637  * an index line, not necessarily defined in a rc file. */
638  {
639  mutt_buffer_strcpy(err, _("default colors not supported"));
640  return MUTT_CMD_ERROR;
641  }
642 
643  if (regex_colors_parse_color_list(cid, buf->data, fg, bg, attrs, &rc, err))
644  {
645  // do nothing
646  }
647  else if (quoted_colors_parse_color(cid, fg, bg, attrs, q_level, &rc, err))
648  {
649  // do nothing
650  }
651  else if ((cid == MT_COLOR_STATUS) && MoreArgs(s))
652  {
653  /* 'color status fg bg' can have up to 2 arguments:
654  * 0 arguments: sets the default status color (handled below by else part)
655  * 1 argument : colorize pattern on match
656  * 2 arguments: colorize nth submatch of pattern */
658 
659  if (MoreArgs(s))
660  {
661  struct Buffer tmp = mutt_buffer_make(0);
663  if (!mutt_str_atoui_full(tmp.data, &match))
664  {
665  mutt_buffer_printf(err, _("%s: invalid number: %s"),
666  color ? "color" : "mono", tmp.data);
667  mutt_buffer_dealloc(&tmp);
668  return MUTT_CMD_WARNING;
669  }
670  mutt_buffer_dealloc(&tmp);
671  }
672 
673  if (MoreArgs(s))
674  {
675  mutt_buffer_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
676  return MUTT_CMD_WARNING;
677  }
678 
679  rc = regex_colors_parse_status_list(cid, buf->data, fg, bg, attrs, match, err);
680  }
681  else // Remaining simple colours
682  {
683  SimpleColors[cid] = fgbgattr_to_color(fg, bg, attrs);
684  rc = MUTT_CMD_SUCCESS;
685  }
686 
687  if (rc == MUTT_CMD_SUCCESS)
688  {
689  get_colorid_name(cid, buf);
690  mutt_debug(LL_NOTIFY, "NT_COLOR_SET: %s\n", buf->data);
691  struct EventColor ev_c = { cid };
693  }
694 
695  return rc;
696 }
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
int fgbgattr_to_color(int fg, int bg, int attrs)
Convert a foreground, background, attribute triplet into a colour.
Definition: command.c:556
bool regex_colors_parse_color_list(enum ColorId cid, const char *pat, uint32_t fg, uint32_t bg, int attrs, int *rc, struct Buffer *err)
Parse a Regex 'color' command.
Definition: regex.c:290
int regex_colors_parse_status_list(enum ColorId cid, const char *pat, uint32_t fg, uint32_t bg, int attrs, int match, struct Buffer *err)
Parse a Regex 'color status' command.
Definition: regex.c:338
#define COLOR_DEFAULT
Definition: color.h:103
ColorId
List of all colored objects.
Definition: color.h:35
@ MT_COLOR_TREE
Index: tree-drawing characters.
Definition: color.h:72
@ NT_COLOR_SET
Color has been set.
Definition: notify2.h:41
bool quoted_colors_parse_color(enum ColorId cid, uint32_t fg, uint32_t bg, int attrs, int q_level, int *rc, struct Buffer *err)
Parse the 'color quoted' command.
Definition: quoted.c:92
String manipulation buffer.
Definition: buffer.h:34
char * dptr
Current read/write position.
Definition: buffer.h:36

Variable Documentation

◆ ColorFields

const struct Mapping ColorFields[]

Mapping of colour names to their IDs.

Definition at line 1 of file command.c.

◆ ComposeColorFields

const struct Mapping ComposeColorFields[]
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 }
}
@ MT_COLOR_COMPOSE_SECURITY_ENCRYPT
Mail will be encrypted.
Definition: color.h:43
@ MT_COLOR_COMPOSE_SECURITY_NONE
Mail will not be encrypted or signed.
Definition: color.h:44
@ MT_COLOR_COMPOSE_SECURITY_BOTH
Mail will be encrypted and signed.
Definition: color.h:42

Mapping of compose colour names to their IDs.

Definition at line 1 of file command.c.