NeoMutt  2025-09-05-55-g97fc89
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Colour Parsing API

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

Functions

enum CommandResult parse_color_pair (struct Buffer *buf, struct Buffer *s, struct AttrColor *ac, struct Buffer *err)
 Parse a pair of colours - Implements parser_callback_t -.
 
enum CommandResult parse_attr_spec (struct Buffer *buf, struct Buffer *s, struct AttrColor *ac, struct Buffer *err)
 Parse an attribute description - 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]acColour
[out]errBuffer for error messages
Return values
0Success
-1Error

Function Documentation

◆ parse_color_pair()

enum CommandResult parse_color_pair ( struct Buffer * buf,
struct Buffer * s,
struct AttrColor * ac,
struct Buffer * err )

Parse a pair of colours - Implements parser_callback_t -.

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

Definition at line 282 of file parse_color.c.

284{
285 while (true)
286 {
287 if (!MoreArgsF(s, TOKEN_COMMENT))
288 {
289 buf_printf(err, _("%s: too few arguments"), "color");
290 return MUTT_CMD_WARNING;
291 }
292
294 if (buf_is_empty(buf))
295 continue;
296
298 if (attr == -1)
299 {
300 enum CommandResult rc = parse_color_name(buf_string(buf), &ac->fg, err);
301 if (rc != MUTT_CMD_SUCCESS)
302 return rc;
303 break;
304 }
305
306 if (attr == A_NORMAL)
307 ac->attrs = attr; // Clear all attributes
308 else
309 ac->attrs |= attr; // Merge with other attributes
310 }
311
312 if (!MoreArgsF(s, TOKEN_COMMENT))
313 {
314 buf_printf(err, _("%s: too few arguments"), "color");
315 return MUTT_CMD_WARNING;
316 }
317
319
320 return parse_color_name(buf_string(buf), &ac->bg, err);
321}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
CommandResult
Error codes for command_t parse functions.
Definition command.h:35
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition command.h:38
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:37
int parse_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition extract.c:48
#define MoreArgsF(buf, flags)
Definition extract.h:33
#define TOKEN_COMMENT
Don't reap comments.
Definition extract.h:50
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition mapping.c:85
#define _(a)
Definition message.h:28
static struct Mapping AttributeNames[]
Mapping of attribute names to their IDs.
Definition parse_color.c:60
enum CommandResult parse_color_name(const char *s, struct ColorElement *elem, struct Buffer *err)
Parse a colour name.
struct ColorElement bg
Background colour.
Definition attr.h:68
struct ColorElement fg
Foreground colour.
Definition attr.h:67
int attrs
Text attributes, e.g. A_BOLD.
Definition attr.h:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_attr_spec()

enum CommandResult parse_attr_spec ( struct Buffer * buf,
struct Buffer * s,
struct AttrColor * ac,
struct Buffer * err )

Parse an attribute description - Implements parser_callback_t -.

Definition at line 326 of file parse_color.c.

328{
329 if (!buf || !s || !ac)
330 return MUTT_CMD_ERROR;
331
332 if (!MoreArgs(s))
333 {
334 buf_printf(err, _("%s: too few arguments"), "mono");
335 return MUTT_CMD_WARNING;
336 }
337
339
341 if (attr == -1)
342 {
343 buf_printf(err, _("%s: no such attribute"), buf_string(buf));
344 return MUTT_CMD_WARNING;
345 }
346
347 if (attr == A_NORMAL)
348 ac->attrs = attr; // Clear all attributes
349 else
350 ac->attrs |= attr; // Merge with other attributes
351
352 return MUTT_CMD_SUCCESS;
353}
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:36
#define MoreArgs(buf)
Definition extract.h:30
#define TOKEN_NO_FLAGS
No flags are set.
Definition extract.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function: