NeoMutt  2020-06-26-89-g172cd3
Teaching an old dog new tricks
DOXYGEN
color.h File Reference

Color and attribute parsing. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "mutt_commands.h"
+ Include dependency graph for color.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ColorLine
 A regular expression and a color to highlight a line. More...
 
struct  ColorList
 A set of colors. More...
 
struct  Colors
 
struct  EventColor
 An Event that happened to a Colour. More...
 

Enumerations

enum  ColorId {
  MT_COLOR_NONE = 50, MT_COLOR_ATTACHMENT, MT_COLOR_ATTACH_HEADERS, MT_COLOR_BODY,
  MT_COLOR_BOLD, MT_COLOR_COMPOSE_HEADER, MT_COLOR_COMPOSE_SECURITY_BOTH, MT_COLOR_COMPOSE_SECURITY_ENCRYPT,
  MT_COLOR_COMPOSE_SECURITY_NONE, MT_COLOR_COMPOSE_SECURITY_SIGN, MT_COLOR_ERROR, MT_COLOR_HDRDEFAULT,
  MT_COLOR_HEADER, MT_COLOR_INDICATOR, MT_COLOR_MARKERS, MT_COLOR_MESSAGE,
  MT_COLOR_MESSAGE_LOG, MT_COLOR_NORMAL, MT_COLOR_OPTIONS, MT_COLOR_PROGRESS,
  MT_COLOR_PROMPT, MT_COLOR_QUOTED, MT_COLOR_SEARCH, MT_COLOR_SIDEBAR_DIVIDER,
  MT_COLOR_SIDEBAR_FLAGGED, MT_COLOR_SIDEBAR_HIGHLIGHT, MT_COLOR_SIDEBAR_INDICATOR, MT_COLOR_SIDEBAR_NEW,
  MT_COLOR_SIDEBAR_ORDINARY, MT_COLOR_SIDEBAR_SPOOLFILE, MT_COLOR_SIDEBAR_UNREAD, MT_COLOR_SIGNATURE,
  MT_COLOR_STATUS, MT_COLOR_TILDE, MT_COLOR_TREE, MT_COLOR_UNDERLINE,
  MT_COLOR_WARNING, MT_COLOR_INDEX, MT_COLOR_INDEX_AUTHOR, MT_COLOR_INDEX_FLAGS,
  MT_COLOR_INDEX_SUBJECT, MT_COLOR_INDEX_TAG, MT_COLOR_INDEX_COLLAPSED, MT_COLOR_INDEX_DATE,
  MT_COLOR_INDEX_LABEL, MT_COLOR_INDEX_NUMBER, MT_COLOR_INDEX_SIZE, MT_COLOR_INDEX_TAGS,
  MT_COLOR_MAX
}
 List of all colored objects. More...
 

Functions

 STAILQ_HEAD (ColorLineList, ColorLine)
 
int mutt_color_alloc (struct Colors *c, uint32_t fg, uint32_t bg)
 Allocate a colour pair. More...
 
int mutt_color_combine (struct Colors *c, uint32_t fg_attr, uint32_t bg_attr)
 Combine two colours. More...
 
void mutt_color_free (struct Colors *c, uint32_t fg, uint32_t bg)
 Free a colour. More...
 
struct Colorsmutt_colors_new (void)
 Create new colours. More...
 
void mutt_colors_free (struct Colors **ptr)
 Free all the colours. 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...
 
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...
 

Detailed Description

Color and attribute parsing.

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

Enumeration Type Documentation

◆ ColorId

enum ColorId

List of all colored objects.

This enumeration starts at 50 to avoid any of the values being 37 (ASCII %). Inserting colour codes into expando strings, when one of the colour codes was '', was causing formatting problems.

Enumerator
MT_COLOR_NONE 
MT_COLOR_ATTACHMENT 

MIME attachments text (entire line)

MT_COLOR_ATTACH_HEADERS 

MIME attachment test (takes a pattern)

MT_COLOR_BODY 

