NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
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 -. More...
 
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 -. More...
 

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

213{
214 if (fg)
215 *fg = COLOR_UNSET;
216 if (bg)
217 *bg = COLOR_UNSET;
218
219 if (!MoreArgs(s))
220 {
221 mutt_buffer_printf(err, _("%s: too few arguments"), "mono");
222 return MUTT_CMD_WARNING;
223 }
224
226
227 if (mutt_istr_equal("bold", buf->data))
228 *attrs |= A_BOLD;
229 else if (mutt_istr_equal("italic", buf->data))
230 *attrs |= A_ITALIC;
231 else if (mutt_istr_equal("none", buf->data))
232 *attrs = A_NORMAL; // Use '=' to clear other bits
233 else if (mutt_istr_equal("normal", buf->data))
234 *attrs = A_NORMAL; // Use '=' to clear other bits
235 else if (mutt_istr_equal("reverse", buf->data))
236 *attrs |= A_REVERSE;
237 else if (mutt_istr_equal("standout", buf->data))
238 *attrs |= A_STANDOUT;
239 else if (mutt_istr_equal("underline", buf->data))
240 *attrs |= A_UNDERLINE;
241 else
242 {
243 mutt_buffer_printf(err, _("%s: no such attribute"), buf->data);
244 return MUTT_CMD_WARNING;
245 }
246
247 return MUTT_CMD_SUCCESS;
248}
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:168
#define MoreArgs(buf)
Definition: buffer.h:40
#define COLOR_UNSET
Definition: color.h:100
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:37
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition: command.h:36
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:273
#define _(a)
Definition: message.h:28
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:819
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:67
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 255 of file command.c.

258{
259 while (true)
260 {
261 if (!MoreArgs(s))
262 {
263 mutt_buffer_printf(err, _("%s: too few arguments"), "color");
264 return MUTT_CMD_WARNING;
265 }
266
268
269 if (mutt_istr_equal("bold", buf->data))
270 {
271 *attrs |= A_BOLD;
272 color_debug(LL_DEBUG5, "bold\n");
273 }
274 else if (mutt_istr_equal("italic", buf->data))
275 {
276 *attrs |= A_ITALIC;
277 color_debug(LL_DEBUG5, "italic\n");
278 }
279 else if (mutt_istr_equal("none", buf->data))
280 {
281 *attrs = A_NORMAL; // Use '=' to clear other bits
282 color_debug(LL_DEBUG5, "none\n");
283 }
284 else if (mutt_istr_equal("normal", buf->data))
285 {
286 *attrs = A_NORMAL; // Use '=' to clear other bits
287 color_debug(LL_DEBUG5, "normal\n");
288 }
289 else if (mutt_istr_equal("reverse", buf->data))
290 {
291 *attrs |= A_REVERSE;
292 color_debug(LL_DEBUG5, "reverse\n");
293 }
294 else if (mutt_istr_equal("standout", buf->data))
295 {
296 *attrs |= A_STANDOUT;
297 color_debug(LL_DEBUG5, "standout\n");
298 }
299 else if (mutt_istr_equal("underline", buf->data))
300 {
301 *attrs |= A_UNDERLINE;
302 color_debug(LL_DEBUG5, "underline\n");
303 }
304 else
305 {
306 enum CommandResult rc = parse_color_name(buf->data, fg, attrs, true, err);
307 if (rc != MUTT_CMD_SUCCESS)
308 return rc;
309 break;
310 }
311 }
312
313 if (!MoreArgs(s))
314 {
315 mutt_buffer_printf(err, _("%s: too few arguments"), "color");
316 return MUTT_CMD_WARNING;
317 }
318
320
321 return parse_color_name(buf->data, bg, attrs, false, err);
322}
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:121
CommandResult
Error codes for command_t parse functions.
Definition: command.h:34
int color_debug(enum LogLevel level, const char *format,...)
Write to the log file.
Definition: debug.c:44
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function: