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) {
|
||||
int y;
|
||||
if (c->b) {
|
||||
if (c && c->b) {
|
||||
memset (c->b, '\n', c->blen);
|
||||
c->b[c->blen] = 0;
|
||||
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) {
|
||||
int ret = R_TRUE;
|
||||
if (!c) return 0;
|
||||
x += c->sx;
|
||||
y += c->sy;
|
||||
if (x >= c->w) {
|
||||
@ -85,7 +86,10 @@ static char *getrow (char *p, char **n) {
|
||||
|
||||
static char *prefixline(RConsCanvas *c, int *left) {
|
||||
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++) {
|
||||
if (p[x] == '\n')
|
||||
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) {
|
||||
int x, y, olen = 0;
|
||||
char *o = malloc (c->w*(c->h+1));
|
||||
char *b = c->b;
|
||||
if (!o)
|
||||
return NULL;
|
||||
char *o, *b;
|
||||
if (!c) return NULL;
|
||||
b = c->b;
|
||||
o = malloc (c->w*(c->h+1));
|
||||
if (!o) return NULL;
|
||||
for (y = 0; y<c->h; y++) {
|
||||
for (x = 0; x<c->w; x++) {
|
||||
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) {
|
||||
int blen = (w+1)*h;
|
||||
char *b = NULL;
|
||||
if (w < 0) return R_FALSE;
|
||||
if (!c || w < 0) return R_FALSE;
|
||||
b = realloc (c->b, blen+1);
|
||||
if (!b) return R_FALSE;
|
||||
c->blen = blen;
|
||||
|
@ -579,6 +579,7 @@ R_API int r_cons_get_cursor(int *rows) {
|
||||
return col;
|
||||
}
|
||||
|
||||
// XXX: if this function returns <0 in rows or cols expect MAYHEM
|
||||
R_API int r_cons_get_size(int *rows) {
|
||||
#if EMSCRIPTEN
|
||||
I.columns = 80;
|
||||
@ -614,12 +615,25 @@ R_API int r_cons_get_size(int *rows) {
|
||||
I.rows = 23;
|
||||
}
|
||||
#endif
|
||||
if (rows)
|
||||
*rows = I.rows;
|
||||
#if SIMULATE_ADB_SHELL
|
||||
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_rows) I.rows = I.force_rows;
|
||||
if (I.fix_columns) I.columns += I.fix_columns;
|
||||
if (I.fix_rows) I.rows += I.fix_rows;
|
||||
if (rows)
|
||||
*rows = I.rows;
|
||||
I.rows = R_MAX (0, I.rows);
|
||||
return R_MAX (0, I.columns);
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ static Edge edges[] = {
|
||||
static void Node_print(RConsCanvas *can, Node *n, int cur) {
|
||||
char title[128];
|
||||
|
||||
if (!can)
|
||||
return;
|
||||
n->w = r_str_bounds (n->text, &n->h);
|
||||
n->w += 4;
|
||||
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) {
|
||||
int x, y, x2, y2;
|
||||
int xinc = 3+(nth*3);
|
||||
x = a->x+xinc;
|
||||
y = a->y+a->h;
|
||||
x2 = b->x+xinc;
|
||||
x = a->x + xinc;
|
||||
y = a->y + a->h;
|
||||
x2 = b->x + xinc;
|
||||
y2 = b->y;
|
||||
L (x,y,x2,y2);
|
||||
L (x, y, x2, y2);
|
||||
}
|
||||
|
||||
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];
|
||||
int i, h, w = r_cons_get_size (&h);
|
||||
r_cons_clear00 ();
|
||||
if (!can) {
|
||||
return;
|
||||
}
|
||||
r_cons_canvas_resize (can, w, h);
|
||||
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);
|
||||
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);
|
||||
if (!nodes) {
|
||||
|
@ -1393,6 +1393,11 @@ R_API int r_core_visual(RCore *core, const char *input) {
|
||||
ut64 scrseek;
|
||||
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;
|
||||
//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;
|
||||
r_cons_singleton ()->teefile = "";
|
||||
|
||||
core->print->flags |= R_PRINT_FLAGS_ADDRMOD;
|
||||
core->print->flags |= R_PRINT_FLAGS_ADDRMOD;
|
||||
do {
|
||||
wheel = r_config_get_i (core->config, "scr.wheel");
|
||||
r_cons_show_cursor (R_FALSE);
|
||||
|
Loading…
Reference in New Issue
Block a user