radare2/libr/cons
pancake d95befca7a
Fix #16233 - ~{} works on colorized JSONs ##json (#16425)
* Fix #16233 - ~{} works on colorized JSONs ##json
* Fix issue in json_indent
2020-04-06 16:08:47 +08:00
..
d Improve the gentoo theme ##cons 2020-02-11 00:49:40 +01:00
2048.c Fix #16138 - Do not preincrement when it's not necessary (#16151) 2020-03-05 19:06:59 +01:00
canvas_line.c Honor utf8 in diagonal graph lines ##graph 2019-07-18 03:54:15 +02:00
canvas.c Fix double-free in canvas.c (#15379) 2019-10-29 10:24:09 +01:00
cons.c Drop the reset attributes on newlines 2020-03-04 02:10:07 +01:00
cutf8.c Avoid duplicated module filenames to fix static.sh ##build (#16403) 2020-04-02 14:30:27 +02:00
dietline.c Fix #16192 - segfault in qwert^a^x 2020-03-12 12:08:28 +01:00
editor.c Make size arg of r_file_slurp() size_t (#16221) 2020-03-15 23:34:38 +01:00
grep.c Fix #16233 - ~{} works on colorized JSONs ##json (#16425) 2020-04-06 16:08:47 +08:00
html.c Fix again the EOL bgcolor issue (and improve scr.html) (#16120) ##cons 2020-03-04 00:09:12 +01:00
hud.c Avoidify the strTrim() APIs + cleanup/refactor ##util (#16056) 2020-03-02 21:39:37 +01:00
input.c Fix fgets() usage (#16068) 2020-02-29 20:47:10 +01:00
less.c More spelling fixes in the code 2019-06-20 13:36:02 +08:00
line.c Fix #15359 - Enable key.f# keys to be used in the shell ##cons 2020-02-23 11:55:54 +01:00
Makefile Avoid duplicated module filenames to fix static.sh ##build (#16403) 2020-04-02 14:30:27 +02:00
meson.build Avoid duplicated module filenames to fix static.sh ##build (#16403) 2020-04-02 14:30:27 +02:00
more.c More spelling fixes in the code 2019-06-20 13:36:02 +08:00
output.c Drop the reset attributes on newlines 2020-03-04 02:10:07 +01:00
pager_private.h Code cleanup in RCons 2019-06-09 18:50:36 +02:00
pager.c Code cleanup in RCons 2019-06-09 18:50:36 +02:00
pal.c Avoidify the strTrim() APIs + cleanup/refactor ##util (#16056) 2020-03-02 21:39:37 +01:00
pipe.c Fix #10851 - Solve slurp messages on http/sandbox/pipe ##remote 2019-09-16 14:25:37 +02:00
README
rgb.c Fix #16138 - Do not preincrement when it's not necessary (#16151) 2020-03-05 19:06:59 +01:00
stiv.c Update stiv.c to remove warning (#15116) 2019-09-26 18:46:06 +02:00

+--------+
| r_cons |
+--------+

r_cons_fb

r_cons_frame
r_cons_frame_add
r_cons_frame_del

struct r_cons_frame_t {
	int w, h; // should be the same as text|draw->w and text|draw->h 
	int rw, rh;
	struct r_cons_buffer_t *text;
	struct r_cons_buffer_t *draw;
	struct
};

struct r_cons_buffer_t {
	int alpha; /* ' ' chars in buffers are not written */
	int w, h;
	ut8 *buf;
};

struct r_cons_t {
	struct r_cons_buffer_t *b;
	int w, h;
	struct list_head frames;
};

struct r_cons_frame_t *r_cons_frame_new(int x, int y, int w, int h)
{
	struct r_cons_frame_t *f = R_NEW(struct r_cons_frame_t);
	f->text = r_cons_buffer_new(w, h);
	f->draw = r_cons_buffer_new(w, h);
	f->w = w;
	f->h = h;
	return f;
}

void r_cons_frame_add(struct r_cons_t *cons, struct r_cons_frame_t *f, int head)
{
	if (head) list_add(&(f->list), &cons->frames);
	else list_add_tail(&(f->list), &cons->frames);
}


int r_cons_frame_render(struct r_cons_frame_t *frame, struct r_cons_buffer_t *buf)
{
	/* foreach pixel resolve matching frame (Z-ordered) and draw */
}

/* <{:api-prefix r_cons_}> */
/* <{:doc Draws a line between two points in a buffer}> */
/* <{:api int,buffer_line,int,int,int,int}> */
void r_cons_buffer_line(struct r_cons_buffer_t *buf, int x0, int y0, int x1, int y1)
{
	/* XXX PURE SHIT */
	char onechars[9] = {
		'.', '_',',',
		'\\', '|','/',
		'\'', '^','\'',
	};
	double x = x0;
	double y = y0;
	double xi = x1-x0;
	double yi = y1-y0;
	for(;x<x1;x++) {
		r_cons_buffer_putch(buf, x, y, '.');
		x+=xi;
	}
}

/* buffers */

struct r_cons_buffer *r_cons_buffer_new(int w, int h)
{
	struct r_cons_buffer_t *buf = R_NEW(struct r_cons_buffer_t);
	if (w<1) w=1;
	if (h<1) h=1;
	buf->rw = buf->w = w;
	buf->rh = buf->h = h;
	buf->buf = (ut8*)malloc(w*h);
	return buf;
}

int r_cons_buffer_set_size(struct r_cons_buffer *buf, int w, int h)
{
	struct r_cons_buffer_t *buf = R_NEW(struct r_cons_buffer_t);
	if (w<1) w=1;
	if (h<1) h=1;
	if (w>buf->rw) {
		/* must resize internal buffer */
		buf->rw = w;
		buf->buf = (ut8*) realloc(buf->buf, w*h);
	}
	buf->rw = buf->w = w;
	buf->rh = buf->h = h;
	buf->buf = (ut8*)malloc(w*h);
	return buf;
}