mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-27 08:12:44 +00:00
Change the look of the p= (Add scr.hist.block) ##print
This commit is contained in:
parent
7a13776783
commit
e33a88e5be
@ -2125,6 +2125,13 @@ static bool cb_scrnkey(void *user, void *data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cb_scr_histblock(void *user, void *data) {
|
||||
RCore *core = (RCore *) user;
|
||||
RConfigNode *node = (RConfigNode *) data;
|
||||
core->print->histblock = node->i_value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cb_scrprompt(void *user, void *data) {
|
||||
RCore *core = (RCore *)user;
|
||||
RConfigNode *node = (RConfigNode *) data;
|
||||
@ -3459,6 +3466,7 @@ R_API int r_core_config_init(RCore *core) {
|
||||
SETPREF ("scr.prompt.flag", "false", "Show flag name in the prompt");
|
||||
SETPREF ("scr.prompt.sect", "false", "Show section name in the prompt");
|
||||
SETPREF ("scr.tts", "false", "Use tts if available by a command (see ic)");
|
||||
SETCB ("scr.hist.block", "true", &cb_scr_histblock, "Use blocks for histogram");
|
||||
SETCB ("scr.prompt", "true", &cb_scrprompt, "Show user prompt (used by r2 -q)");
|
||||
SETCB ("scr.tee", "", &cb_teefile, "Pipe output to file of this name");
|
||||
SETPREF ("scr.seek", "", "Seek to the specified address on startup");
|
||||
|
@ -398,7 +398,7 @@ typedef struct r_cons_canvas_t {
|
||||
#define RUNE_CURVE_CORNER_TR "╮"
|
||||
#define RUNE_CURVE_CORNER_BR "╯"
|
||||
#define RUNE_CURVE_CORNER_BL "╰"
|
||||
|
||||
#define RUNE_LONG_LINE_HORIZ "―"
|
||||
#define UTF_CIRCLE "\u25EF"
|
||||
|
||||
typedef char *(*RConsEditorCallback)(void *core, const char *file, const char *str);
|
||||
|
@ -70,6 +70,7 @@ typedef struct r_print_t {
|
||||
int width;
|
||||
int limit;
|
||||
int bits;
|
||||
bool histblock;
|
||||
// true if the cursor is enabled, false otherwise
|
||||
bool cur_enabled;
|
||||
// offset of the selected byte from the first displayed one
|
||||
|
@ -75,12 +75,19 @@ R_API void r_print_columns (RPrint *p, const ut8 *buf, int len, int height) {
|
||||
// int realrows = rows * 2;
|
||||
bool colors = p->flags & R_PRINT_FLAGS_COLOR;
|
||||
RConsPrintablePalette *pal = &p->cons->context->pal;
|
||||
const char *vline = p->cons->use_utf8 ? RUNE_LINE_VERT : "|";
|
||||
const char *kol[5];
|
||||
kol[0] = pal->call;
|
||||
kol[1] = pal->jmp;
|
||||
kol[2] = pal->cjmp;
|
||||
kol[3] = pal->mov;
|
||||
kol[4] = pal->nop;
|
||||
const char *bgkol[5];
|
||||
bgkol[0] = Color_BGGREEN;
|
||||
bgkol[1] = Color_BGGREEN;
|
||||
bgkol[2] = Color_BGGREEN;
|
||||
bgkol[3] = Color_BGWHITE;
|
||||
bgkol[4] = Color_BGBLUE;
|
||||
if (colors) {
|
||||
for (i = 0; i < rows; i++) {
|
||||
int threshold = i * (0xff / rows);
|
||||
@ -88,10 +95,10 @@ R_API void r_print_columns (RPrint *p, const ut8 *buf, int len, int height) {
|
||||
int realJ = j * len / cols;
|
||||
if (255 - buf[realJ] < threshold || (i + 1 == rows)) {
|
||||
int koli = i * 5 / rows;
|
||||
if (p->cons->use_utf8) {
|
||||
p->cb_printf ("%s%s%s", kol[koli], RUNE_LINE_VERT, Color_RESET);
|
||||
if (p->histblock) {
|
||||
p->cb_printf ("%s%s%s", bgkol[koli], " ", Color_RESET);
|
||||
} else {
|
||||
p->cb_printf ("%s|" Color_RESET, kol[koli]);
|
||||
p->cb_printf ("%s%s%s", kol[koli], vline, Color_RESET);
|
||||
}
|
||||
} else {
|
||||
p->cb_printf (" ");
|
||||
@ -107,11 +114,7 @@ R_API void r_print_columns (RPrint *p, const ut8 *buf, int len, int height) {
|
||||
for (j = 0; j < cols; j++) {
|
||||
int realJ = j * len / cols;
|
||||
if (255 - buf[realJ] < threshold) {
|
||||
if (p->cons->use_utf8) {
|
||||
p->cb_printf (RUNE_LINE_VERT);
|
||||
} else {
|
||||
p->cb_printf ("|");
|
||||
}
|
||||
p->cb_printf (vline);
|
||||
} else if (i + 1 == rows) {
|
||||
p->cb_printf ("_");
|
||||
} else {
|
||||
@ -1663,22 +1666,43 @@ R_API void r_print_zoom(RPrint *p, void *user, RPrintZoomCallback cb, ut64 from,
|
||||
p->flags |= R_PRINT_FLAGS_HEADER;
|
||||
}
|
||||
|
||||
static inline void getLineColor (RPrint *p, int k, int cols) {
|
||||
RConsPrintablePalette *pal = &p->cons->context->pal;
|
||||
const char *h_line = p->cons->use_utf8 ? RUNE_LONG_LINE_HORIZ : "-";
|
||||
const char *kol[5];
|
||||
kol[0] = pal->nop;
|
||||
kol[1] = pal->mov;
|
||||
kol[2] = pal->cjmp;
|
||||
kol[3] = pal->jmp;
|
||||
kol[4] = pal->call;
|
||||
const char *bgkol[5];
|
||||
bgkol[0] = Color_BGBLUE;
|
||||
bgkol[1] = Color_BGWHITE;
|
||||
bgkol[2] = Color_BGGREEN;
|
||||
bgkol[3] = Color_BGGREEN;
|
||||
bgkol[4] = Color_BGGREEN;
|
||||
|
||||
const bool show_colors = (p && (p->flags & R_PRINT_FLAGS_COLOR));
|
||||
if (show_colors) {
|
||||
int idx = (int) ((k * 4) / cols);
|
||||
if (p->histblock) {
|
||||
const char *str = bgkol[idx];
|
||||
p->cb_printf ("%s%s", str, " ");
|
||||
} else {
|
||||
const char *str = kol[idx];
|
||||
p->cb_printf ("%s%s", str, h_line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step) {
|
||||
r_return_if_fail (p && arr);
|
||||
const bool show_colors = (p && (p->flags & R_PRINT_FLAGS_COLOR));
|
||||
const bool bgFill = (p && (p->flags & R_PRINT_FLAGS_BGFILL));
|
||||
bool useUtf8 = p->cons->use_utf8;
|
||||
// bool useUtf8Curvy = p->cons->use_utf8_curvy;
|
||||
const char *tr_corner = "."; // useUtf8 ? (useUtf8Curvy ? RUNECODESTR_CURVE_CORNER_TR : RUNE_CORNER_TR) : ".";
|
||||
const char *br_corner = "'"; // useUtf8 ? (useUtf8Curvy ? RUNECODESTR_CURVE_CORNER_BR : RUNE_CORNER_BR) : "'";
|
||||
const char *v_line = useUtf8 ? RUNE_LINE_VERT : "|";
|
||||
const char *h_line = "_"; // useUtf8 ? RUNE_LINE_HORIZ : "_";
|
||||
char *firebow[6];
|
||||
int i = 0, j;
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
firebow[i] = p->cb_color (i, 6, bgFill);
|
||||
}
|
||||
|
||||
#define INC 5
|
||||
#if TOPLINE
|
||||
if (arr[0] > 1) {
|
||||
@ -1694,9 +1718,15 @@ R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step
|
||||
p->cb_printf ("\n");
|
||||
}
|
||||
#endif
|
||||
// get the max of columns
|
||||
int cols = 0;
|
||||
for (i = 0; i < size; i++) {
|
||||
cols = arr[i] > cols ? arr[i] : cols;
|
||||
}
|
||||
cols /= 5;
|
||||
for (i = 0; i < size; i++) {
|
||||
ut8 next = (i + 1 < size)? arr[i + 1]: 0;
|
||||
int base = 0;
|
||||
int base = 0, k = 0;
|
||||
if (addr != UT64_MAX && step > 0) {
|
||||
ut64 at = addr + (i * step);
|
||||
if (p->cur_enabled) {
|
||||
@ -1715,57 +1745,40 @@ R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step
|
||||
} else {
|
||||
p->cb_printf (v_line);
|
||||
}
|
||||
if (show_colors) {
|
||||
int idx = (int) (arr[i] * 5 / 255);
|
||||
const char *k = firebow[idx];
|
||||
p->cb_printf ("%s", k);
|
||||
}
|
||||
if (next < INC) {
|
||||
base = 1;
|
||||
}
|
||||
if (next < arr[i]) {
|
||||
if (arr[i] > INC) {
|
||||
for (j = 0; j < next + base; j += INC) {
|
||||
if (bgFill) {
|
||||
p->cb_printf (i ? " " : br_corner);
|
||||
} else {
|
||||
p->cb_printf (i ? tr_corner : br_corner);
|
||||
}
|
||||
getLineColor (p, k, cols);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
for (j = next + INC; j + base < arr[i]; j += INC) {
|
||||
p->cb_printf (h_line);
|
||||
getLineColor (p, k, cols);
|
||||
k++;
|
||||
}
|
||||
} else {
|
||||
if (i == 0) {
|
||||
for (j = INC; j < arr[i] + base; j += INC) {
|
||||
p->cb_printf (br_corner);
|
||||
}
|
||||
} else {
|
||||
for (j = INC; j < arr[i] + base; j += INC) {
|
||||
p->cb_printf (tr_corner);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (show_colors) {
|
||||
p->cb_printf ("%s%s", v_line, Color_RESET);
|
||||
} else {
|
||||
p->cb_printf (v_line);
|
||||
getLineColor (p, k, cols);
|
||||
k++;
|
||||
}
|
||||
if (i + 1 == size) {
|
||||
for (j = arr[i] + INC + base; j + base < next; j += INC) {
|
||||
p->cb_printf (h_line);
|
||||
getLineColor (p, k, cols);
|
||||
k++;
|
||||
}
|
||||
} else if (arr[i + 1] > arr[i]) {
|
||||
for (j = arr[i] + INC + base; j + base < next; j += INC) {
|
||||
p->cb_printf (h_line);
|
||||
getLineColor (p, k, cols);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
if (show_colors) {
|
||||
p->cb_printf ("%s", Color_RESET);
|
||||
}
|
||||
p->cb_printf ("\n");
|
||||
}
|
||||
for (i = 0; i < 6; i++) {
|
||||
free (firebow[i]);
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_print_2bpp_row(RPrint *p, ut8 *buf) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user