NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
command.c File Reference

Parse colour commands. More...

#include "config.h"
#include <stddef.h>
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "parse/lib.h"
#include "color.h"
#include "command2.h"
#include "debug.h"
#include "globals.h"
#include "notify2.h"
#include "quoted.h"
#include "regex4.h"
#include "simple2.h"
+ Include dependency graph for command.c:

Go to the source code of this file.

Enumerations

enum  ColorPrefix { COLOR_PREFIX_NONE , COLOR_PREFIX_ALERT , COLOR_PREFIX_BRIGHT , COLOR_PREFIX_LIGHT }
 Constants for colour prefixes of named colours. More...
 

Functions

static uint32_t color_xterm256_to_24bit (const uint32_t color)
 Convert a xterm color to its RGB value.
 
static void modify_color_by_prefix (enum ColorPrefix prefix, bool is_fg, uint32_t *col, int *attrs)
 Modify a colour/attributes based on a prefix, e.g.
 
static int parse_color_prefix (const char *s, enum ColorPrefix *prefix)
 Parse a colour prefix, e.g.
 
static enum CommandResult parse_color_namedcolor (const char *s, uint32_t *col, int *attrs, bool is_fg, struct Buffer *err)
 Parse a named colour, e.g.
 
static enum CommandResult parse_color_colornnn (const char *s, uint32_t *col, int *attrs, bool is_fg, struct Buffer *err)
 Parse a colorNNN, e.g.
 
static enum CommandResult parse_color_rrggbb (const char *s, uint32_t *col, int *attrs, bool is_fg, struct Buffer *err)
 Parse an RGB colour, e.g.
 
static enum CommandResult parse_color_name (const char *s, uint32_t *col, int *attrs, bool is_fg, struct Buffer *err)
 Parse a colour name.
 
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 -.
 
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 -.
 
void get_colorid_name (unsigned int cid, struct Buffer *buf)
 Get the name of a color id.
 
static enum CommandResult parse_object (struct Buffer *buf, struct Buffer *s, enum ColorId *cid, int *ql, struct Buffer *err)
 Identify a colour object.
 
static enum CommandResult parse_uncolor (struct Buffer *buf, struct Buffer *s, struct Buffer *err, bool uncolor)
 Parse an 'uncolor' command.
 
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.
 