Pager: highlight body of message (takes a pattern)

MT_COLOR_BOLD 

Bold text.

MT_COLOR_COMPOSE_HEADER 

Header labels, e.g. From:

MT_COLOR_COMPOSE_SECURITY_BOTH 

Mail will be encrypted and signed.

MT_COLOR_COMPOSE_SECURITY_ENCRYPT 

Mail will be encrypted.

MT_COLOR_COMPOSE_SECURITY_NONE 

Mail will not be encrypted or signed.

MT_COLOR_COMPOSE_SECURITY_SIGN 

Mail will be signed.

MT_COLOR_ERROR 

Error message.

MT_COLOR_HDRDEFAULT 

Header default colour.

MT_COLOR_HEADER 

Message headers (takes a pattern)

MT_COLOR_INDICATOR 

Selected item in list.

MT_COLOR_MARKERS 

Pager: markers, line continuation.

MT_COLOR_MESSAGE 

Informational message.

MT_COLOR_MESSAGE_LOG 

Menu showing log messages.

MT_COLOR_NORMAL 

Plain text.

MT_COLOR_OPTIONS 

Options in prompt.

MT_COLOR_PROGRESS 

Progress bar.

MT_COLOR_PROMPT 

Question/user input.

MT_COLOR_QUOTED 

Pager: quoted text.

MT_COLOR_SEARCH 

Pager: search matches.

MT_COLOR_SIDEBAR_DIVIDER 

Line dividing sidebar from the index/pager.

MT_COLOR_SIDEBAR_FLAGGED 

Mailbox with flagged messages.

MT_COLOR_SIDEBAR_HIGHLIGHT 

Select cursor.

MT_COLOR_SIDEBAR_INDICATOR 

Current open mailbox.

MT_COLOR_SIDEBAR_NEW 

Mailbox with new mail.

MT_COLOR_SIDEBAR_ORDINARY 

Mailbox with no new or flagged messages.

MT_COLOR_SIDEBAR_SPOOLFILE 

$spoolfile (Spool mailbox)

MT_COLOR_SIDEBAR_UNREAD 

Mailbox with unread mail.

MT_COLOR_SIGNATURE 

Pager: signature lines.

MT_COLOR_STATUS 

Status bar (takes a pattern)

MT_COLOR_TILDE 

Pager: empty lines after message.

MT_COLOR_TREE 

Index: tree-drawing characters.

MT_COLOR_UNDERLINE 

Underlined text.

MT_COLOR_WARNING 

Warning messages.

MT_COLOR_INDEX 

Index: default colour (takes a pattern)

MT_COLOR_INDEX_AUTHOR 

Index: author field (takes a pattern)

MT_COLOR_INDEX_FLAGS 

Index: flags field (takes a pattern)

MT_COLOR_INDEX_SUBJECT 

Index: subject field (takes a pattern)

MT_COLOR_INDEX_TAG 

Index: tag field (g, takes a pattern)

MT_COLOR_INDEX_COLLAPSED 

Index: number of messages in collapsed thread.

MT_COLOR_INDEX_DATE 

Index: date field.

MT_COLOR_INDEX_LABEL 

Index: label field.

MT_COLOR_INDEX_NUMBER 

Index: index number.

MT_COLOR_INDEX_SIZE 

Index: size field.

MT_COLOR_INDEX_TAGS 

Index: tags field (g, J)

MT_COLOR_MAX 

Definition at line 58 of file color.h.

