NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Colour Parsing API

Prototype for a function to parse color config. More...

Functions

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

Detailed Description

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]attrsAttributes, e.g. A_UNDERLINE
[out]errBuffer for error messages
Return values
0Success
-1Error

Function Documentation

◆ parse_attr_spec()

static enum CommandResult parse_attr_spec ( struct Buffer buf,
struct Buffer s,
uint32_t *  fg,
uint32_t *  bg,
int *  attrs,
struct Buffer err 
)
static

Parse an attribute description - Implements parser_callback_t -.

Definition at line 544 of file command.c.

547{
548 if (fg)
549 *fg = COLOR_UNSET;
550 if (bg)
551 *bg = COLOR_UNSET;
552
553 if (!MoreArgs(s))
554 {
555 buf_printf(err, _("%s: too few arguments"), "mono");
556 return MUTT_CMD_WARNING;
557 }
558
560
561 if (mutt_istr_equal("bold", buf->data))
562 {
563 *attrs |= A_BOLD;
564 }
565 else if (mutt_istr_equal("italic", buf->data))
566 {
567 *attrs |= A_ITALIC;
568 }
569 else if (mutt_istr_equal("none", buf->data))
570 {
571 *attrs = A_NORMAL; // Use '=' to clear other bits
572 }
573 else if (mutt_istr_equal("normal", buf->data))
574 {
575 *attrs = A_NORMAL; // Use '=' to clear other bits
576 }
577 else if (mutt_istr_equal("reverse", buf->data))
578 {
579 *attrs |= A_REVERSE;
580 }
581 else if (mutt_istr_equal("standout", buf->data))
582 {
583 *attrs |= A_STANDOUT;
584 }
585 else if (mutt_istr_equal("underline", buf->data))
586 {
587 *attrs |= A_UNDERLINE;
588 }
589 else
590 {
591 buf_printf(err, _("%s: no such attribute"), buf->data);
592 return MUTT_CMD_WARNING;
593 }
594
595 return MUTT_CMD_SUCCESS;
596}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:173
#define COLOR_UNSET
Definition: color.h:105
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:39
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition: command.h:38
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
#define _(a)
Definition: message.h:28
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:810
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_color_pair()

static enum CommandResult parse_color_pair ( struct Buffer buf,
struct Buffer s,
uint32_t *  fg,
uint32_t *  bg,
int *  attrs,
struct Buffer err 
)
static

Parse a pair of colours - Implements parser_callback_t -.

Parse a pair of colours, e.g. "red default"

Definition at line 603 of file command.c.

606{
607 while (true)
608 {
609 if (!MoreArgsF(s, TOKEN_COMMENT))
610 {
611 buf_printf(err, _("%s: too few arguments"), "color");
612 return MUTT_CMD_WARNING;
613 }
614
616
617 if (mutt_istr_equal("bold", buf->data))
618 {
619 *attrs |= A_BOLD;
620 color_debug(LL_DEBUG5, "bold\n");
621 }
622 else if (mutt_istr_equal("italic", buf->data))
623 {
624 *attrs |= A_ITALIC;
625 color_debug(LL_DEBUG5, "italic\n");
626 }
627 else if (mutt_istr_equal("none", buf->data))
628 {
629 *attrs = A_NORMAL; // Use '=' to clear other bits
630 color_debug(LL_DEBUG5, "none\n");
631 }
632 else if (mutt_istr_equal("normal", buf->data))
633 {
634 *attrs = A_NORMAL; // Use '=' to clear other bits
635 color_debug(LL_DEBUG5, "normal\n");
636 }
637 else if (mutt_istr_equal("reverse", buf->data))
638 {
639 *attrs |= A_REVERSE;
640 color_debug(LL_DEBUG5, "reverse\n");
641 }
642 else if (mutt_istr_equal("standout", buf->data))
643 {
644 *attrs |= A_STANDOUT;
645 color_debug(LL_DEBUG5, "standout\n");
646 }
647 else if (mutt_istr_equal("underline", buf->data))
648 {
649 *attrs |= A_UNDERLINE;
650 color_debug(LL_DEBUG5, "underline\n");
651 }
652 else
653 {
654 enum CommandResult rc = parse_color_name(buf->data, fg, attrs, true, err);
655 if (rc != MUTT_CMD_SUCCESS)
656 return rc;
657 break;
658 }
659 }
660
661 if (!MoreArgsF(s, TOKEN_COMMENT))
662 {
663 buf_printf(err, _("%s: too few arguments"), "color");
664 return MUTT_CMD_WARNING;
665 }
666
668
669 return parse_color_name(buf->data, bg, attrs, false, err);
670}
static enum CommandResult parse_color_name(const char *s, uint32_t *col, int *attrs, bool is_fg, struct Buffer *err)
Parse a colour name.
Definition: command.c:515
CommandResult
Error codes for command_t parse functions.
Definition: command.h:36
int color_debug(enum LogLevel level, const char *format,...)
Write to the log file.
Definition: debug.c:51
#define MoreArgsF(buf, flags)
Definition: extract.h:34
#define TOKEN_COMMENT
Don't reap comments.
Definition: extract.h: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: