mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 13:49:50 +00:00
Fix the support for 0x0 sized terminals (adb shell)
This commit is contained in:
parent
0931f502ed
commit
a18f7819d9
@ -12,7 +12,7 @@ R_API void r_cons_canvas_free (RConsCanvas *c) {
|
|||||||
|
|
||||||
R_API void r_cons_canvas_clear (RConsCanvas *c) {
|
R_API void r_cons_canvas_clear (RConsCanvas *c) {
|
||||||
int y;
|
int y;
|
||||||
if (c->b) {
|
if (c && c->b) {
|
||||||
memset (c->b, '\n', c->blen);
|
memset (c->b, '\n', c->blen);
|
||||||
c->b[c->blen] = 0;
|
c->b[c->blen] = 0;
|
||||||
for (y = 0; y<c->h; y++)
|
for (y = 0; y<c->h; y++)
|
||||||
@ -43,6 +43,7 @@ R_API RConsCanvas* r_cons_canvas_new (int w, int h) {
|
|||||||
|
|
||||||
R_API int r_cons_canvas_gotoxy(RConsCanvas *c, int x, int y) {
|
R_API int r_cons_canvas_gotoxy(RConsCanvas *c, int x, int y) {
|
||||||
int ret = R_TRUE;
|
int ret = R_TRUE;
|
||||||
|
if (!c) return 0;
|
||||||
x += c->sx;
|
x += c->sx;
|
||||||
y += c->sy;
|
y += c->sy;
|
||||||
if (x >= c->w) {
|
if (x >= c->w) {
|
||||||
@ -85,7 +86,10 @@ static char *getrow (char *p, char **n) {
|
|||||||
|
|
||||||
static char *prefixline(RConsCanvas *c, int *left) {
|
static char *prefixline(RConsCanvas *c, int *left) {
|
||||||
int x;
|
int x;
|
||||||
char *p = c->b + (c->y * c->w);
|
char *p;
|
||||||
|
if (!c)
|
||||||
|
return NULL;
|
||||||
|
p = c->b + (c->y * c->w);
|
||||||
for (x = 0; x<c->x; x++) {
|
for (x = 0; x<c->x; x++) {
|
||||||
if (p[x] == '\n')
|
if (p[x] == '\n')
|
||||||
p[x] = ' ';
|
p[x] = ' ';
|
||||||
@ -128,10 +132,11 @@ R_API void r_cons_canvas_write(RConsCanvas *c, const char *_s) {
|
|||||||
|
|
||||||
R_API char *r_cons_canvas_to_string(RConsCanvas *c) {
|
R_API char *r_cons_canvas_to_string(RConsCanvas *c) {
|
||||||
int x, y, olen = 0;
|
int x, y, olen = 0;
|
||||||
char *o = malloc (c->w*(c->h+1));
|
char *o, *b;
|
||||||
char *b = c->b;
|
if (!c) return NULL;
|
||||||
if (!o)
|
b = c->b;
|
||||||
return NULL;
|
o = malloc (c->w*(c->h+1));
|
||||||
|
if (!o) return NULL;
|
||||||
for (y = 0; y<c->h; y++) {
|
for (y = 0; y<c->h; y++) {
|
||||||
for (x = 0; x<c->w; x++) {
|
for (x = 0; x<c->w; x++) {
|
||||||
int p = x + (y*c->w);
|
int p = x + (y*c->w);
|
||||||
@ -156,7 +161,7 @@ R_API void r_cons_canvas_print(RConsCanvas *c) {
|
|||||||
R_API int r_cons_canvas_resize(RConsCanvas *c, int w, int h) {
|
R_API int r_cons_canvas_resize(RConsCanvas *c, int w, int h) {
|
||||||
int blen = (w+1)*h;
|
int blen = (w+1)*h;
|
||||||
char *b = NULL;
|
char *b = NULL;
|
||||||
if (w < 0) return R_FALSE;
|
if (!c || w < 0) return R_FALSE;
|
||||||
b = realloc (c->b, blen+1);
|
b = realloc (c->b, blen+1);
|
||||||
if (!b) return R_FALSE;
|
if (!b) return R_FALSE;
|
||||||
c->blen = blen;
|
c->blen = blen;
|
||||||
|
@ -579,6 +579,7 @@ R_API int r_cons_get_cursor(int *rows) {
|
|||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: if this function returns <0 in rows or cols expect MAYHEM
|
||||||
R_API int r_cons_get_size(int *rows) {
|
R_API int r_cons_get_size(int *rows) {
|
||||||
#if EMSCRIPTEN
|
#if EMSCRIPTEN
|
||||||
I.columns = 80;
|
I.columns = 80;
|
||||||
@ -614,12 +615,25 @@ R_API int r_cons_get_size(int *rows) {
|
|||||||
I.rows = 23;
|
I.rows = 23;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (rows)
|
#if SIMULATE_ADB_SHELL
|
||||||
*rows = I.rows;
|
I.rows = 0;
|
||||||
|
I.columns = 0;
|
||||||
|
#endif
|
||||||
|
#if SIMULATE_MAYHEM
|
||||||
|
// expect tons of crashes
|
||||||
|
I.rows = -1;
|
||||||
|
I.columns = -1;
|
||||||
|
#endif
|
||||||
|
if (I.rows<0)
|
||||||
|
I.rows = 0;
|
||||||
|
if (I.columns<0)
|
||||||
|
I.columns = 0;
|
||||||
if (I.force_columns) I.columns = I.force_columns;
|
if (I.force_columns) I.columns = I.force_columns;
|
||||||
if (I.force_rows) I.rows = I.force_rows;
|
if (I.force_rows) I.rows = I.force_rows;
|
||||||
if (I.fix_columns) I.columns += I.fix_columns;
|
if (I.fix_columns) I.columns += I.fix_columns;
|
||||||
if (I.fix_rows) I.rows += I.fix_rows;
|
if (I.fix_rows) I.rows += I.fix_rows;
|
||||||
|
if (rows)
|
||||||
|
*rows = I.rows;
|
||||||
I.rows = R_MAX (0, I.rows);
|
I.rows = R_MAX (0, I.rows);
|
||||||
return R_MAX (0, I.columns);
|
return R_MAX (0, I.columns);
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,8 @@ static Edge edges[] = {
|
|||||||
static void Node_print(RConsCanvas *can, Node *n, int cur) {
|
static void Node_print(RConsCanvas *can, Node *n, int cur) {
|
||||||
char title[128];
|
char title[128];
|
||||||
|
|
||||||
|
if (!can)
|
||||||
|
return;
|
||||||
n->w = r_str_bounds (n->text, &n->h);
|
n->w = r_str_bounds (n->text, &n->h);
|
||||||
n->w += 4;
|
n->w += 4;
|
||||||
n->h += 3;
|
n->h += 3;
|
||||||
@ -81,11 +83,11 @@ static void Node_print(RConsCanvas *can, Node *n, int cur) {
|
|||||||
static void Edge_print(RConsCanvas *can, Node *a, Node *b, int nth) {
|
static void Edge_print(RConsCanvas *can, Node *a, Node *b, int nth) {
|
||||||
int x, y, x2, y2;
|
int x, y, x2, y2;
|
||||||
int xinc = 3+(nth*3);
|
int xinc = 3+(nth*3);
|
||||||
x = a->x+xinc;
|
x = a->x + xinc;
|
||||||
y = a->y+a->h;
|
y = a->y + a->h;
|
||||||
x2 = b->x+xinc;
|
x2 = b->x + xinc;
|
||||||
y2 = b->y;
|
y2 = b->y;
|
||||||
L (x,y,x2,y2);
|
L (x, y, x2, y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Edge_node(Edge *edges, int cur, int nth) {
|
static int Edge_node(Edge *edges, int cur, int nth) {
|
||||||
@ -322,6 +324,9 @@ static void r_core_graph_refresh (RCore *core) {
|
|||||||
char title[128];
|
char title[128];
|
||||||
int i, h, w = r_cons_get_size (&h);
|
int i, h, w = r_cons_get_size (&h);
|
||||||
r_cons_clear00 ();
|
r_cons_clear00 ();
|
||||||
|
if (!can) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
r_cons_canvas_resize (can, w, h);
|
r_cons_canvas_resize (can, w, h);
|
||||||
r_cons_canvas_clear (can);
|
r_cons_canvas_clear (can);
|
||||||
|
|
||||||
@ -362,6 +367,10 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn) {
|
|||||||
}
|
}
|
||||||
w = r_cons_get_size (&h);
|
w = r_cons_get_size (&h);
|
||||||
can = r_cons_canvas_new (w-1, h-1);
|
can = r_cons_canvas_new (w-1, h-1);
|
||||||
|
if (!can) {
|
||||||
|
eprintf ("Cannot create RCons.canvas context\n");
|
||||||
|
return R_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
n_nodes = bbNodes (core, fcn, &nodes);
|
n_nodes = bbNodes (core, fcn, &nodes);
|
||||||
if (!nodes) {
|
if (!nodes) {
|
||||||
|
@ -1393,6 +1393,11 @@ R_API int r_core_visual(RCore *core, const char *input) {
|
|||||||
ut64 scrseek;
|
ut64 scrseek;
|
||||||
int wheel, flags, ch;
|
int wheel, flags, ch;
|
||||||
|
|
||||||
|
if (r_cons_get_size(&ch)<1 || ch<1) {
|
||||||
|
eprintf ("Cannot create Visual context. Use scr.fix_{columns|rows}\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
obs = core->blocksize;
|
obs = core->blocksize;
|
||||||
//r_cons_set_cup (R_TRUE);
|
//r_cons_set_cup (R_TRUE);
|
||||||
|
|
||||||
@ -1408,7 +1413,7 @@ R_API int r_core_visual(RCore *core, const char *input) {
|
|||||||
teefile = r_cons_singleton ()->teefile;
|
teefile = r_cons_singleton ()->teefile;
|
||||||
r_cons_singleton ()->teefile = "";
|
r_cons_singleton ()->teefile = "";
|
||||||
|
|
||||||
core->print->flags |= R_PRINT_FLAGS_ADDRMOD;
|
core->print->flags |= R_PRINT_FLAGS_ADDRMOD;
|
||||||
do {
|
do {
|
||||||
wheel = r_config_get_i (core->config, "scr.wheel");
|
wheel = r_config_get_i (core->config, "scr.wheel");
|
||||||
r_cons_show_cursor (R_FALSE);
|
r_cons_show_cursor (R_FALSE);
|
||||||
|
Loading…
Reference in New Issue
Block a user