NeoMutt  2019-12-07-60-g0cfa53
Teaching an old dog new tricks
DOXYGEN
color.h File Reference

Color and attribute parsing. More...

#include "config.h"
#include <regex.h>
#include <stdbool.h>
#include <stdint.h>
#include "mutt/mutt.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 an 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)
 
int mutt_color_combine (struct Colors *c, uint32_t fg_attr, uint32_t bg_attr)
 
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, unsigned long data, struct Buffer *err)
 
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...
 
enum CommandResult mutt_parse_uncolor (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 
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...
 

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 59 of file color.h.

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

Function Documentation

◆ STAILQ_HEAD()

STAILQ_HEAD ( ColorLineList  ,
ColorLine   
)

◆ mutt_color_alloc()

int mutt_color_alloc ( struct Colors c,
uint32_t  fg,
uint32_t  bg 
)
+ 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 
)
+ Here is the caller graph for this function:

◆ mutt_color_free()

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

Free a colour.

Parameters
cColours
fgForeground colour ID
bgBackground colour ID

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

Definition at line 251 of file color.c.

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

◆ mutt_colors_new()

struct Colors* mutt_colors_new ( void  )

Create new colours.

Return values
ptrNew Colors

Definition at line 373 of file color.c.

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

◆ mutt_colors_free()

void mutt_colors_free ( struct Colors **  ptr)

Free all the colours.

Parameters
ptrColours

Definition at line 355 of file color.c.

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

◆ mutt_parse_color()

enum CommandResult mutt_parse_color ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
+ Here is the caller graph for this function:

◆ mutt_parse_mono()

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

Parse the 'mono' command - Implements command_t.

Definition at line 1370 of file color.c.

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

◆ mutt_parse_uncolor()

enum CommandResult mutt_parse_uncolor ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
+ Here is the caller graph for this function:

◆ mutt_parse_unmono()

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

Parse the 'unmono' command - Implements command_t.

Definition at line 932 of file color.c.

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