Support RGB colors in scr.html

This commit is contained in:
pancake 2015-01-13 01:22:33 +01:00
parent 456a9c1fdf
commit fb45861275
2 changed files with 21 additions and 3 deletions

View File

@ -302,6 +302,15 @@ R_API int r_cons_grep_line(char *buf, int len) {
return len;
}
static const char *gethtmlrgb(const char *str) {
static char buf[32];
ut8 r, g, b;
r = g = b = 0;
r_cons_rgb_parse (str, &r, &g, &b, 0);
sprintf (buf, "#%02x%02x%02x", r, g, b);
return buf;
}
static const char *gethtmlcolor(const char ptrch, const char *def) {
switch (ptrch) {
case '0': return "#000"; // BLACK
@ -351,7 +360,7 @@ R_API int r_cons_html_print(const char *ptr) {
}
esc = 2;
continue;
} else
} else
if (esc == 2) {
// TODO: use dword comparison here
if (ptr[0]=='2' && ptr[1]=='J') {
@ -361,6 +370,14 @@ R_API int r_cons_html_print(const char *ptr) {
str = ptr;
continue;
} else
if (!strncmp (ptr, "38;5;", 5)) {
char *end = strchr (ptr, 'm');
printf ("<font color='%s'>", gethtmlrgb (ptr));
fflush (stdout);
ptr = end;
str = ptr + 1;
esc = 0;
} else
if (ptr[0]=='0' && ptr[1]==';' && ptr[2]=='0') {
r_cons_gotoxy (0, 0);
ptr += 4;

View File

@ -87,7 +87,8 @@ R_API int r_cons_rgb_parse (const char *p, ut8 *r, ut8 *g, ut8 *b, int *is_bg) {
//const double k = (256/6);
if (!p) return 0;
if (*p==0x1b) p++;
if (*p!='[') return 0;
//if (*p!='[') return 0;
if (*p!='[') p--;
switch (p[1]) {
case '1': bold=255; p+=2; break;
case '3': isbg=0; break;
@ -99,7 +100,7 @@ R_API int r_cons_rgb_parse (const char *p, ut8 *r, ut8 *g, ut8 *b, int *is_bg) {
int x, y, z;
int n = atoi (p+6);
unrgb (n, &x, &y, &z);
SETRGB (x,y,z);
SETRGB (x, y, z);
} else {
/* truecolor */
p += 6;