56 ansi->
attrs = A_NORMAL;
67 return ((c ==
'm') || (c ==
';'));
84 if ((str[0] !=
'\033') || (str[1] !=
'['))
88 while ((str[i] !=
'\0') && (isdigit(str[i]) || (str[i] ==
';')))
115 if (dry_run || !ansi)
120 while (pos < seq_len)
122 if ((buf[pos] ==
'0') && isdigit(buf[pos + 1]))
133 ansi->
attrs |= A_BOLD;
136 else if ((buf[pos] ==
'2') && isdigit(buf[pos + 1]) &&
ansi_is_end_char(buf[pos + 2]))
138 char digit = buf[pos + 1];
142 ansi->
attrs &= ~A_BOLD;
144 else if (
digit ==
'3')
146 ansi->
attrs &= ~A_ITALIC;
148 else if (
digit ==
'4')
150 ansi->
attrs &= ~A_UNDERLINE;
152 else if (
digit ==
'5')
154 ansi->
attrs &= ~A_BLINK;
156 else if (
digit ==
'7')
158 ansi->
attrs &= ~A_REVERSE;
166 else if (buf[pos] ==
'3')
171 if ((buf[pos + 1] >=
'0') && (buf[pos + 1] <
'8') &&
ansi_is_end_char(buf[pos + 2]))
173 elem->
color = buf[pos + 1] -
'0';
177 else if (buf[pos + 1] ==
'8')
183 unsigned long value = strtoul(buf + pos + 5, &end, 10);
188 pos += end - &buf[pos];
202 unsigned long value = 0;
205 value = strtoul(buf + pos, &end, 10);
206 if ((value > 255) || !end || (end[0] !=
';'))
211 pos += end - &buf[pos] + 1;
213 value = strtoul(buf + pos, &end, 10);
214 if ((value > 255) || !end || (end[0] !=
';'))
219 pos += end - &buf[pos] + 1;
221 value = strtoul(buf + pos, &end, 10);
222 if ((value > 255) || !end || (end[0] !=
'm'))
227 pos += end - &buf[pos] + 1;
229 elem->
color = (r << 16) + (g << 8) + (b << 0);
251 ansi->
attrs |= A_UNDERLINE;
254 else if (buf[pos] ==
'4')
259 if ((buf[pos + 1] >=
'0') && (buf[pos + 1] <
'8') &&
ansi_is_end_char(buf[pos + 2]))
261 elem->
color = buf[pos + 1] -
'0';
265 else if (buf[pos + 1] ==
'8')
271 unsigned long value = strtoul(buf + pos + 5, &end, 10);
276 pos += end - &buf[pos];
290 unsigned long value = 0;
293 value = strtoul(buf + pos, &end, 10);
294 if ((value > 255) || !end || (end[0] !=
';'))
299 pos += end - &buf[pos] + 1;
301 value = strtoul(buf + pos, &end, 10);
302 if ((value > 255) || !end || (end[0] !=
';'))
307 pos += end - &buf[pos] + 1;
309 value = strtoul(buf + pos, &end, 10);
310 if ((value > 255) || !end || (end[0] !=
'm'))
315 pos += end - &buf[pos] + 1;
317 elem->
color = (r << 16) + (g << 8) + (b << 0);
339 ansi->
attrs |= A_BLINK;
344 ansi->
attrs |= A_REVERSE;
347 else if (buf[pos] ==
';')
353 while ((pos < seq_len) && (buf[pos] !=
';'))
@ CT_SIMPLE
Simple colour, e.g. "Red".
@ CT_PALETTE
Palette colour, e.g. "color207".
@ CT_RGB
True colour, e.g. "#11AAFF".
Color and attribute parsing.
Convenience wrapper for the gui headers.
Convenience wrapper for the library headers.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
int ansi_color_parse_single(const char *buf, struct AnsiColor *ansi, bool dry_run)
Parse a single ANSI escape sequence.
void ansi_color_reset(struct AnsiColor *ansi)
Reset an AnsiColor to uncoloured.
static bool ansi_is_end_char(char c)
Is this the end of a sequence?
int ansi_color_seq_length(const char *str)
Is this an ANSI escape sequence?
int attrs
Text attributes, e.g. A_BOLD.
const struct AttrColor * attr_color
Curses colour of text.
struct ColorElement bg
Background colour.
struct ColorElement fg
Foreground colour.
enum ColorType type
Type of Colour.