NeoMutt  2018-07-16 +952-a2da0a
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 "mutt.h"
#include "color.h"
#include "context.h"
#include "globals.h"
#include "keymap.h"
#include "mailbox.h"
#include "menu.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_QUOTE_INIT   8
 

Typedefs

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

Functions

static struct ColorLinenew_color_line (void)
 Create a new ColorLine. More...
 
static void free_color_line (struct ColorLine *tmp, bool free_colors)
 Free a ColorLine. More...
 
void ci_start_color (void)
 Set up the default colours. More...
 
static void do_uncolor (struct Buffer *buf, struct Buffer *s, struct ColorLineHead *cl, bool *do_cache, bool parse_uncolor)
 Parse the "uncolor" or "unmono" command. More...
 
static int parse_uncolor (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err, bool parse_uncolor)
 Parse an 'uncolor' command. More...
 
int mutt_parse_unmono (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unmono' command - Implements command_t. More...
 
static int add_pattern (struct ColorLineHead *top, const char *s, bool sensitive, int fg, int bg, int attr, struct Buffer *err, bool is_index, int match)
 Associate a colour to a pattern. More...
 
static int parse_object (struct Buffer *buf, struct Buffer *s, int *o, int *ql, struct Buffer *err)
 Parse a colour config line. More...
 
static int parse_attr_spec (struct Buffer *buf, struct Buffer *s, int *fg, int *bg, int *attr, struct Buffer *err)
 Parse an attribute description - Implements parser_callback_t. More...
 
static int fgbgattr_to_color (int fg, int bg, int attr)
 Convert a foreground, background, attribute triplet into a colour. More...
 
static int 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...
 
int mutt_parse_mono (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'mono' command - Implements command_t. More...
 
static void mutt_free_color_list (struct ColorLineHead *head)
 Free a list of colours. More...
 
void mutt_free_colors (void)
 Free all the colours (on shutdown) More...
 

Variables

int * ColorQuote = NULL
 Array of colours for quoted email text. More...
 
int ColorQuoteUsed
 Number of colours for quoted email text. More...
 
int ColorDefs [MT_COLOR_MAX]
 Array of all fixed colours, see enum ColorId. More...
 
struct ColorLineHead ColorAttachList = STAILQ_HEAD_INITIALIZER(ColorAttachList)
 List of colours applied to the attachment headers. More...
 
struct ColorLineHead ColorBodyList = STAILQ_HEAD_INITIALIZER(ColorBodyList)
 List of colours applied to the email body. More...
 
struct ColorLineHead ColorHdrList = STAILQ_HEAD_INITIALIZER(ColorHdrList)
 List of colours applied to the email headers. More...
 
struct ColorLineHead ColorIndexAuthorList = STAILQ_HEAD_INITIALIZER(ColorIndexAuthorList)
 List of colours applied to the author in the index. More...
 
struct ColorLineHead ColorIndexFlagsList = STAILQ_HEAD_INITIALIZER(ColorIndexFlagsList)
 List of colours applied to the flags in the index. More...
 
struct ColorLineHead ColorIndexList = STAILQ_HEAD_INITIALIZER(ColorIndexList)
 List of default colours applied to the index. More...
 
struct ColorLineHead ColorIndexSubjectList = STAILQ_HEAD_INITIALIZER(ColorIndexSubjectList)
 List of colours applied to the subject in the index. More...
 
struct ColorLineHead ColorIndexTagList = STAILQ_HEAD_INITIALIZER(ColorIndexTagList)
 List of colours applied to tags in the index. More...
 
struct ColorLineHead ColorStatusList = STAILQ_HEAD_INITIALIZER(ColorStatusList)
 List of colours applied to the status bar. More...
 
static int ColorQuoteSize
 
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

#define COLOR_QUOTE_INIT   8

Definition at line 154 of file color.c.

Typedef Documentation

typedef int(* parser_callback_t) (struct Buffer *buf, struct Buffer *s, int *fg, int *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 877 of file color.c.

Function Documentation

static struct ColorLine* new_color_line ( void  )
static

Create a new ColorLine.

Return values
ptrNewly allocated ColorLine

Definition at line 160 of file color.c.

161 {
162  struct ColorLine *p = mutt_mem_calloc(1, sizeof(struct ColorLine));
163 
164  p->fg = -1;
165  p->bg = -1;
166  return p;
167 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
short fg
Definition: mutt_curses.h:185
short bg
Definition: mutt_curses.h:186
A regular expression and a color to highlight a line.
Definition: mutt_curses.h:178

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void free_color_line ( struct ColorLine tmp,
bool  free_colors 
)
static

Free a ColorLine.

Parameters
tmpColorLine to free
free_colorsIf true, free its colours too

Definition at line 174 of file color.c.

175 {
176  if (!tmp)
177  return;
178 
179 #ifdef HAVE_COLOR
180  if (free_colors && (tmp->fg != -1) && (tmp->bg != -1))
181  mutt_free_color(tmp->fg, tmp->bg);
182 #endif
183 
184  /* we should really introduce a container
185  * type for regular expressions.
186  */
187 
188  regfree(&tmp->regex);
190  FREE(&tmp->pattern);
191  FREE(&tmp);
192 }
char * pattern
Definition: mutt_curses.h:182
void mutt_pattern_free(struct Pattern **pat)
Free a Pattern.
Definition: pattern.c:1248
struct Pattern * color_pattern
compiled pattern to speed up index color calculation
Definition: mutt_curses.h:183
void mutt_free_color(int fg, int bg)
regex_t regex
Definition: mutt_curses.h:180
short fg
Definition: mutt_curses.h:185
#define FREE(x)
Definition: memory.h:46
short bg
Definition: mutt_curses.h:186

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ci_start_color ( void  )

Set up the default colours.

Definition at line 197 of file color.c.

198 {
199  memset(ColorDefs, A_NORMAL, sizeof(int) * MT_COLOR_MAX);
201  memset(ColorQuote, A_NORMAL, sizeof(int) * COLOR_QUOTE_INIT);
203  ColorQuoteUsed = 0;
204 
205  /* set some defaults */
206  ColorDefs[MT_COLOR_STATUS] = A_REVERSE;
207  ColorDefs[MT_COLOR_INDICATOR] = A_REVERSE;
208  ColorDefs[MT_COLOR_SEARCH] = A_REVERSE;
209  ColorDefs[MT_COLOR_MARKERS] = A_REVERSE;
210 #ifdef USE_SIDEBAR
211  ColorDefs[MT_COLOR_HIGHLIGHT] = A_UNDERLINE;
212 #endif
213  /* special meaning: toggle the relevant attribute */
216 
217 #ifdef HAVE_COLOR
218  start_color();
219 #endif
220 }
int * ColorQuote
Array of colours for quoted email text.
Definition: color.c:49
Bold text.
Definition: mutt_curses.h:140
static int ColorQuoteSize
Definition: color.c:63
int ColorQuoteUsed
Number of colours for quoted email text.
Definition: color.c:50
Pager: search matches.
Definition: mutt_curses.h:139
Pager: markers, line continuation.
Definition: mutt_curses.h:133
Underlined text.
Definition: mutt_curses.h:141
Select cursor.
Definition: mutt_curses.h:147
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:99
#define COLOR_QUOTE_INIT
Definition: color.c:154
int ColorDefs[MT_COLOR_MAX]
Array of all fixed colours, see enum ColorId.
Definition: color.c:51
Status bar.
Definition: mutt_curses.h:128
Selected item in list.
Definition: mutt_curses.h:127

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void do_uncolor ( struct Buffer buf,
struct Buffer s,
struct ColorLineHead *  cl,
bool *  do_cache,
bool  parse_uncolor 
)
static

Parse the "uncolor" or "unmono" command.

Parameters
[in]bufBuffer for temporary storage
[in]sBuffer containing the uncolor command
[in]clList of existing colours
[in,out]do_cacheSet to true if colours were freed
[in]parse_uncolorIf true, 'uncolor', else 'unmono'

Definition at line 520 of file color.c.

522 {
523  struct ColorLine *np = NULL, *tmp = NULL;
524  do
525  {
526  mutt_extract_token(buf, s, 0);
527  if (mutt_str_strcmp("*", buf->data) == 0)
528  {
529  np = STAILQ_FIRST(cl);
530  while (np)
531  {
532  tmp = STAILQ_NEXT(np, entries);
533  if (!*do_cache)
534  {
535  *do_cache = true;
536  }
538  np = tmp;
539  }
540  STAILQ_INIT(cl);
541  return;
542  }
543  else
544  {
545  tmp = NULL;
546  STAILQ_FOREACH(np, cl, entries)
547  {
548  if (mutt_str_strcmp(buf->data, np->pattern) == 0)
549  {
550  if (!*do_cache)
551  {
552  *do_cache = true;
553  }
554  mutt_debug(1, "Freeing pattern \"%s\" from ColorList\n", buf->data);
555  if (tmp)
556  STAILQ_REMOVE_AFTER(cl, tmp, entries);
557  else
558  STAILQ_REMOVE_HEAD(cl, entries);
560  break;
561  }
562  tmp = np;
563  }
564  }
565  } while (MoreArgs(s));
566 }
static int parse_uncolor(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err, bool parse_uncolor)
Parse an &#39;uncolor&#39; command.
Definition: color.c:582
char * pattern
Definition: mutt_curses.h:182
#define STAILQ_REMOVE_HEAD(head, field)
Definition: queue.h:420
#define MoreArgs(buf)
Definition: buffer.h:44
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags)
Extract one token from a string.
Definition: init.c:2520
#define STAILQ_INIT(head)
Definition: queue.h:370
static void free_color_line(struct ColorLine *tmp, bool free_colors)
Free a ColorLine.
Definition: color.c:174
char * data
pointer to data
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
#define STAILQ_NEXT(elm, field)
Definition: queue.h:398
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
#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:612
A regular expression and a color to highlight a line.
Definition: mutt_curses.h:178

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int parse_uncolor ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err,
bool  parse_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
parse_uncolorIf true, 'uncolor', else 'unmono'
Return values
0Success
-1Error

usage:

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

Definition at line 582 of file color.c.

584 {
585  int object = 0;
586  bool do_cache = false;
587 
588  mutt_extract_token(buf, s, 0);
589 
590  object = mutt_map_get_value(buf->data, Fields);
591  if (object == -1)
592  {
593  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
594  return -1;
595  }
596 
597  if (object > MT_COLOR_INDEX_SUBJECT)
598  { /* uncolor index column */
599  ColorDefs[object] = 0;
601  return 0;
602  }
603 
604  if (!mutt_str_startswith(buf->data, "body", CASE_MATCH) &&
605  !mutt_str_startswith(buf->data, "header", CASE_MATCH) &&
606  !mutt_str_startswith(buf->data, "index", CASE_MATCH))
607  {
608  mutt_buffer_printf(err, _("%s: command valid only for index, body, header objects"),
609  parse_uncolor ? "uncolor" : "unmono");
610  return -1;
611  }
612 
613  if (!MoreArgs(s))
614  {
615  mutt_buffer_printf(err, _("%s: too few arguments"), parse_uncolor ? "uncolor" : "unmono");
616  return -1;
617  }
618 
619  if (
620 #ifdef HAVE_COLOR
621  /* we're running without curses */
622  OptNoCurses || /* we're parsing an uncolor command, and have no colors */
623  (parse_uncolor && !has_colors())
624  /* we're parsing an unmono command, and have colors */
625  || (!parse_uncolor && has_colors())
626 #else
627  /* We don't even have colors compiled in */
629 #endif
630  )
631  {
632  /* just eat the command, but don't do anything real about it */
633  do
634  mutt_extract_token(buf, s, 0);
635  while (MoreArgs(s));
636 
637  return 0;
638  }
639 
640  if (object == MT_COLOR_BODY)
641  do_uncolor(buf, s, &ColorBodyList, &do_cache, parse_uncolor);
642  else if (object == MT_COLOR_HEADER)
643  do_uncolor(buf, s, &ColorHdrList, &do_cache, parse_uncolor);
644  else if (object == MT_COLOR_ATTACH_HEADERS)
645  do_uncolor(buf, s, &ColorAttachList, &do_cache, parse_uncolor);
646  else if (object == MT_COLOR_INDEX)
647  do_uncolor(buf, s, &ColorIndexList, &do_cache, parse_uncolor);
648  else if (object == MT_COLOR_INDEX_AUTHOR)
649  do_uncolor(buf, s, &ColorIndexAuthorList, &do_cache, parse_uncolor);
650  else if (object == MT_COLOR_INDEX_FLAGS)
651  do_uncolor(buf, s, &ColorIndexFlagsList, &do_cache, parse_uncolor);
652  else if (object == MT_COLOR_INDEX_SUBJECT)
653  do_uncolor(buf, s, &ColorIndexSubjectList, &do_cache, parse_uncolor);
654  else if (object == MT_COLOR_INDEX_TAG)
655  do_uncolor(buf, s, &ColorIndexTagList, &do_cache, parse_uncolor);
656 
657  bool is_index = ((object == MT_COLOR_INDEX) || (object == MT_COLOR_INDEX_AUTHOR) ||
658  (object == MT_COLOR_INDEX_FLAGS) || (object == MT_COLOR_INDEX_SUBJECT) ||
659  (object == MT_COLOR_INDEX_TAG));
660 
661  if (is_index && do_cache && !OptNoCurses)
662  {
664  /* force re-caching of index colors */
665  for (int i = 0; Context && i < Context->mailbox->msg_count; i++)
666  Context->mailbox->hdrs[i]->pair = 0;
667  }
668  return 0;
669 }
Index: subject field (takes a pattern)
Definition: mutt_curses.h:159
The "current" mailbox.
Definition: context.h:36
int msg_count
total number of messages
Definition: mailbox.h:86
struct ColorLineHead ColorIndexFlagsList
List of colours applied to the flags in the index.
Definition: color.c:56
static int parse_uncolor(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err, bool parse_uncolor)
Parse an &#39;uncolor&#39; command.
Definition: color.c:582
static void do_uncolor(struct Buffer *buf, struct Buffer *s, struct ColorLineHead *cl, bool *do_cache, bool parse_uncolor)
Parse the "uncolor" or "unmono" command.
Definition: color.c:520
struct ColorLineHead ColorBodyList
List of colours applied to the email body.
Definition: color.c:53
#define _(a)
Definition: message.h:28
Message headers (takes a pattern)
Definition: mutt_curses.h:135
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:45
Match case when comparing strings.
Definition: string2.h:69
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:200
struct Email ** hdrs
Definition: mailbox.h:93
#define MoreArgs(buf)
Definition: buffer.h:44
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags)
Extract one token from a string.
Definition: init.c:2520
struct Mailbox * mailbox
Definition: context.h:50
Index: default colour (takes a pattern)
Definition: mutt_curses.h:155
struct ColorLineHead ColorIndexAuthorList
List of colours applied to the author in the index.
Definition: color.c:55
Index: tag field (g, takes a pattern)
Definition: mutt_curses.h:158
Index: flags field (takes a pattern)
Definition: mutt_curses.h:157
Index: author field (takes a pattern)
Definition: mutt_curses.h:156
char * data
pointer to data
Definition: buffer.h:35
Pager: highlight body of message (takes a pattern)
Definition: mutt_curses.h:134
struct ColorLineHead ColorHdrList
List of colours applied to the email headers.
Definition: color.c:54
int ColorDefs[MT_COLOR_MAX]
Array of all fixed colours, see enum ColorId.
Definition: color.c:51
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:166
MIME attachment test (takes a pattern)
Definition: mutt_curses.h:138
struct ColorLineHead ColorIndexSubjectList
List of colours applied to the subject in the index.
Definition: color.c:58
struct ColorLineHead ColorIndexTagList
List of colours applied to tags in the index.
Definition: color.c:59
struct ColorLineHead ColorIndexList
List of default colours applied to the index.
Definition: color.c:57
int pair
color-pair to use when displaying in the index
Definition: email.h:81
Index panel (list of emails)
Definition: keymap.h:73
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:101
struct ColorLineHead ColorAttachList
List of colours applied to the attachment headers.
Definition: color.c:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

689 {
690  return parse_uncolor(buf, s, data, err, false);
691 }
static int parse_uncolor(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err, bool parse_uncolor)
Parse an &#39;uncolor&#39; command.
Definition: color.c:582

+ Here is the call graph for this function:

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

Associate a colour to a pattern.

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

Definition at line 707 of file color.c.

709 {
710  /* is_index used to store compiled pattern
711  * only for `index' color object
712  * when called from mutt_parse_color() */
713 
714  struct ColorLine *tmp = NULL;
715 
716  STAILQ_FOREACH(tmp, top, entries)
717  {
718  if (sensitive)
719  {
720  if (mutt_str_strcmp(s, tmp->pattern) == 0)
721  break;
722  }
723  else
724  {
725  if (mutt_str_strcasecmp(s, tmp->pattern) == 0)
726  break;
727  }
728  }
729 
730  if (tmp)
731  {
732 #ifdef HAVE_COLOR
733  if (fg != -1 && bg != -1)
734  {
735  if (tmp->fg != fg || tmp->bg != bg)
736  {
737  mutt_free_color(tmp->fg, tmp->bg);
738  tmp->fg = fg;
739  tmp->bg = bg;
740  attr |= mutt_alloc_color(fg, bg);
741  }
742  else
743  attr |= (tmp->pair & ~A_BOLD);
744  }
745 #endif /* HAVE_COLOR */
746  tmp->pair = attr;
747  }
748  else
749  {
750  tmp = new_color_line();
751  if (is_index)
752  {
753  char buf[LONG_STRING];
754  mutt_str_strfcpy(buf, s, sizeof(buf));
755  mutt_check_simple(buf, sizeof(buf), NONULL(SimpleSearch));
757  if (!tmp->color_pattern)
758  {
759  free_color_line(tmp, true);
760  return -1;
761  }
762  }
763  else
764  {
765  int flags = 0;
766  if (sensitive)
767  flags = mutt_mb_is_lower(s) ? REG_ICASE : 0;
768  else
769  flags = REG_ICASE;
770 
771  const int r = REGCOMP(&tmp->regex, s, flags);
772  if (r != 0)
773  {
774  regerror(r, &tmp->regex, err->data, err->dsize);
775  free_color_line(tmp, true);
776  return -1;
777  }
778  }
779  tmp->pattern = mutt_str_strdup(s);
780  tmp->match = match;
781 #ifdef HAVE_COLOR
782  if (fg != -1 && bg != -1)
783  {
784  tmp->fg = fg;
785  tmp->bg = bg;
786  attr |= mutt_alloc_color(fg, bg);
787  }
788 #endif
789  tmp->pair = attr;
790  STAILQ_INSERT_HEAD(top, tmp, entries);
791  }
792 
793  /* force re-caching of index colors */
794  if (is_index)
795  {
796  for (int i = 0; Context && i < Context->mailbox->msg_count; i++)
797  Context->mailbox->hdrs[i]->pair = 0;
798  }
799 
800  return 0;
801 }
The "current" mailbox.
Definition: context.h:36
#define NONULL(x)
Definition: string2.h:39
int msg_count
total number of messages
Definition: mailbox.h:86
int mutt_alloc_color(int fg, int bg)
WHERE char * SimpleSearch
Config: Pattern to search for when search doesn&#39;t contain ~&#39;s.
Definition: globals.h:143
#define MUTT_FULL_MSG
Definition: pattern.h:39
char * pattern
Definition: mutt_curses.h:182
#define LONG_STRING
Definition: string2.h:36
struct Email ** hdrs
Definition: mailbox.h:93
int match
which substringmap 0 for old behaviour
Definition: mutt_curses.h:181
size_t dsize
length of data
Definition: buffer.h:37
struct Mailbox * mailbox
Definition: context.h:50
struct Pattern * color_pattern
compiled pattern to speed up index color calculation
Definition: mutt_curses.h:183
static struct ColorLine * new_color_line(void)
Create a new ColorLine.
Definition: color.c:160
static void free_color_line(struct ColorLine *tmp, bool free_colors)
Free a ColorLine.
Definition: color.c:174
char * data
pointer to data
Definition: buffer.h:35
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:742
#define STAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:381
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct Pattern * mutt_pattern_comp(char *s, int flags, struct Buffer *err)
Create a Pattern.
Definition: pattern.c:1289
void mutt_free_color(int fg, int bg)
regex_t regex
Definition: mutt_curses.h:180
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:384
short fg
Definition: mutt_curses.h:185
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:625
void mutt_check_simple(char *s, size_t len, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:2117
short bg
Definition: mutt_curses.h:186
bool mutt_mb_is_lower(const char *s)
Does a multi-byte string contain only lowercase characters?
Definition: mbyte.c:346
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:612
int pair
color-pair to use when displaying in the index
Definition: email.h:81
#define REGCOMP(X, Y, Z)
Compile a regular expression.
Definition: regex3.h:52
A regular expression and a color to highlight a line.
Definition: mutt_curses.h:178

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int parse_object ( struct Buffer buf,
struct Buffer s,
int *  o,
int *  ql,
struct Buffer err 
)
static

Parse a colour config line.

Parameters
[in]bufTemporary Buffer space
[in]sBuffer containing string to be parsed
[out]oIndex into the fields map
[out]qlQuote level
[out]errBuffer for error messages
Return values
0Success
-1Error

Definition at line 813 of file color.c.

815 {
816  if (!MoreArgs(s))
817  {
818  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
819  return -1;
820  }
821 
822  mutt_extract_token(buf, s, 0);
823  if (mutt_str_startswith(buf->data, "quoted", CASE_MATCH))
824  {
825  if (buf->data[6])
826  {
827  char *eptr = NULL;
828  *ql = strtol(buf->data + 6, &eptr, 10);
829  if (*eptr || *ql < 0)
830  {
831  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
832  return -1;
833  }
834  }
835  else
836  *ql = 0;
837 
838  *o = MT_COLOR_QUOTED;
839  }
840  else if (mutt_str_strcasecmp(buf->data, "compose") == 0)
841  {
842  if (!MoreArgs(s))
843  {
844  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
845  return -1;
846  }
847 
848  mutt_extract_token(buf, s, 0);
849 
851  if (*o == -1)
852  {
853  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
854  return -1;
855  }
856  }
857  else if ((*o = mutt_map_get_value(buf->data, Fields)) == -1)
858  {
859  mutt_buffer_printf(err, _("%s: no such object"), buf->data);
860  return -1;
861  }
862 
863  return 0;
864 }
static const struct Mapping ComposeFields[]
Definition: color.c:145
Pager: quoted text.
Definition: mutt_curses.h:125
#define _(a)
Definition: message.h:28
Match case when comparing strings.
Definition: string2.h:69
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:200
#define MoreArgs(buf)
Definition: buffer.h:44
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags)
Extract one token from a string.
Definition: init.c:2520
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:166
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:625
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:101

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Parse an attribute description - Implements parser_callback_t.

Definition at line 918 of file color.c.

920 {
921  if (fg)
922  *fg = -1;
923  if (bg)
924  *bg = -1;
925 
926  if (!MoreArgs(s))
927  {
928  mutt_buffer_printf(err, _("%s: too few arguments"), "mono");
929  return -1;
930  }
931 
932  mutt_extract_token(buf, s, 0);
933 
934  if (mutt_str_strcasecmp("bold", buf->data) == 0)
935  *attr |= A_BOLD;
936  else if (mutt_str_strcasecmp("underline", buf->data) == 0)
937  *attr |= A_UNDERLINE;
938  else if (mutt_str_strcasecmp("none", buf->data) == 0)
939  *attr = A_NORMAL;
940  else if (mutt_str_strcasecmp("reverse", buf->data) == 0)
941  *attr |= A_REVERSE;
942  else if (mutt_str_strcasecmp("standout", buf->data) == 0)
943  *attr |= A_STANDOUT;
944  else if (mutt_str_strcasecmp("normal", buf->data) == 0)
945  *attr = A_NORMAL; /* needs use = instead of |= to clear other bits */
946  else
947  {
948  mutt_buffer_printf(err, _("%s: no such attribute"), buf->data);
949  return -1;
950  }
951 
952  return 0;
953 }
#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:200
#define MoreArgs(buf)
Definition: buffer.h:44
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags)
Extract one token from a string.
Definition: init.c:2520
char * data
pointer to data
Definition: buffer.h:35
short fg
Definition: mutt_curses.h:185
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:625
short bg
Definition: mutt_curses.h:186

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

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

Definition at line 962 of file color.c.

963 {
964 #ifdef HAVE_COLOR
965  if (fg != -1 && bg != -1)
966  return attr | mutt_alloc_color(fg, bg);
967  else
968 #endif
969  return attr;
970 }
int mutt_alloc_color(int fg, int bg)
short fg
Definition: mutt_curses.h:185
short bg
Definition: mutt_curses.h:186

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int 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
0Success
-1Error

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

Definition at line 986 of file color.c.

988 {
989  int object = 0, attr = 0, fg = 0, bg = 0, q_level = 0;
990  int r = 0, match = 0;
991 
992  if (parse_object(buf, s, &object, &q_level, err) == -1)
993  return -1;
994 
995  if (callback(buf, s, &fg, &bg, &attr, err) == -1)
996  return -1;
997 
998  /* extract a regular expression if needed */
999 
1000  if ((object == MT_COLOR_BODY) || (object == MT_COLOR_HEADER) ||
1001  (object == MT_COLOR_ATTACH_HEADERS) || (object == MT_COLOR_INDEX) ||
1002  (object == MT_COLOR_INDEX_AUTHOR) || (object == MT_COLOR_INDEX_FLAGS) ||
1003  (object == MT_COLOR_INDEX_TAG) || (object == MT_COLOR_INDEX_SUBJECT))
1004  {
1005  if (!MoreArgs(s))
1006  {
1007  mutt_buffer_printf(err, _("%s: too few arguments"), color ? "color" : "mono");
1008  return -1;
1009  }
1010 
1011  mutt_extract_token(buf, s, 0);
1012  }
1013 
1014  if (MoreArgs(s) && (object != MT_COLOR_STATUS))
1015  {
1016  mutt_buffer_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
1017  return -1;
1018  }
1019 
1020  /* dry run? */
1021 
1022  if (dry_run)
1023  {
1024  *s->dptr = '\0'; /* fake that we're done parsing */
1025  return 0;
1026  }
1027 
1028 #ifdef HAVE_COLOR
1029 #ifdef HAVE_USE_DEFAULT_COLORS
1030  if (!OptNoCurses &&
1031  has_colors()
1032  /* delay use_default_colors() until needed, since it initializes things */
1033  && (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT || object == MT_COLOR_TREE) &&
1034  use_default_colors() != OK)
1035  /* the case of the tree object is special, because a non-default
1036  * fg color of the tree element may be combined dynamically with
1037  * the default bg color of an index line, not necessarily defined in
1038  * a rc file.
1039  */
1040  {
1041  mutt_buffer_strcpy(err, _("default colors not supported"));
1042  return -1;
1043  }
1044 #endif /* HAVE_USE_DEFAULT_COLORS */
1045 #endif
1046 
1047  if (object == MT_COLOR_HEADER)
1048  r = add_pattern(&ColorHdrList, buf->data, false, fg, bg, attr, err, false, match);
1049  else if (object == MT_COLOR_BODY)
1050  r = add_pattern(&ColorBodyList, buf->data, true, fg, bg, attr, err, false, match);
1051  else if (object == MT_COLOR_ATTACH_HEADERS)
1052  r = add_pattern(&ColorAttachList, buf->data, true, fg, bg, attr, err, false, match);
1053  else if ((object == MT_COLOR_STATUS) && MoreArgs(s))
1054  {
1055  /* 'color status fg bg' can have up to 2 arguments:
1056  * 0 arguments: sets the default status color (handled below by else part)
1057  * 1 argument : colorize pattern on match
1058  * 2 arguments: colorize nth submatch of pattern
1059  */
1060  mutt_extract_token(buf, s, 0);
1061 
1062  if (MoreArgs(s))
1063  {
1064  struct Buffer temporary = { 0 };
1065  mutt_extract_token(&temporary, s, 0);
1066  match = atoi(temporary.data);
1067  FREE(&temporary.data);
1068  }
1069 
1070  if (MoreArgs(s))
1071  {
1072  mutt_buffer_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
1073  return -1;
1074  }
1075 
1076  r = add_pattern(&ColorStatusList, buf->data, true, fg, bg, attr, err, false, match);
1077  }
1078  else if (object == MT_COLOR_INDEX)
1079  {
1080  r = add_pattern(&ColorIndexList, buf->data, true, fg, bg, attr, err, true, match);
1082  }
1083  else if (object == MT_COLOR_INDEX_AUTHOR)
1084  {
1085  r = add_pattern(&ColorIndexAuthorList, buf->data, true, fg, bg, attr, err, true, match);
1087  }
1088  else if (object == MT_COLOR_INDEX_FLAGS)
1089  {
1090  r = add_pattern(&ColorIndexFlagsList, buf->data, true, fg, bg, attr, err, true, match);
1092  }
1093  else if (object == MT_COLOR_INDEX_SUBJECT)
1094  {
1095  r = add_pattern(&ColorIndexSubjectList, buf->data, true, fg, bg, attr, err, true, match);
1097  }
1098  else if (object == MT_COLOR_INDEX_TAG)
1099  {
1100  r = add_pattern(&ColorIndexTagList, buf->data, true, fg, bg, attr, err, true, match);
1102  }
1103  else if (object == MT_COLOR_QUOTED)
1104  {
1105  if (q_level >= ColorQuoteSize)
1106  {
1107  mutt_mem_realloc(&ColorQuote, (ColorQuoteSize += 2) * sizeof(int));
1110  }
1111  if (q_level >= ColorQuoteUsed)
1112  ColorQuoteUsed = q_level + 1;
1113  if (q_level == 0)
1114  {
1115  ColorDefs[MT_COLOR_QUOTED] = fgbgattr_to_color(fg, bg, attr);
1116 
1118  for (q_level = 1; q_level < ColorQuoteUsed; q_level++)
1119  {
1120  if (ColorQuote[q_level] == A_NORMAL)
1121  ColorQuote[q_level] = ColorDefs[MT_COLOR_QUOTED];
1122  }
1123  }
1124  else
1125  ColorQuote[q_level] = fgbgattr_to_color(fg, bg, attr);
1126  }
1127  else
1128  {
1129  ColorDefs[object] = fgbgattr_to_color(fg, bg, attr);
1130  if (object > MT_COLOR_INDEX_AUTHOR)
1132  }
1133 
1134  return r;
1135 }
Index: subject field (takes a pattern)
Definition: mutt_curses.h:159
static int parse_object(struct Buffer *buf, struct Buffer *s, int *o, int *ql, struct Buffer *err)
Parse a colour config line.
Definition: color.c:813
int * ColorQuote
Array of colours for quoted email text.
Definition: color.c:49
struct ColorLineHead ColorIndexFlagsList
List of colours applied to the flags in the index.
Definition: color.c:56
Pager: quoted text.
Definition: mutt_curses.h:125
static int ColorQuoteSize
Definition: color.c:63
struct ColorLineHead ColorBodyList
List of colours applied to the email body.
Definition: color.c:53
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
Message headers (takes a pattern)
Definition: mutt_curses.h:135
int ColorQuoteUsed
Number of colours for quoted email text.
Definition: color.c:50
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:45
static int add_pattern(struct ColorLineHead *top, const char *s, bool sensitive, int fg, int bg, int attr, struct Buffer *err, bool is_index, int match)
Associate a colour to a pattern.
Definition: color.c:707
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:200
int match
which substringmap 0 for old behaviour
Definition: mutt_curses.h:181
#define MoreArgs(buf)
Definition: buffer.h:44
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags)
Extract one token from a string.
Definition: init.c:2520
Index: default colour (takes a pattern)
Definition: mutt_curses.h:155
struct ColorLineHead ColorIndexAuthorList
List of colours applied to the author in the index.
Definition: color.c:55
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:124
Index: tag field (g, takes a pattern)
Definition: mutt_curses.h:158
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:316
Index: flags field (takes a pattern)
Definition: mutt_curses.h:157
char * dptr
current read/write position
Definition: buffer.h:36
Index: author field (takes a pattern)
Definition: mutt_curses.h:156
char * data
pointer to data
Definition: buffer.h:35
Pager: highlight body of message (takes a pattern)
Definition: mutt_curses.h:134
Index: tree-drawing characters.
Definition: mutt_curses.h:129
struct ColorLineHead ColorHdrList
List of colours applied to the email headers.
Definition: color.c:54
static int fgbgattr_to_color(int fg, int bg, int attr)
Convert a foreground, background, attribute triplet into a colour.
Definition: color.c:962
int ColorDefs[MT_COLOR_MAX]
Array of all fixed colours, see enum ColorId.
Definition: color.c:51
short fg
Definition: mutt_curses.h:185
MIME attachment test (takes a pattern)
Definition: mutt_curses.h:138
struct ColorLineHead ColorIndexSubjectList
List of colours applied to the subject in the index.
Definition: color.c:58
struct ColorLineHead ColorIndexTagList
List of colours applied to tags in the index.
Definition: color.c:59
#define FREE(x)
Definition: memory.h:46
Status bar.
Definition: mutt_curses.h:128
short bg
Definition: mutt_curses.h:186
struct ColorLineHead ColorStatusList
List of colours applied to the status bar.
Definition: color.c:60
struct ColorLineHead ColorIndexList
List of default colours applied to the index.
Definition: color.c:57
Index panel (list of emails)
Definition: keymap.h:73
struct ColorLineHead ColorAttachList
List of colours applied to the attachment headers.
Definition: color.c:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1160 {
1161  bool dry_run = false;
1162 
1163 #ifdef HAVE_COLOR
1164  if (OptNoCurses || has_colors())
1165  dry_run = true;
1166 #else
1167  if (OptNoCurses)
1168  dry_run = true;
1169 #endif
1170 
1171  return parse_color(buf, s, err, parse_attr_spec, dry_run, false);
1172 }
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:45
static int parse_attr_spec(struct Buffer *buf, struct Buffer *s, int *fg, int *bg, int *attr, struct Buffer *err)
Parse an attribute description - Implements parser_callback_t.
Definition: color.c:918
static int parse_color(struct Buffer *buf, struct Buffer *s, struct Buffer *err, parser_callback_t callback, bool dry_run, bool color)
Parse a "color" command.
Definition: color.c:986

