NeoMutt  2024-04-16-36-g75b6fb
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 281 of file parse_color.c.

283{
284 while (true)
285 {
286 if (!MoreArgsF(s, TOKEN_COMMENT))
287 {
288 buf_printf(err, _("%s: too few arguments"), "color");
289 return MUTT_CMD_WARNING;
290 }
291
293 if (buf_is_empty(buf))
294 continue;
295
296 int attr = mutt_map_get_value(buf->data, AttributeNames);
297 if (attr == -1)
298 {
299 enum CommandResult rc = parse_color_name(buf->data, &ac->fg, err);
300 if (rc != MUTT_CMD_SUCCESS)
301 return rc;
302 break;
303 }
304
305 if (attr == A_NORMAL)
306 ac->attrs = attr; // Clear all attributes
307 else
308 ac->attrs |= attr; // Merge with other attributes
309 }
310
311 if (!MoreArgsF(s, TOKEN_COMMENT))
312 {
313 buf_printf(err, _("%s: too few arguments"), "color");
314 return MUTT_CMD_WARNING;
315 }
316
318
319 return parse_color_name(buf->data, &ac->bg, err);
320}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:290
CommandResult
Error codes for command_t parse functions.
Definition: command.h:36
@ 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:50
#define MoreArgsF(buf, flags)
Definition: extract.h:35
#define TOKEN_COMMENT
Don't reap comments.
Definition: extract.h:52
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:59
enum CommandResult parse_color_name(const char *s, struct ColorElement *elem, struct Buffer *err)
Parse a colour name.
Definition: parse_color.c:248
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
char * data
Pointer to data.
Definition: buffer.h:37
+ 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 325 of file parse_color.c.

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