mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-26 00:55:59 +00:00
Fix parsing of rgb colors and support html
This commit is contained in:
parent
a9a8fa2886
commit
cdc6fb4687
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2013-2015 - pancake, sghctoma */
|
||||
/* radare - LGPL - Copyright 2013-2016 - pancake, sghctoma */
|
||||
|
||||
#include <r_cons.h>
|
||||
|
||||
@ -88,22 +88,29 @@ struct {
|
||||
} colors[] = {
|
||||
{ "black", Color_BLACK, Color_BGBLACK },
|
||||
{ "red", Color_RED, Color_BGRED },
|
||||
{ "bred", Color_BRED, Color_BGRED },
|
||||
{ "white", Color_WHITE, Color_BGWHITE },
|
||||
{ "green", Color_GREEN, Color_BGGREEN },
|
||||
{ "bgreen", Color_BGREEN, Color_BGGREEN },
|
||||
{ "magenta", Color_MAGENTA, Color_BGMAGENTA },
|
||||
{ "bmagenta", Color_BMAGENTA, Color_BGMAGENTA },
|
||||
{ "yellow", Color_YELLOW, Color_BGYELLOW },
|
||||
{ "byellow", Color_BYELLOW, Color_BGYELLOW },
|
||||
{ "cyan", Color_CYAN, Color_BGCYAN },
|
||||
{ "bcyan", Color_BCYAN, Color_BGCYAN },
|
||||
{ "blue", Color_BLUE, Color_BGBLUE },
|
||||
{ "bblue", Color_BBLUE, Color_BGBLUE },
|
||||
{ "gray", Color_GRAY, Color_BGGRAY },
|
||||
{ "bgray", Color_BGRAY, Color_BGGRAY },
|
||||
{ "none", Color_RESET, Color_RESET },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static inline ut8 rgbnum (const char ch1, const char ch2) {
|
||||
ut8 r = 0;
|
||||
ut8 r = 0, r2 = 0;
|
||||
r_hex_to_byte (&r, ch1);
|
||||
r_hex_to_byte (&r, ch2);
|
||||
return r;
|
||||
r_hex_to_byte (&r2, ch2);
|
||||
return r << 4 | r2;
|
||||
}
|
||||
|
||||
R_API void r_cons_pal_random () {
|
||||
@ -149,6 +156,16 @@ R_API char *r_cons_pal_parse (const char *str) {
|
||||
free (s);
|
||||
return r_cons_color_random (0);
|
||||
}
|
||||
if (!strncmp (s, "#", 1)) {
|
||||
if (strlen (s) == 7) {
|
||||
#define C(x) (x >> 4)
|
||||
int R, G, B;
|
||||
sscanf (s, "%02x%02x%02x", &R, &G, &B);
|
||||
r_cons_rgb_str (out, C(R), C(G), C(B), 0);
|
||||
} else {
|
||||
eprintf ("Invalid html color code\n");
|
||||
}
|
||||
} else
|
||||
if (!strncmp (s, "rgb:", 4)) {
|
||||
if (strlen (s) == 7) {
|
||||
r = rgbnum (s[4], '0');
|
||||
@ -167,12 +184,12 @@ R_API char *r_cons_pal_parse (const char *str) {
|
||||
r = rgbnum (p[4], '0');
|
||||
g = rgbnum (p[5], '0');
|
||||
b = rgbnum (p[6], '0');
|
||||
r_cons_rgb_str (out + strlen(out), r, g, b, 1);
|
||||
r_cons_rgb_str (out + strlen (out), r, g, b, 1);
|
||||
} else if (strlen (s) == 10) {
|
||||
r = rgbnum (p[4], p[5]);
|
||||
g = rgbnum (p[6], p[7]);
|
||||
b = rgbnum (p[8], p[9]);
|
||||
r_cons_rgb_str (out + strlen(out), r, g, b, 1);
|
||||
r_cons_rgb_str (out + strlen (out), r, g, b, 1);
|
||||
}
|
||||
}
|
||||
for (i = 0; colors[i].name; i++) {
|
||||
@ -401,6 +418,19 @@ R_API void r_cons_pal_list (int rad) {
|
||||
free (name);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
r = g = b = 0;
|
||||
r_cons_rgb_parse (*color, &r, &g, &b, NULL);
|
||||
rgbstr[0] = 0;
|
||||
// r_cons_rgb_str (rgbstr, r, g, b, 0);
|
||||
{
|
||||
char *name = strdup (keys[i].name);
|
||||
r_str_replace_char (name, '.', '_');
|
||||
r_cons_printf (".%s { color:#%02x%02x%02x }\n",
|
||||
name, r, g, b);
|
||||
free (name);
|
||||
}
|
||||
break;
|
||||
case '*':
|
||||
case 'r':
|
||||
case 1:
|
||||
|
@ -97,7 +97,7 @@ R_API void r_cons_rgb_init (void) {
|
||||
|
||||
R_API int r_cons_rgb_parse (const char *p, ut8 *r, ut8 *g, ut8 *b, int *is_bg) {
|
||||
const char *q = 0;
|
||||
int isbg = 0, bold=127;
|
||||
int isbg = 0, bold = 255; // 127; // 255 ?
|
||||
//const double k = (256/6);
|
||||
if (!p) return 0;
|
||||
if (*p == 0x1b) p++;
|
||||
@ -109,7 +109,8 @@ R_API int r_cons_rgb_parse (const char *p, ut8 *r, ut8 *g, ut8 *b, int *is_bg) {
|
||||
case '4': isbg = 1; break;
|
||||
}
|
||||
#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 (strchr (p, ';')) {
|
||||
if (p[4] == '5') {
|
||||
int x, y, z;
|
||||
int n = atoi (p+6);
|
||||
@ -129,7 +130,7 @@ R_API int r_cons_rgb_parse (const char *p, ut8 *r, ut8 *g, ut8 *b, int *is_bg) {
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
/* plain ansi */
|
||||
/* plain ansi escape codes */
|
||||
if (is_bg) *is_bg = isbg;
|
||||
switch (p[2]) {
|
||||
case '0': SETRGB (0, 0, 0); break;
|
||||
|
@ -682,7 +682,7 @@ static char *core_anal_graph_label(RCore *core, RAnalBlock *bb, int opts) {
|
||||
r_list_foreach (bb->ops, iter, opi) {
|
||||
r_bin_addr2line (core->bin, opi->addr, file, sizeof (file)-1, &line);
|
||||
#else
|
||||
for (at=bb->addr; at<bb->addr+bb->size; at+=2) {
|
||||
for (at = bb->addr; at < bb->addr + bb->size; at += 2) {
|
||||
r_bin_addr2line (core->bin, at, file, sizeof (file)-1, &line);
|
||||
#endif
|
||||
if (line != 0 && line != oline && strcmp (file, "??")) {
|
||||
@ -693,11 +693,11 @@ static char *core_anal_graph_label(RCore *core, RAnalBlock *bb, int opts) {
|
||||
memcpy (cmdstr + idx, filestr, flen);
|
||||
idx += flen;
|
||||
if (is_json) {
|
||||
memcpy (cmdstr + idx, "\\n", 3);
|
||||
strcpy (cmdstr + idx, "\\n");
|
||||
} else if (is_html) {
|
||||
memcpy (cmdstr + idx, "<br />", 7);
|
||||
strcpy (cmdstr + idx, "<br />");
|
||||
} else {
|
||||
memcpy (cmdstr + idx, "\\l", 3);
|
||||
strcpy (cmdstr + idx, "\\l");
|
||||
}
|
||||
free (filestr);
|
||||
}
|
||||
|
@ -154,17 +154,11 @@ static int cmd_eval(void *data, const char *input) {
|
||||
case 'j':
|
||||
r_config_list (core->config, NULL, 'j');
|
||||
break;
|
||||
case '\0':
|
||||
case '\0': // "e"
|
||||
r_config_list (core->config, NULL, 0);
|
||||
break;
|
||||
case 'c':
|
||||
case 'c': // "ec"
|
||||
switch (input[1]) {
|
||||
case 'h': // echo
|
||||
if (( p = strchr (input, ' ') )) {
|
||||
r_cons_strcat (p+1);
|
||||
r_cons_newline ();
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
r_cons_pal_init (NULL);
|
||||
break;
|
||||
@ -224,11 +218,19 @@ static int cmd_eval(void *data, const char *input) {
|
||||
nextpal (core, 'l');
|
||||
}
|
||||
break;
|
||||
case 's': r_cons_pal_show (); break;
|
||||
case '*': r_cons_pal_list (1); break;
|
||||
case 'j': r_cons_pal_list ('j'); break;
|
||||
case 'c': r_cons_pal_list ('c'); break;
|
||||
case '\0': r_cons_pal_list (0); break;
|
||||
case 's': r_cons_pal_show (); break; // "ecs"
|
||||
case '*': r_cons_pal_list (1); break; // "ec*"
|
||||
case 'h': // echo
|
||||
if (( p = strchr (input, ' ') )) {
|
||||
r_cons_strcat (p+1);
|
||||
r_cons_newline ();
|
||||
} else {
|
||||
r_cons_pal_list ('h'); break; // "ecj"
|
||||
}
|
||||
break;
|
||||
case 'j': r_cons_pal_list ('j'); break; // "ecj"
|
||||
case 'c': r_cons_pal_list ('c'); break; // "ecc"
|
||||
case '\0': r_cons_pal_list (0); break; // "ec"
|
||||
case 'r': // "ecr"
|
||||
r_cons_pal_random ();
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user