59 {
60  MT_COLOR_NONE = 50,
83 #ifdef USE_SIDEBAR
92 #endif
99  /* please no non-MT_COLOR_INDEX objects after this point */
105  /* below here - only index coloring stuff that doesn't have a pattern */
112  MT_COLOR_MAX,
113 };
Mail will be encrypted.
Definition: color.h:67
MIME attachment test (takes a pattern)
Definition: color.h:62
Bold text.
Definition: color.h:64
Index: index number.
Definition: color.h:109
Header default colour.
Definition: color.h:71
Underlined text.
Definition: color.h:97
Progress bar.
Definition: color.h:79
Index: tags field (g, J)
Definition: color.h:111
Informational message.
Definition: color.h:75
Pager: highlight body of message (takes a pattern)
Definition: color.h:63
Mailbox with no new or flagged messages.
Definition: color.h:89
Line dividing sidebar from the index/pager.
Definition: color.h:84
Pager: signature lines.
Definition: color.h:93
Select cursor.
Definition: color.h:86
Pager: quoted text.
Definition: color.h:81
Index: number of messages in collapsed thread.
Definition: color.h:106
Mailbox with new mail.
Definition: color.h:88
Current open mailbox.
Definition: color.h:87
Menu showing log messages.
Definition: color.h:76
Index: author field (takes a pattern)
Definition: color.h:101
Pager: empty lines after message.
Definition: color.h:95
Message headers (takes a pattern)
Definition: color.h:72
Index: tag field (g, takes a pattern)
Definition: color.h:104
Index: tree-drawing characters.
Definition: color.h:96
Pager: markers, line continuation.
Definition: color.h:74
Plain text.
Definition: color.h:77
Index: date field.
Definition: color.h:107
Index: size field.
Definition: color.h:110
Status bar (takes a pattern)
Definition: color.h:94
Header labels, e.g. From:
Definition: color.h:65
Selected item in list.
Definition: color.h:73
Mail will be signed.
Definition: color.h:69
Mail will be encrypted and signed.
Definition: color.h:66
Index: label field.
Definition: color.h:108
Index: subject field (takes a pattern)
Definition: color.h:103
Error message.
Definition: color.h:70
MIME attachments text (entire line)
Definition: color.h:61
Mailbox with unread mail.
Definition: color.h:91
Pager: search matches.
Definition: color.h:82
Mail will not be encrypted or signed.
Definition: color.h:68
Options in prompt.
Definition: color.h:78
Index: default colour (takes a pattern)
Definition: color.h:100
Question/user input.
Definition: color.h:80
Mailbox with flagged messages.
Definition: color.h:85
Warning messages.
Definition: color.h:98
Index: flags field (takes a pattern)
Definition: color.h:102
$spoolfile (Spool mailbox)
Definition: color.h:90

Function Documentation

◆ STAILQ_HEAD()

STAILQ_HEAD ( ColorLineList  ,
ColorLine   
)

◆ mutt_color_alloc()

int mutt_color_alloc ( struct Colors c,
uint32_t  fg,
uint32_t  bg 
)

Allocate a colour pair.

Parameters
cColours
fgForeground colour ID
bgBackground colour ID
Return values
numCombined colour pair

Definition at line 471 of file color.c.

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

◆ mutt_color_combine()

int mutt_color_combine ( struct Colors c,
uint32_t  fg_attr,
uint32_t  bg_attr 
)

Combine two colours.

Parameters
cColours
fg_attrColour pair of foreground to use
bg_attrColour pair of background to use
Return values
numColour pair of combined colour

Definition at line 576 of file color.c.

577 {
578  uint32_t fg = COLOR_DEFAULT;
579  uint32_t bg = COLOR_DEFAULT;
580 
581  mutt_lookup_color(c, fg_attr, &fg, NULL);
582  mutt_lookup_color(c, bg_attr, NULL, &bg);
583 
584  if ((fg == COLOR_DEFAULT) && (bg == COLOR_DEFAULT))
585  return A_NORMAL;
586  return mutt_color_alloc(c, fg, bg);
587 }
#define COLOR_DEFAULT
Definition: color.c:70
static int mutt_lookup_color(struct Colors *c, short pair, uint32_t *fg, uint32_t *bg)
Get the colours from a colour pair.
Definition: color.c:550
uint32_t bg
Definition: color.h:123
uint32_t fg
Definition: color.h:122
int mutt_color_alloc(struct Colors *c, uint32_t fg, uint32_t bg)
Allocate a colour pair.
Definition: color.c:471
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_color_free()

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