+ Here is the call graph for this function:

static void mutt_free_color_list ( struct ColorLineHead *  head)
static

Free a list of colours.

Parameters
headColorLine List

Definition at line 1178 of file color.c.

1179 {
1180  struct ColorLine *np, *tmp;
1181  STAILQ_FOREACH_SAFE(np, head, entries, tmp)
1182  {
1183  STAILQ_REMOVE(head, np, ColorLine, entries);
1184  free_color_line(np, true);
1185  }
1186 }
#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 free_color_line(struct ColorLine *tmp, bool free_colors)
Free a ColorLine.
Definition: color.c:174
A regular expression and a color to highlight a line.
Definition: mutt_curses.h:178

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_free_colors ( void  )

Free all the colours (on shutdown)

Definition at line 1191 of file color.c.

1192 {
1202 
1203  struct ColorList *cl = ColorList;
1204  struct ColorList *next = NULL;
1205  while (cl)
1206  {
1207  next = cl->next;
1208  FREE(&cl);
1209  cl = next;
1210  }
1211  ColorList = NULL;
1212 }
struct ColorLineHead ColorIndexFlagsList
List of colours applied to the flags in the index.
Definition: color.c:56
struct ColorLineHead ColorBodyList
List of colours applied to the email body.
Definition: color.c:53
struct ColorLineHead ColorIndexAuthorList
List of colours applied to the author in the index.
Definition: color.c:55
struct ColorLineHead ColorHdrList
List of colours applied to the email headers.
Definition: color.c:54
static void mutt_free_color_list(struct ColorLineHead *head)
Free a list of colours.
Definition: color.c:1178
struct ColorLineHead ColorIndexSubjectList
List of colours applied to the subject in the index.
Definition: color.c:58
struct ColorLineHead ColorIndexTagList
List of colours applied to tags in the index.
Definition: color.c:59
#define FREE(x)
Definition: memory.h:46
struct ColorLineHead ColorStatusList
List of colours applied to the status bar.
Definition: color.c:60
struct ColorLineHead ColorIndexList
List of default colours applied to the index.
Definition: color.c:57
struct ColorLineHead ColorAttachList
List of colours applied to the attachment headers.
Definition: color.c:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