enum CommandResult mutt_parse_uncolor (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'uncolor' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_unmono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmono' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_color (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'color' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_mono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'mono' command - Implements Command::parse() -.
 

Variables

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

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.

Enumeration Type Documentation

◆ ColorPrefix

Constants for colour prefixes of named colours.

Enumerator
COLOR_PREFIX_NONE 

no prefix

COLOR_PREFIX_ALERT 

"alert" colour prefix

COLOR_PREFIX_BRIGHT 

"bright" colour prefix

COLOR_PREFIX_LIGHT 

"light" colour prefix

Definition at line 132 of file command.c.

133{
138};
@ COLOR_PREFIX_NONE
no prefix
Definition: command.c:134
@ COLOR_PREFIX_ALERT
"alert" colour prefix
Definition: command.c:135
@ COLOR_PREFIX_LIGHT
"light" colour prefix
Definition: command.c:137
@ COLOR_PREFIX_BRIGHT
"bright" colour prefix
Definition: command.c:136

Function Documentation

◆ color_xterm256_to_24bit()

static uint32_t color_xterm256_to_24bit ( const uint32_t  color)
static

Convert a xterm color to its RGB value.

Parameters
[in]colorxterm color number to be converted
Return values
numThe color's RGB value as number with value 0xRRGGBB

There are 256 xterm colors numbered 0 to 255.

Caller contract: color must be between 0 and 255.

Xterm Color Codes

Basic and Bright Colors

  • 0-7 correspond to the 8 terminal colours
  • 8-15 are the bright variants of 0-7
0 #000000 1 #800000 2 #008000 3 #808000 4 #000080 5 #800080 6 #008080 7 #c0c0c0
8 #808080 9 #ff0000 10 #00ff00 11 #ffff00 12 #0000ff 13 #ff00ff 14 #00ffff 15 #ffffff

Color palette

16 #000000 17 #00005f 18 #000087 19 #0000af 20 #0000d7 21 #0000ff
22 #005f00 23 #005f5f 24 #005f87 25 #005faf 26 #005fd7 27 #005fff
28 #008700 29 #00875f 30 #008787 31 #0087af 32 #0087d7 33 #0087ff
34 #00af00 35 #00af5f 36 #00af87 37 #00afaf 38 #00afd7 39 #00afff
40 #00d700 41 #00d75f 42 #00d787 43 #00d7af 44 #00d7d7 45 #00d7ff
46 #00ff00 47 #00ff5f 48 #00ff87 49 #00ffaf 50 #00ffd7 51 #00ffff
52 #5f0000 53 #5f005f 54 #5f0087 55 #5f00af 56 #5f00d7 57 #5f00ff
58 #5f5f00 59 #5f5f5f 60 #5f5f87 61 #5f5faf 62 #5f5fd7 63 #5f5fff
64 #5f8700 65 #5f875f 66 #5f8787 67 #5f87af 68 #5f87d7 69 #5f87ff
70 #5faf00 71 #5faf5f 72 #5faf87 73 #5fafaf 74 #5fafd7 75 #5fafff
76 #5fd700 77 #5fd75f 78 #5fd787 79 #5fd7af 80 #5fd7d7 81 #5fd7ff
82 #5fff00 83 #5fff5f 84 #5fff87 85 #5fffaf 86 #5fffd7 87 #5fffff
88 #870000 89 #87005f 90 #870087 91 #8700af 92 #8700d7 93 #8700ff
94 #875f00 95 #875f5f 96 #875f87 97 #875faf 98 #875fd7 99 #875fff
100 #878700 101 #87875f 102 #878787 103 #8787af 104 #8787d7 105 #8787ff
106 #87af00 107 #87af5f 108 #87af87 109 #87afaf 110 #87afd7 111 #87afff
112 #87d700 113 #87d75f 114 #87d787 115 #87d7af 116 #87d7d7 117 #87d7ff
118 #87ff00 119 #87ff5f 120 #87ff87 121 #87ffaf 122 #87ffd7 123 #87ffff
124 #af0000 125 #af005f 126 #af0087 127 #af00af 128 #af00d7 129 #af00ff
130 #af5f00 131 #af5f5f 132 #af5f87 133 #af5faf 134 #af5fd7 135 #af5fff
136 #af8700 137 #af875f 138 #af8787 139 #af87af 140 #af87d7 141 #af87ff
142 #afaf00 143 #afaf5f 144 #afaf87 145 #afafaf 146 #afafd7 147 #afafff
148 #afd700 149 #afd75f 150 #afd787 151 #afd7af 152 #afd7d7 153 #afd7ff
154 #afff00 155 #afff5f 156 #afff87 157 #afffaf 158 #afffd7 159 #afffff
160 #d70000 161 #d7005f 162 #d70087 163 #d700af 164 #d700d7 165 #d700ff
166 #d75f00 167 #d75f5f 168 #d75f87 169 #d75faf 170 #d75fd7 171 #d75fff
172 #d78700 173 #d7875f 174 #d78787 175 #d787af 176 #d787d7 177 #d787ff
178 #d7af00 179 #d7af5f 180 #d7af87 181 #d7afaf 182 #d7afd7 183 #d7afff
184 #d7d700 185 #d7d75f 186 #d7d787 187 #d7d7af 188 #d7d7d7 189 #d7d7ff
190 #d7ff00 191 #d7ff5f 192 #d7ff87 193 #d7ffaf 194 #d7ffd7 195 #d7ffff
196 #ff0000 197 #ff005f 198 #ff0087 199 #ff00af 200 #ff00d7 201 #ff00ff
202 #ff5f00 203 #ff5f5f 204 #ff5f87 205 #ff5faf 206 #ff5fd7 207 #ff5fff
208 #ff8700 209 #ff875f 210 #ff8787 211 #ff87af 212 #ff87d7 213 #ff87ff
214 #ffaf00 215 #ffaf5f 216 #ffaf87 217 #ffafaf 218 #ffafd7 219 #ffafff
220 #ffd700 221 #ffd75f 222 #ffd787 223 #ffd7af 224 #ffd7d7 225 #ffd7ff
226 #ffff00 227 #ffff5f 228 #ffff87 229 #ffffaf 230 #ffffd7 231 #ffffff

Grey Scale Ramp

232 #080808 233 #121212 234 #1c1c1c 235 #262626 236 #303030 237 #3a3a3a 238 #444444 239 #4e4e4e
240 #585858 241 #606060 242 #666666 243 #767676 244 #808080 245 #8a8a8a 246 #949494 247 #9e9e9e
248 #a8a8a8 249 #b2b2b2 250 #bcbcbc 251 #c6c6c6 252 #d0d0d0 253 #dadada 254 #e4e4e4 255 #eeeeee

Definition at line 211 of file command.c.

212{
213 static const uint32_t basic[] = {
214 0x000000, 0x800000, 0x008000, 0x808000, 0x000080, 0x800080,
215 0x008080, 0xc0c0c0, 0x808080, 0xff0000, 0x00ff00, 0xffff00,
216 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff,
217 };
218
219 assert(color < 256);
220
221 if (color < 16)
222 {
223 color_debug(LL_DEBUG5, "Converted color 0-15: %d\n", color);
224 /* The first 16 colours are the "usual" terminal colours */
225 return basic[color];
226 }
227
228 if (color < 232)
229 {
230 /* The Color palette is divided in 6x6x6 colours, i.e. each R, G, B channel
231 * has six values:
232 *
233 * value: 1 2 3 4 5 6
234 * color: 0x00 0x5f 0x87 0xaf 0xd7 0xff
235 *
236 * The steps between the values is 0x28 = 40, the EXCEPT for the first one
237 * where it is 0x5f = 95.
238 *
239 * If we express the xterm color number minus 16 to base 6, i.e.
240 *
241 * color - 16 = (vr * 36) + (vg * 6) + (vb * 1)
242 *
243 * with vr, vg, vb integers between 0 and 5, then vr, vg, vb is the channel
244 * value for red, green, and blue, respectively.
245 */
246
247 uint32_t normalised_color = color - 16;
248 uint32_t vr = (normalised_color % 216) / 36; /* 216 = 6*6*6 */
249 uint32_t vg = (normalised_color % 36) / 6;
250 uint32_t vb = (normalised_color % 6) / 1;
251
252 /* First step is wider than the other ones, so add the difference if needed */
253 uint32_t r = vr * 0x28 + ((vr > 0) ? (0x5f - 0x40) : 0);
254 uint32_t g = vg * 0x28 + ((vg > 0) ? (0x5f - 0x40) : 0);
255 uint32_t b = vb * 0x28 + ((vb > 0) ? (0x5f - 0x40) : 0);
256
257 uint32_t rgb = (r << 16) + (g << 8) + (b << 0);
258 color_debug(LL_DEBUG5, "Converted xterm color %d to RGB #%x:\n", color, rgb);
259 return rgb;
260 }
261
262 /* Grey scale starts at 0x08 and adds 0xa = 10 in very step ending in 0xee.
263 * There are a total of 6*4 = 24 grey colors in total. */
264 uint32_t steps = color - 232;
265 uint32_t grey = (steps * 0x0a) + 0x08;
266 uint32_t rgb = (grey << 16) + (grey << 8) + (grey << 0);
267 color_debug(LL_DEBUG5, "Converted xterm color %d to RGB #%x:\n", color, rgb);
268 return rgb;
269}
int color_debug(enum LogLevel level, const char *format,...)
Write to the log file.
Definition: debug.c:51
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ modify_color_by_prefix()

static void modify_color_by_prefix ( enum ColorPrefix  prefix,
bool  is_fg,
uint32_t *  col,
int *  attrs 
)
static

Modify a colour/attributes based on a prefix, e.g.

"bright"

Parameters
[in]prefixprefix to apply
[in]is_fgtrue if a foreground colour should be modified
[in,out]colcolour to modify
[in,out]attrsattributes to modify

Definition at line 279 of file command.c.

281{
282 if (prefix == COLOR_PREFIX_NONE)
283 return; // nothing to do here
284
285 if (prefix == COLOR_PREFIX_ALERT)
286 {
287 *attrs |= A_BOLD;
288 *attrs |= A_BLINK;
289 }
290 else if (is_fg)
291 {
292 if ((COLORS >= 16) && (prefix == COLOR_PREFIX_LIGHT))
293 {
294 if (*col <= 7)
295 {
296 /* Advance the color 0-7 by 8 to get the light version */
297 *col += 8;
298 }
299 }
300 else
301 {
302 *attrs |= A_BOLD;
303 }
304 }
305 else
306 {
307 if (COLORS >= 16)
308 {
309 if (*col <= 7)
310 {
311 /* Advance the color 0-7 by 8 to get the light version */
312 *col += 8;
313 }
314 }
315 }
316}
+ Here is the caller graph for this function:

◆ parse_color_prefix()

static int parse_color_prefix ( const char *  s,
enum ColorPrefix prefix 
)
static

Parse a colour prefix, e.g.

"bright"

Parameters
[in]sString to parse
[out]prefixparsed prefix, see ColorPrefix
Return values
numLength of the matched prefix
0No prefix matched

If prefixes should be parsed, but their value is irrelevant, NULL can be passed as 'prefix'.

Definition at line 328 of file command.c.

329{
330 int clen = 0;
331
332 if ((clen = mutt_istr_startswith(s, "bright")))
333 {
334 color_debug(LL_DEBUG5, "bright\n");
335 if (prefix)
336 *prefix = COLOR_PREFIX_BRIGHT;
337 }
338 else if ((clen = mutt_istr_startswith(s, "alert")))
339 {
340 color_debug(LL_DEBUG5, "alert\n");
341 if (prefix)
342 *prefix = COLOR_PREFIX_ALERT;
343 }
344 else if ((clen = mutt_istr_startswith(s, "light")))
345 {
346 color_debug(LL_DEBUG5, "light\n");
347 if (prefix)
348 *prefix = COLOR_PREFIX_LIGHT;
349 }
350
351 return clen;
352}
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:240
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_color_namedcolor()

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

Parse a named colour, e.g.

"brightred"

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
MUTT_CMD_SUCCESSColour parsed successfully
MUTT_CMD_WARNINGUnknown colour, try other parsers

Definition at line 364 of file command.c.

366{
367 enum ColorPrefix prefix = COLOR_PREFIX_NONE;
368 s += parse_color_prefix(s, &prefix);
369
370 if ((*col = mutt_map_get_value(s, ColorNames)) == -1)
371 return MUTT_CMD_WARNING;
372
373 const char *name = mutt_map_get_name(*col, ColorNames);
374 if (name)
375 color_debug(LL_DEBUG5, "color: %s\n", name);
376
377 modify_color_by_prefix(prefix, is_fg, col, attrs);
378
379#ifdef NEOMUTT_DIRECT_COLORS
380 /* If we are running in direct color mode, we must convert the color
381 * number 0-15 to an RGB value.
382 * The first 16 colours of the xterm palette correspond to the terminal
383 * colours. Note that this replace the colour with a predefined RGB value
384 * and not the RGB value the terminal configured to use.
385 *
386 * Note that some colors are "special" e.g. "default" and do not fall in
387 * the range from 0 to 15. These must not be converted.
388 */
389 const bool c_color_directcolor = cs_subset_bool(NeoMutt->sub, "color_directcolor");
390 if (c_color_directcolor && (*col < 16))
391 {
392 *col = color_xterm256_to_24bit(*col);
393 }
394#endif
395 return MUTT_CMD_SUCCESS;
396}
static int parse_color_prefix(const char *s, enum ColorPrefix *prefix)
Parse a colour prefix, e.g.
Definition: command.c:328
static uint32_t color_xterm256_to_24bit(const uint32_t color)
Convert a xterm color to its RGB value.
Definition: command.c:211
ColorPrefix
Constants for colour prefixes of named colours.
Definition: command.c:133
static void modify_color_by_prefix(enum ColorPrefix prefix, bool is_fg, uint32_t *col, int *attrs)
Modify a colour/attributes based on a prefix, e.g.
Definition: command.c:279
const struct Mapping ColorNames[]
Mapping between a colour name and an ncurses colour.
Definition: color.c:46
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:39
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition: command.h:38
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_color_colornnn()

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

Parse a colorNNN, e.g.

"color123".

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
MUTT_CMD_SUCCESSColour parsed successfully
MUTT_CMD_WARNINGUnknown colour, try other parsers
MUTT_CMD_ERRORError, colour could not be parsed

On MUTT_CMD_ERROR, an error message will be written to err.

Definition at line 411 of file command.c.

413{
414 /* prefixes bright, alert, light are only allowed for named colours and
415 * colorNNN for backwards compatibility. */
416 enum ColorPrefix prefix = COLOR_PREFIX_NONE;
417 s += parse_color_prefix(s, &prefix);
418
419 int clen = 0;
420 /* allow aliases for xterm color resources */
421 if ((clen = mutt_istr_startswith(s, "color")) == 0)
422 return MUTT_CMD_WARNING;
423
424 s += clen;
425 char *eptr = NULL;
426 *col = strtoul(s, &eptr, 10);
427 /* There are only 256 xterm colors. Do not confuse with COLORS which is
428 * the number of colours the terminal supports (usually one of 16, 256,
429 * 16777216 (=24bit)). */
430 if ((*s == '\0') || (*eptr != '\0') || (*col >= 256) || ((*col >= COLORS) && !OptNoCurses))
431 {
432 buf_printf(err, _("%s: color not supported by term"), s);
433 return MUTT_CMD_ERROR;
434 }
435
436 modify_color_by_prefix(prefix, is_fg, col, attrs);
437
438#ifdef NEOMUTT_DIRECT_COLORS
439 const bool c_color_directcolor = cs_subset_bool(NeoMutt->sub, "color_directcolor");
440 if (c_color_directcolor)
441 {
442 /* If we are running in direct color mode, we must convert the xterm
443 * color numbers 0-255 to an RGB value. */
444 *col = color_xterm256_to_24bit(*col);
445 /* FIXME: The color values 0 to 7 (both inclusive) are still occupied by
446 * the default terminal colours. As a workaround we round them up to
447 * #000008 which is the blackest black we can produce. */
448 if (*col < 8)
449 *col = 8;
450 }
451#endif
452 color_debug(LL_DEBUG5, "colorNNN %d\n", *col);
453 return MUTT_CMD_SUCCESS;
454}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:173
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition: command.h:37
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:79
#define _(a)
Definition: message.h:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_color_rrggbb()

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

Parse an RGB colour, e.g.

"#12FE45"

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
MUTT_CMD_SUCCESSColour parsed successfully
MUTT_CMD_WARNINGUnknown colour, try other parsers
MUTT_CMD_ERRORError, colour could not be parsed

On MUTT_CMD_ERROR, an error message will be written to err.

Definition at line 469 of file command.c.

471{
472 /* parse #RRGGBB colours */
473 if (s[0] != '#')
474 return MUTT_CMD_WARNING;
475
476#ifndef NEOMUTT_DIRECT_COLORS
477 buf_printf(err, _("Direct colors support not compiled in: %s"), s);
478 return MUTT_CMD_ERROR;
479#endif
480 const bool c_color_directcolor = cs_subset_bool(NeoMutt->sub, "color_directcolor");
481 if (!c_color_directcolor)
482 {
483 buf_printf(err, _("Direct colors support disabled: %s"), s);
484 return MUTT_CMD_ERROR;
485 }
486 s++;
487 char *eptr = NULL;
488 *col = strtoul(s, &eptr, 16);
489 if ((*s == '\0') || (*eptr != '\0') || ((*col >= COLORS) && !OptNoCurses))
490 {
491 buf_printf(err, _("%s: color not supported by term"), s);
492 return MUTT_CMD_ERROR;
493 }
494 /* FIXME: The color values 0 to 7 (both inclusive) are still occupied by
495 * the default terminal colours. As a workaround we round them up to
496 * #000008 which is the blackest black we can produce. */
497 if (*col < 8)
498 *col = 8;
499
500 color_debug(LL_DEBUG5, "#RRGGBB: %d\n", *col);
501 return MUTT_CMD_SUCCESS;
502}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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", "#12FE45"

Definition at line 515 of file command.c.

517{
518 mutt_debug(LL_DEBUG5, "Parsing color name: %s\n", s);
519
520 /* Try the different colour syntaxes. A return value of MUTT_CMD_WARNING
521 * means, we should try the next syntax. */
522 enum CommandResult cr;
523
524 /* #RRGGBB */
525 cr = parse_color_rrggbb(s, col, attrs, is_fg, err);
526 if (cr != MUTT_CMD_WARNING)
527 return cr;
528 /* color123 */
529 cr = parse_color_colornnn(s, col, attrs, is_fg, err);
530 if (cr != MUTT_CMD_WARNING)
531 return cr;
532 /* named color, e.g. "brightred" */
533 cr = parse_color_namedcolor(s, col, attrs, is_fg, err);
534 if (cr != MUTT_CMD_WARNING)
535 return cr;
536
537 buf_printf(err, _("%s: no such color"), s);
538 return MUTT_CMD_WARNING;
539}
static enum CommandResult parse_color_colornnn(const char *s, uint32_t *col, int *attrs, bool is_fg, struct Buffer *err)
Parse a colorNNN, e.g.
Definition: command.c:411
static enum CommandResult parse_color_rrggbb(const char *s, uint32_t *col, int *attrs, bool is_fg, struct Buffer *err)
Parse an RGB colour, e.g.
Definition: command.c:469
static enum CommandResult parse_color_namedcolor(const char *s, uint32_t *col, int *attrs, bool is_fg, struct Buffer *err)
Parse a named colour, e.g.
Definition: command.c:364
CommandResult
Error codes for command_t parse functions.
Definition: command.h:36
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 677 of file command.c.

678{
679 const char *name = NULL;
680
682 {
684 if (name)
685 {
686 buf_printf(buf, "compose %s", name);
687 return;
688 }
689 }
690
691 name = mutt_map_get_name(cid, ColorFields);
692 if (name)
693 buf_addstr(buf, name);
694 else
695 buf_printf(buf, "UNKNOWN %d", cid);
696}
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:238
const struct Mapping ComposeColorFields[]
Mapping of compose colour names to their IDs.
Definition: command.c:118
const struct Mapping ColorFields[]
Mapping of colour names to their IDs.
Definition: command.c:61
@ MT_COLOR_COMPOSE_SECURITY_SIGN
Mail will be signed.
Definition: color.h:48
@ MT_COLOR_COMPOSE_HEADER
Header labels, e.g. From:
Definition: color.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_object()

static enum CommandResult parse_object ( struct Buffer buf,
struct Buffer s,
enum ColorId 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 709 of file command.c.

711{
712 int rc;
713
714 if (mutt_str_startswith(buf->data, "quoted") != 0)
715 {
716 int val = 0;
717 if (buf->data[6] != '\0')
718 {
719 if (!mutt_str_atoi_full(buf->data + 6, &val) || (val > COLOR_QUOTES_MAX))
720 {
721 buf_printf(err, _("%s: no such object"), buf->data);
722 return MUTT_CMD_WARNING;
723 }
724 }
725
726 *ql = val;
727 *cid = MT_COLOR_QUOTED;
728 return MUTT_CMD_SUCCESS;
729 }
730
731 if (mutt_istr_equal(buf->data, "compose"))
732 {
733 if (!MoreArgs(s))
734 {
735 buf_printf(err, _("%s: too few arguments"), "color");
736 return MUTT_CMD_WARNING;
737 }
738
740
742 if (rc == -1)
743 {
744 buf_printf(err, _("%s: no such object"), buf->data);
745 return MUTT_CMD_WARNING;
746 }
747
748 *cid = rc;
749 return MUTT_CMD_SUCCESS;
750 }
751
753 if (rc == -1)
754 {
755 buf_printf(err, _("%s: no such object"), buf->data);
756 return MUTT_CMD_WARNING;
757 }
758 else
759 {
760 color_debug(LL_DEBUG5, "object: %s\n", mutt_map_get_name(rc, ColorFields));
761 }
762
763 *cid = rc;
764 return MUTT_CMD_SUCCESS;
765}
@ MT_COLOR_QUOTED
Pager: quoted text.
Definition: color.h:61
int parse_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: extract.c:48
#define MoreArgs(buf)
Definition: extract.h:31
#define TOKEN_NO_FLAGS
No flags are set.
Definition: extract.h:45
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:810
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:228
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: quoted.h:37
char * data
Pointer to data.
Definition: buffer.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_uncolor()

static enum CommandResult parse_uncolor ( struct Buffer buf,
struct Buffer s,
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 779 of file command.c.

781{
783
784 if (mutt_str_equal(buf->data, "*"))
785 {
787 return MUTT_CMD_SUCCESS;
788 }
789
790 unsigned int cid = MT_COLOR_NONE;
791 int ql = 0;
792 color_debug(LL_DEBUG5, "uncolor: %s\n", buf_string(buf));
793 enum CommandResult rc = parse_object(buf, s, &cid, &ql, err);
794 if (rc != MUTT_CMD_SUCCESS)
795 return rc;
796
797 if (cid == -1)
798 {
799 buf_printf(err, _("%s: no such object"), buf->data);
800 return MUTT_CMD_ERROR;
801 }
802
803 if (cid == MT_COLOR_QUOTED)
804 {
805 color_debug(LL_DEBUG5, "quoted\n");
806 return quoted_colors_parse_uncolor(cid, ql, err);
807 }
808
809 if ((cid == MT_COLOR_STATUS) && !MoreArgs(s))
810 {
811 color_debug(LL_DEBUG5, "simple\n");
812 simple_color_reset(cid); // default colour for the status bar
813 return MUTT_CMD_SUCCESS;
814 }
815
816 if (!mutt_color_has_pattern(cid))
817 {
818 color_debug(LL_DEBUG5, "simple\n");
820 return MUTT_CMD_SUCCESS;
821 }
822
823 if (OptNoCurses)
824 {
825 do
826 {
827 color_debug(LL_DEBUG5, "do nothing\n");
828 /* just eat the command, but don't do anything real about it */
830 } while (MoreArgs(s));
831
832 return MUTT_CMD_SUCCESS;
833 }
834
835 bool changes = false;
836 if (!MoreArgs(s))
837 {
838 if (regex_colors_parse_uncolor(cid, NULL, uncolor))
839 return MUTT_CMD_SUCCESS;
840 else
841 return MUTT_CMD_ERROR;
842 }
843
844 do
845 {
847 if (mutt_str_equal("*", buf->data))
848 {
849 if (regex_colors_parse_uncolor(cid, NULL, uncolor))
850 return MUTT_CMD_SUCCESS;
851 else
852 return MUTT_CMD_ERROR;
853 }
854
855 changes |= regex_colors_parse_uncolor(cid, buf->data, uncolor);
856
857 } while (MoreArgs(s));
858
859 if (changes)
861
862 return MUTT_CMD_SUCCESS;
863}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
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:709
bool regex_colors_parse_uncolor(enum ColorId cid, const char *pat, bool uncolor)
Parse a Regex 'uncolor' command.
Definition: regex.c:439
void simple_color_reset(enum ColorId cid)
Clear the colour of a simple object.
Definition: simple.c:151
void colors_cleanup(void)
Reset all the simple, quoted and regex colours.
Definition: color.c:64
bool mutt_color_has_pattern(enum ColorId cid)
Check if a color object supports a regex pattern.
Definition: color.c:110
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:75
@ MT_COLOR_NONE
Definition: color.h:39
void regex_colors_dump_all(void)
Dump all the Regex colours to the log.
Definition: debug.c:387
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
enum CommandResult quoted_colors_parse_uncolor(enum ColorId cid, int q_level, struct Buffer *err)
Parse the 'uncolor quoted' command.
Definition: quoted.c:170
+ 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 1064 of file command.c.

1067{
1068 int attrs = 0, q_level = 0;
1069 uint32_t fg = 0, bg = 0, match = 0;
1070 enum ColorId cid = MT_COLOR_NONE;
1071 enum CommandResult rc;
1072
1073 if (!MoreArgs(s))
1074 {
1075#ifdef USE_DEBUG_COLOR
1076 if (StartupComplete)
1077 return color_dump(buf, s, 0, err);
1078#endif
1079
1080 buf_printf(err, _("%s: too few arguments"), "color");
1081 return MUTT_CMD_WARNING;
1082 }
1083
1085 color_debug(LL_DEBUG5, "color: %s\n", buf_string(buf));
1086
1087 rc = parse_object(buf, s, &cid, &q_level, err);
1088 if (rc != MUTT_CMD_SUCCESS)
1089 return rc;
1090
1091 rc = callback(buf, s, &fg, &bg, &attrs, err);
1092 if (rc != MUTT_CMD_SUCCESS)
1093 return rc;
1094
1095 /* extract a regular expression if needed */
1096
1097 if (mutt_color_has_pattern(cid) && cid != MT_COLOR_STATUS)
1098 {
1099 color_debug(LL_DEBUG5, "regex needed\n");
1100 if (MoreArgs(s))
1101 {
1103 }
1104 else
1105 {
1106 buf_strcpy(buf, ".*");
1107 }
1108 }
1109
1110 if (MoreArgs(s) && (cid != MT_COLOR_STATUS))
1111 {
1112 buf_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
1113 return MUTT_CMD_WARNING;
1114 }
1115
1116 if (dry_run)
1117 {
1118 color_debug(LL_DEBUG5, "dry_run bailout\n");
1119 *s->dptr = '\0'; /* fake that we're done parsing */
1120 return MUTT_CMD_SUCCESS;
1121 }
1122
1123 /* The case of the tree object is special, because a non-default fg color of
1124 * the tree element may be combined dynamically with the default bg color of
1125 * an index line, not necessarily defined in a rc file. */
1126 if (!OptNoCurses &&
1127 ((fg == COLOR_DEFAULT) || (bg == COLOR_DEFAULT) || (cid == MT_COLOR_TREE)) &&
1128 (use_default_colors() != OK))
1129 {
1130 buf_strcpy(err, _("default colors not supported"));
1131 return MUTT_CMD_ERROR;
1132 }
1133
1134 if (regex_colors_parse_color_list(cid, buf->data, fg, bg, attrs, &rc, err))
1135 {
1136 color_debug(LL_DEBUG5, "regex_colors_parse_color_list done\n");
1137 return rc;
1138 // do nothing
1139 }
1140 else if (quoted_colors_parse_color(cid, fg, bg, attrs, q_level, &rc, err))
1141 {
1142 color_debug(LL_DEBUG5, "quoted_colors_parse_color done\n");
1143 return rc;
1144 // do nothing
1145 }
1146 else if ((cid == MT_COLOR_STATUS) && MoreArgs(s))
1147 {
1148 color_debug(LL_DEBUG5, "status\n");
1149 /* 'color status fg bg' can have up to 2 arguments:
1150 * 0 arguments: sets the default status color (handled below by else part)
1151 * 1 argument : colorize pattern on match
1152 * 2 arguments: colorize nth submatch of pattern */
1154
1155 if (MoreArgs(s))
1156 {
1157 struct Buffer tmp = buf_make(0);
1159 if (!mutt_str_atoui_full(tmp.data, &match))
1160 {
1161 buf_printf(err, _("%s: invalid number: %s"), color ? "color" : "mono", tmp.data);
1162 buf_dealloc(&tmp);
1163 return MUTT_CMD_WARNING;
1164 }
1165 buf_dealloc(&tmp);
1166 }
1167
1168 if (MoreArgs(s))
1169 {
1170 buf_printf(err, _("%s: too many arguments"), color ? "color" : "mono");
1171 return MUTT_CMD_WARNING;
1172 }
1173
1174 rc = regex_colors_parse_status_list(cid, buf->data, fg, bg, attrs, match, err);
1175 return rc;
1176 }
1177 else // Remaining simple colours
1178 {
1179 color_debug(LL_DEBUG5, "simple\n");
1180 if (simple_color_set(cid, fg, bg, attrs))
1181 rc = MUTT_CMD_SUCCESS;
1182 else
1183 rc = MUTT_CMD_ERROR;
1184 }
1185
1186 if (rc == MUTT_CMD_SUCCESS)
1187 {
1188 get_colorid_name(cid, buf);
1189 color_debug(LL_DEBUG5, "NT_COLOR_SET: %s\n", buf->data);
1190 struct EventColor ev_c = { cid, NULL };
1192 }
1193
1194 return rc;
1195}
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:389
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:70
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:407
void get_colorid_name(unsigned int cid, struct Buffer *buf)
Get the name of a color id.
Definition: command.c:677
struct Notify * ColorsNotify
Notifications: ColorId, EventColor.
Definition: notify.c:35
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:340
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:410
struct AttrColor * simple_color_set(enum ColorId cid, int fg, int bg, int attrs)
Set the colour of a simple object.
Definition: simple.c:125
#define COLOR_DEFAULT
Definition: color.h:104
ColorId
List of all colored objects.
Definition: color.h:38
@ MT_COLOR_TREE
Index: tree-drawing characters.
Definition: color.h:79
bool StartupComplete
When the config has been read.
Definition: main.c:194
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
@ NT_COLOR_SET
Color has been set.
Definition: notify2.h:41
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.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:106
String manipulation buffer.
Definition: buffer.h:34
char * dptr
Current read/write position.
Definition: buffer.h:36
An Event that happened to a Colour.
Definition: notify2.h:53
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ ColorFields

const struct Mapping ColorFields[]

Mapping of colour names to their IDs.

Definition at line 61 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:46
@ MT_COLOR_COMPOSE_SECURITY_NONE
Mail will not be encrypted or signed.
Definition: color.h:47
@ MT_COLOR_COMPOSE_SECURITY_BOTH
Mail will be encrypted and signed.
Definition: color.h:45

Mapping of compose colour names to their IDs.

Definition at line 118 of file command.c.