Ejemplo n.º 1
0
R_API RConsCanvas *r_cons_canvas_new(int w, int h) {
	RConsCanvas *c;
	if (w < 1 || h < 1) {
		return NULL;
	}
	c = R_NEW0 (RConsCanvas);
	if (!c) return NULL;
	c->color = 0;
	c->sx = 0;
	c->sy = 0;
	c->blen = (w + 1) * h;
	c->b = malloc (c->blen + 1);
	if (!c->b) {
		free (c);
		return NULL;
	}
	c->attrslen = 0;
	c->attrs = calloc (sizeof (*c->attrs), c->blen + 1);
	if (!c->attrs) {
		free (c->b);
		free (c);
		return NULL;
	}
	c->attr = Color_RESET;
	c->w = w;
	c->h = h;
	c->x = c->y = 0;
	r_cons_canvas_clear (c);
	return c;
}
Ejemplo n.º 2
0
R_API int r_cons_canvas_resize(RConsCanvas *c, int w, int h) {
	void *newbuf = NULL;
	const int blen = (w + 1) * h;
	char *b = NULL;
	if (!c || w < 0) {
		return false;
	}
	b = realloc (c->b, blen + 1);
	if (!b) {
		return false;
	}
	c->b = b;
	newbuf = realloc (c->attrs, sizeof (*c->attrs) * blen + 1);
	if (!newbuf) {
		free (c->b);
		free (c->attrs);
		return false;
	}
	c->attrs = newbuf;
	c->blen = blen;
	c->b = b;
	c->w = w;
	c->h = h;
	c->x = 0;
	c->y = 0;
	r_cons_canvas_clear (c);
	return true;
}
Ejemplo n.º 3
0
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;
    b = realloc (c->b, blen+1);
    if (!b) return R_FALSE;
    c->blen = blen;
    c->b = b;
    c->w = w;
    c->h = h;
    c->x = 0;
    c->y = 0;
    r_cons_canvas_clear (c);
    return R_TRUE;
}
Ejemplo n.º 4
0
R_API RConsCanvas* r_cons_canvas_new (int w, int h) {
    RConsCanvas *c;
    if (w<1||h<1)
        return NULL;
    c = R_NEW0 (RConsCanvas);
    if (!c) return NULL;
    c->sx = 0;
    c->sy = 0;
    c->blen = (w+1)*h;
    c->b = malloc (c->blen+1);
    if (!c->b) {
        free (c);
        return NULL;
    }
    c->w = w;
    c->h = h;
    c->x = c->y = 0;
    r_cons_canvas_clear (c);
    return c;
}
Ejemplo n.º 5
0
// damn singletons.. there should be only one screen and therefor
// only one visual instance of the graph view. refactoring this
// into a struct makes the code to reference pointers unnecesarily
// we can look for a non-global solution here in the future if
// necessary
static void r_core_panels_refresh (RCore *core) {
	char title[128];
	int i, j, h, w = r_cons_get_size (&h);
	if (instep && core->io->debug) {
		r_core_cmd0 (core, "sr pc");
	}
	r_cons_clear00 ();
	if (!can) {
		return;
	}
	r_cons_canvas_resize (can, w, h);
	r_cons_canvas_clear (can);
	if (panels) {
		if (menu_y>0) {
			panels[menu_pos].x = menu_x * 6;
		} else {
			panels[menu_pos].x = w;
		}
		panels[menu_pos].y = 1;
		free (panels[menu_pos].text);
		panels[menu_pos].text = malloc(1024); //r_str_newf ("%d", menu_y);
		panels[menu_pos].text[0] = 0;
		int maxsub = 0;
		for (i=0; menus_sub[i]; i++) { maxsub = i; }
		if (menu_x >= 0 && menu_x <maxsub && menus_sub[menu_x]) {
			for (j = 0; menus_sub[menu_x][j]; j++) {
				if (menu_y-1 == j) {
					strcat (panels[menu_pos].text, "> ");
				} else {
					strcat (panels[menu_pos].text, "  ");
				}
				strcat (panels[menu_pos].text,
					menus_sub[menu_x][j]);
				strcat (panels[menu_pos].text, "        \n");
			}
		}
		for (i=0; panels[i].text; i++) {
		  if (i != curnode) {
		    Panel_print (can, &panels[i], i==curnode);
		  }
		}
	}

	if (menu_y) {
		curnode = menu_pos;
	}
	// redraw current node to make it appear on top
	if (curnode >= 0) {
		Panel_print (can, &panels[curnode], 1);
	}
	Panel_print (can, &panels[menu_pos], menu_y);

	(void)G (-can->sx, -can->sy);
	char str[128];
	title[0] = 0;
	for (i=0; menus[i]; i++) {
		if (menu_x == i) {
			snprintf (str, sizeof (title)-1, "[%s]", menus[i]);
		} else {
			snprintf (str, sizeof (title)-1, " %s ", menus[i]);
		}
		strcat (title, str);
	}
	W (title);

	snprintf (title, sizeof (title)-1,
		"[0x%08"PFMT64x"]", core->offset);
	(void)G (-can->sx + w-strlen (title), -can->sy);
	W (title);

	r_cons_canvas_print (can);
	r_cons_flush_nonewline ();
}