int* ColorQuote = NULL

Array of colours for quoted email text.

Definition at line 49 of file color.c.

int ColorQuoteUsed

Number of colours for quoted email text.

Definition at line 50 of file color.c.

int ColorDefs[MT_COLOR_MAX]

Array of all fixed colours, see enum ColorId.

Definition at line 51 of file color.c.

struct ColorLineHead ColorAttachList = STAILQ_HEAD_INITIALIZER(ColorAttachList)

List of colours applied to the attachment headers.

Definition at line 52 of file color.c.

struct ColorLineHead ColorBodyList = STAILQ_HEAD_INITIALIZER(ColorBodyList)

List of colours applied to the email body.

Definition at line 53 of file color.c.

struct ColorLineHead ColorHdrList = STAILQ_HEAD_INITIALIZER(ColorHdrList)

List of colours applied to the email headers.

Definition at line 54 of file color.c.

struct ColorLineHead ColorIndexAuthorList = STAILQ_HEAD_INITIALIZER(ColorIndexAuthorList)

List of colours applied to the author in the index.

Definition at line 55 of file color.c.

struct ColorLineHead ColorIndexFlagsList = STAILQ_HEAD_INITIALIZER(ColorIndexFlagsList)

List of colours applied to the flags in the index.

Definition at line 56 of file color.c.