Free a colour.

Parameters
cColours
fgForeground colour ID
bgBackground colour ID

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

Definition at line 251 of file color.c.

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

◆ mutt_colors_new()

struct Colors* mutt_colors_new ( void  )

Create new colours.

Return values
ptrNew Colors

Definition at line 373 of file color.c.

374 {
375  struct Colors *c = mutt_mem_calloc(1, sizeof(*c));
376  c->notify = notify_new();
377 
378  quotes_init(c);
379  defs_init(c);
380 
382  STAILQ_INIT(&c->body_list);
383  STAILQ_INIT(&c->hdr_list);
386  STAILQ_INIT(&c->index_list);
390 
391 #ifdef HAVE_COLOR
392  start_color();
393 #endif
394 
396  return c;
397 }
struct ColorLineList status_list
List of colours applied to the status bar.
Definition: color.h:141
struct ColorLineList index_tag_list
List of colours applied to tags in the index.
Definition: color.h:140
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:149
struct ColorLineList body_list
List of colours applied to the email body.
Definition: color.h:134
struct ColorLineList index_flags_list
List of colours applied to the flags in the index.
Definition: color.h:137
struct ColorLineList index_subject_list
List of colours applied to the subject in the index.
Definition: color.h:139
Container for Accounts, Notifications.
Definition: neomutt.h:36
#define STAILQ_INIT(head)
Definition: queue.h:369
static void quotes_init(struct Colors *c)
Initialise the quoted-email colours.
Definition: color.c:205
struct ColorLineList hdr_list
List of colours applied to the email headers.
Definition: color.h:135
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
struct ColorLineList index_author_list
List of colours applied to the author in the index.
Definition: color.h:136
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Definition: color.h:129
struct ColorLineList index_list
List of default colours applied to the index.
Definition: color.h:138
struct ColorLineList attach_list
List of colours applied to the attachment headers.
Definition: color.h:133
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
static void defs_init(struct Colors *c)
Initialise the simple colour definitions.
Definition: color.c:168
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_colors_free()

void mutt_colors_free ( struct Colors **  ptr)

Free all the colours.

Parameters
ptrColours

Definition at line 355 of file color.c.

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

◆ mutt_parse_color()

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

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

Definition at line 1345 of file color.c.

1347 {
1348  bool dry_run = false;
1349 
1350  if (OptNoCurses || !has_colors())
1351  dry_run = true;
1352 
1353  return parse_color(Colors, buf, s, err, parse_color_pair, dry_run, true);
1354 }
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:1171
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
Definition: color.h:129
static enum CommandResult parse_color_pair(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err)
Parse a pair of colours - Implements parser_callback_t.
Definition: color.c:1052
+ Here is the call graph for this function:

◆ mutt_parse_mono()

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

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

Definition at line 1360 of file color.c.

1362 {
1363  bool dry_run = false;
1364 
1365 #ifdef HAVE_COLOR
1366  if (OptNoCurses || has_colors())
1367  dry_run = true;
1368 #else
1369  if (OptNoCurses)
1370  dry_run = true;
1371 #endif
1372 
1373  return parse_color(Colors, buf, s, err, parse_attr_spec, dry_run, false);
1374 }
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:1171
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
static enum CommandResult parse_attr_spec(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err)
Parse an attribute description - Implements parser_callback_t.
Definition: color.c:1102
Definition: color.h:129
+ Here is the call graph for this function:

◆ mutt_parse_uncolor()

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

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

Definition at line 920 of file color.c.

922 {
923  return parse_uncolor(buf, s, Colors, err, true);
924 }
static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, struct Colors *c, struct Buffer *err, bool uncolor)
Parse an &#39;uncolor&#39; command.
Definition: color.c:819
Definition: color.h:129
+ Here is the call graph for this function:

◆ mutt_parse_unmono()

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

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

Definition at line 930 of file color.c.

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