mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-08 23:07:17 +00:00
Html color parse (#9492)
This commit is contained in:
parent
89775276a2
commit
29158c3726
@ -888,14 +888,14 @@ R_API char *r_cons_html_filter(const char *ptr, int *newlen) {
|
|||||||
esc = 0;
|
esc = 0;
|
||||||
str = ptr;
|
str = ptr;
|
||||||
continue;
|
continue;
|
||||||
} else if (!strncmp (ptr, "48;5;", 5)) {
|
} else if (!strncmp (ptr, "48;5;", 5) || !strncmp (ptr, "48;2;", 5)) {
|
||||||
char *end = strchr (ptr, 'm');
|
char *end = strchr (ptr, 'm');
|
||||||
r_strbuf_appendf (res, "<font style='background-color:%s'>", gethtmlrgb (ptr));
|
r_strbuf_appendf (res, "<font style='background-color:%s'>", gethtmlrgb (ptr));
|
||||||
tag_font = true;
|
tag_font = true;
|
||||||
ptr = end;
|
ptr = end;
|
||||||
str = ptr + 1;
|
str = ptr + 1;
|
||||||
esc = 0;
|
esc = 0;
|
||||||
} else if (!strncmp (ptr, "38;5;", 5)) {
|
} else if (!strncmp (ptr, "38;5;", 5) || !strncmp (ptr, "38;2;", 5)) {
|
||||||
char *end = strchr (ptr, 'm');
|
char *end = strchr (ptr, 'm');
|
||||||
r_strbuf_appendf (res, "<font color='%s'>", gethtmlrgb (ptr));
|
r_strbuf_appendf (res, "<font color='%s'>", gethtmlrgb (ptr));
|
||||||
tag_font = true;
|
tag_font = true;
|
||||||
|
@ -111,13 +111,12 @@ R_API void r_cons_rgb_init (void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parse an ANSI code string into RGB values -- Used by HTML filter only */
|
||||||
R_API int r_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a) {
|
R_API int r_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a) {
|
||||||
const char *q = 0;
|
const char *q = 0;
|
||||||
ut8 isbg = 0, bold = 127; // 255; // 127; // 255 ?
|
ut8 isbg = 0, bold = 127;
|
||||||
//const double k = (256/6);
|
|
||||||
if (!p) return 0;
|
if (!p) return 0;
|
||||||
if (*p == 0x1b) p++;
|
if (*p == 0x1b) p++;
|
||||||
//if (*p!='[') return 0;
|
|
||||||
if (*p != '[') p--;
|
if (*p != '[') p--;
|
||||||
switch (p[1]) {
|
switch (p[1]) {
|
||||||
case '1': bold = 255; p += 2; break;
|
case '1': bold = 255; p += 2; break;
|
||||||
@ -126,15 +125,15 @@ R_API int r_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a) {
|
|||||||
}
|
}
|
||||||
#define SETRGB(x,y,z) if (r) *r = (x); if (g) *g = (y); if (b) *b = (z)
|
#define SETRGB(x,y,z) if (r) *r = (x); if (g) *g = (y); if (b) *b = (z)
|
||||||
if (bold != 255 && strchr (p, ';')) {
|
if (bold != 255 && strchr (p, ';')) {
|
||||||
if (p[4] == '5') {
|
if (p[4] == '5') { // \x1b[%d;5;%dm is 256 colors
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
int n = atoi (p + 6);
|
int n = atoi (p + 6);
|
||||||
unrgb (n, &x, &y, &z);
|
unrgb (n, &x, &y, &z);
|
||||||
SETRGB (x, y, z);
|
SETRGB (x, y, z);
|
||||||
} else {
|
} else { // 16M colors (truecolor)
|
||||||
/* truecolor */
|
|
||||||
/* complex rgb */
|
/* complex rgb */
|
||||||
if (r) *r = atoi (p + 6);
|
p += 6;
|
||||||
|
if (r) *r = atoi (p);
|
||||||
q = strchr (p, ';');
|
q = strchr (p, ';');
|
||||||
if (!q) return 0;
|
if (!q) return 0;
|
||||||
if (g) *g = atoi (q + 1);
|
if (g) *g = atoi (q + 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user