21#include "gdbsupport/gdb_regex.h"
44#define NUM_SUBEXPRESSIONS 3
73 str->append (std::to_string (
m_value + (is_fg ? 30 : 40)));
75 str->append (std::to_string (
m_value -
WHITE + (is_fg ? 90 : 100)));
78 str->append (is_fg ?
"38;5;" :
"48;5;");
79 str->append (std::to_string (
m_value));
86 str->append (is_fg ?
"38;2;" :
"48;2;");
87 str->append (std::to_string (
m_red)
88 +
";" + std::to_string (
m_green)
89 +
";" + std::to_string (
m_blue));
103 if (m_value >= 8 && m_value <= 15)
104 memcpy (rgb,
bright_colors[m_value - 8], 3 *
sizeof (uint8_t));
105 else if (m_value >= 16 && m_value <= 231)
111 int component =
value / 36;
112 rgb[0] = component == 0 ? 0 : (55 + component * 40);
114 component =
value / 6;
115 rgb[1] = component == 0 ? 0 : (55 + component * 40);
119 else if (m_value >= 232)
121 uint8_t v = (m_value - 232) * 10 + 8;
127 gdb_assert_not_reached (
"get_rgb called on invalid color");
142 std::string result (
"\033[");
147 result.push_back (
';');
154 result.push_back (
';');
161 result.push_back (
';');
162 result.push_back (
'7');
164 result.push_back (
'm');
174 if (
string[*idx] !=
';')
177 if (
string[*idx] <
'0' ||
string[*idx] >
'9')
180 *num = strtol (
string + *idx, &tail, 10);
181 *idx = tail - string;
236 int match = regexec (&
ansi_regex, buf, ARRAY_SIZE (subexps), subexps, 0);
237 if (match == REG_NOMATCH)
243 gdb_assert (match == 0);
245 gdb_assert (subexps[0].rm_so == 0);
252 *n_read = subexps[0].rm_eo;
275 else if (buf[i] >=
'0' && buf[i] <=
'9')
278 long value = strtol (buf + i, &tail, 10);
363 *n_read = subexps[0].rm_eo;
372 *n_read = subexps[0].rm_eo;
388 *n_read = subexps[0].rm_eo;
399 int match = regexec (&
ansi_regex, buf, ARRAY_SIZE (subexps), subexps, 0);
400 if (match == REG_NOMATCH || buf[subexps[
FINAL_SUBEXP].rm_so] !=
'm')
414 gdb_assert (
code == 0);
void get_rgb(uint8_t *rgb) const
bool append_ansi(bool is_fg, std::string *str) const
initialize_file_ftype _initialize_ui_style
#define NUM_SUBEXPRESSIONS
bool parse(const char *buf, size_t *n_read)
std::string to_ansi() const
static bool read_semi_number(const char *string, regoff_t *idx, long *num)
static const uint8_t bright_colors[][3]
static bool extended_color(const char *str, regoff_t *idx, ui_file_style::color *color)
static const char ansi_regex_text[]
static regex_t ansi_regex
bool skip_ansi_escape(const char *buf, int *n_read)