NeoMutt  2021-10-29-220-g2b1eec
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 1 of file command.c.

205 {
206  if (fg)
207  *fg = COLOR_UNSET;
208  if (bg)
209  *bg = COLOR_UNSET;
210 
211  if (!MoreArgs(s))
212  {
213  mutt_buffer_printf(err, _("%s: too few arguments"), "mono");
214  return MUTT_CMD_WARNING;
215  }
216 
218 
219  if (mutt_istr_equal("bold", buf->data))
220  *attrs |= A_BOLD;
221  else if (mutt_istr_equal("none", buf->data))
222  *attrs = A_NORMAL; // Use '=' to clear other bits
223  else if (mutt_istr_equal("normal", buf->data))
224  *attrs = A_NORMAL; // Use '=' to clear other bits
225  else if (mutt_istr_equal("reverse", buf->data))
226  *attrs |= A_REVERSE;
227  else if (mutt_istr_equal("standout", buf->data))
228  *attrs |= A_STANDOUT;
229  else if (mutt_istr_equal("underline", buf->data))
230  *attrs |= A_UNDERLINE;
231  else
232  {
233  mutt_buffer_printf(err, _("%s: no such attribute"), buf->data);
234  return MUTT_CMD_WARNING;
235  }
236 
237  return MUTT_CMD_SUCCESS;
238 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:40
#define COLOR_UNSET
Definition: color.h:104
@ 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:399
#define _(a)
Definition: message.h:28
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:727
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
char * data
Pointer to data.
Definition: buffer.h:35

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

248 {
249  while (true)
250  {
251  if (!MoreArgs(s))
252  {
253  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
254  return MUTT_CMD_WARNING;
255  }
256 
258 
259  if (mutt_istr_equal("bold", buf->data))
260  {
261  *attrs |= A_BOLD;
262  }
263  else if (mutt_istr_equal("none", buf->data))
264  {
265  *attrs = A_NORMAL; // Use '=' to clear other bits
266  }
267  else if (mutt_istr_equal("normal", buf->data))
268  {
269  *attrs = A_NORMAL; // Use '=' to clear other bits
270  }
271  else if (mutt_istr_equal("reverse", buf->data))
272  {
273  *attrs |= A_REVERSE;
274  }
275  else if (mutt_istr_equal("standout", buf->data))
276  {
277  *attrs |= A_STANDOUT;
278  }
279  else if (mutt_istr_equal("underline", buf->data))
280  {
281  *attrs |= A_UNDERLINE;
282  }
283  else
284  {
285  enum CommandResult rc = parse_color_name(buf->data, fg, attrs, true, err);
286  if (rc != MUTT_CMD_SUCCESS)
287  return rc;
288  break;
289  }
290  }
291 
292  if (!MoreArgs(s))
293  {
294  mutt_buffer_printf(err, _("%s: too few arguments"), "color");
295  return MUTT_CMD_WARNING;
296  }
297 
299 
300  return parse_color_name(buf->data, bg, attrs, false, err);
301 }
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:119
CommandResult
Error codes for command_t parse functions.
Definition: command.h:34