struct ColorLineHead ColorIndexList = STAILQ_HEAD_INITIALIZER(ColorIndexList)

List of default colours applied to the index.

Definition at line 57 of file color.c.

struct ColorLineHead ColorIndexSubjectList = STAILQ_HEAD_INITIALIZER(ColorIndexSubjectList)

List of colours applied to the subject in the index.

Definition at line 58 of file color.c.

struct ColorLineHead ColorIndexTagList = STAILQ_HEAD_INITIALIZER(ColorIndexTagList)

List of colours applied to tags in the index.

Definition at line 59 of file color.c.

struct ColorLineHead ColorStatusList = STAILQ_HEAD_INITIALIZER(ColorStatusList)

List of colours applied to the status bar.

Definition at line 60 of file color.c.

int ColorQuoteSize
static

Definition at line 63 of file color.c.

const struct Mapping Fields[]
static

Definition at line 101 of file color.c.

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 }
}
Header labels, e.g. From:
Definition: mutt_curses.h:167
Mail will not be encrypted or signed.
Definition: mutt_curses.h:171
Mail will be encrypted.
Definition: mutt_curses.h:168
Mail will be signed.
Definition: mutt_curses.h:169
Mail will be encrypted and signed.
Definition: mutt_curses.h:170

Definition at line 145 of file color.c.