NeoMutt  2025-12-11-58-g09398d
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 (const struct Command *cmd, struct Buffer *line, struct AttrColor *ac, struct Buffer *err)
 Parse a pair of colours - Implements parser_callback_t -.
 
enum CommandResult parse_attr_spec (const struct Command *cmd, struct Buffer *line, 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]cmdCommand being parsed
[in]lineBuffer containing string to be parsed
[out]acColour
[out]errBuffer for error messages
Return values
0Success
-1Error
Precondition
cmd is not NULL
line is not NULL
ac is not NULL
err is not NULL

Function Documentation

◆ parse_color_pair()

enum CommandResult parse_color_pair ( const struct Command * cmd,
struct Buffer * line,
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 struct Buffer *token = buf_pool_get();
287
288 while (true)
289 {
290 if (!MoreArgsF(line, TOKEN_COMMENT))
291 {
292 buf_printf(err, _("%s: too few arguments"), cmd->name);
293 goto done;
294 }
295
297 if (buf_is_empty(token))
298 continue;
299
300 int attr = mutt_map_get_value(buf_string(token), AttributeNames);
301 if (attr == -1)
302 {
303 rc = parse_color_name(buf_string(token), &ac->fg, err);
304 if (rc != MUTT_CMD_SUCCESS)
305 goto done;
306 break;
307 }
308
309 if (attr == A_NORMAL)
310 ac->attrs = attr; // Clear all attributes
311 else
312 ac->attrs |= attr; // Merge with other attributes
313 }
314
315 if (!MoreArgsF(line, TOKEN_COMMENT))
316 {
317 buf_printf(err, _("%s: too few arguments"), "color");
318 rc = MUTT_CMD_WARNING;
319 goto done;
320 }
321
323
324 rc = parse_color_name(buf_string(token), &ac->bg, err);
325
326done:
327 buf_pool_release(&token);
328 return rc;
329}
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 *line, 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 Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:96
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
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the command.
Definition command.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_attr_spec()

enum CommandResult parse_attr_spec ( const struct Command * cmd,
struct Buffer * line,
struct AttrColor * ac,
struct Buffer * err )

Parse an attribute description - Implements parser_callback_t -.

Definition at line 334 of file parse_color.c.

336{
337 struct Buffer *token = buf_pool_get();
339
340 if (!MoreArgs(line))
341 {
342 buf_printf(err, _("%s: too few arguments"), cmd->name);
343 goto done;
344 }
345
347
348 int attr = mutt_map_get_value(buf_string(token), AttributeNames);
349 if (attr == -1)
350 {
351 buf_printf(err, _("%s: no such attribute"), buf_string(token));
352 goto done;
353 }
354
355 if (attr == A_NORMAL)
356 ac->attrs = attr; // Clear all attributes
357 else
358 ac->attrs |= attr; // Merge with other attributes
359
360 rc = MUTT_CMD_SUCCESS;
361
362done:
363 buf_pool_release(&token);
364 return rc;
365}
#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: