From 22e024d5de3c3d6ee158d8c816f11cd52fb6cc35 Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 26 Oct 2016 23:04:55 +0200 Subject: [PATCH] Implement scr.linesleep and scr.pagesize for fancier demo output --- libr/cons/cons.c | 25 +++++++++++++++++++++++-- libr/core/config.c | 16 +++++++++++++++- libr/include/r_cons.h | 2 ++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/libr/cons/cons.c b/libr/cons/cons.c index 0c55726ecf..09457f91a2 100644 --- a/libr/cons/cons.c +++ b/libr/cons/cons.c @@ -246,6 +246,7 @@ R_API RCons *r_cons_new() { I.event_data = NULL; I.is_interactive = true; I.noflush = false; + I.linesleep = 0; I.fdin = stdin; I.fdout = 1; I.breaked = false; @@ -253,7 +254,7 @@ R_API RCons *r_cons_new() { I.buffer = NULL; I.buffer_sz = 0; I.buffer_len = 0; - r_cons_get_size (NULL); + r_cons_get_size (&I.pagesize); I.num = NULL; I.null = 0; #if __WINDOWS__ && !__CYGWIN__ @@ -538,7 +539,27 @@ R_API void r_cons_flush() { if (I.is_html) { r_cons_html_print (I.buffer); } else { - r_cons_write (I.buffer, I.buffer_len); + if (I.linesleep > 0 && I.linesleep < 1000) { + int i = 0; + char *ptr = I.buffer; + char *nl = strchr (ptr, '\n'); + int len = I.buffer_len; + I.buffer[I.buffer_len] = 0; + r_cons_break (NULL, NULL); + while (nl && !r_cons_is_breaked ()) { + r_cons_write (ptr, nl - ptr + 1); + if (!(i % I.pagesize)) { + r_sys_usleep (I.linesleep * 1000); + } + ptr = nl + 1; + nl = strchr (ptr, '\n'); + i++; + } + r_cons_write (ptr, I.buffer + len - ptr); + r_cons_break_end (); + } else { + r_cons_write (I.buffer, I.buffer_len); + } } r_cons_reset (); diff --git a/libr/core/config.c b/libr/core/config.c index ea96c3e6cd..2702c3c80e 100644 --- a/libr/core/config.c +++ b/libr/core/config.c @@ -446,7 +446,7 @@ static int cb_asmfeatures(void *user, void *data) { static int cb_asmcpu(void *user, void *data) { RCore *core = (RCore *) user; RConfigNode *node = (RConfigNode *) data; - if (*node->value=='?') { + if (*node->value == '?') { rasm2_list (core, r_config_get (core->config, "asm.arch"), node->value[1]); return 0; } @@ -1142,6 +1142,18 @@ static int cb_screcho(void *user, void *data) { return true; } +static int cb_scrlinesleep(void *user, void *data) { + RConfigNode *node = (RConfigNode *) data; + r_cons_singleton()->linesleep = node->i_value; + return true; +} + +static int cb_scrpagesize(void *user, void *data) { + RConfigNode *node = (RConfigNode *) data; + r_cons_singleton()->pagesize= node->i_value; + return true; +} + static int cb_scrflush(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; r_cons_singleton()->flush = node->i_value; @@ -1980,6 +1992,8 @@ R_API int r_core_config_init(RCore *core) { #endif r_config_desc (cfg, "scr.fgets", "Use fgets() instead of dietline for prompt input"); SETCB("scr.echo", "false", &cb_screcho, "Show rcons output in realtime to stderr and buffer"); + SETICB("scr.linesleep", 0, &cb_scrlinesleep, "Flush sleeping some ms in every line"); + SETICB("scr.pagesize", 1, &cb_scrpagesize, "Flush in pages when scr.linesleep is != 0"); SETCB("scr.flush", "false", &cb_scrflush, "Force flush to console in realtime (breaks scripting)"); /* TODO: rename to asm.color.ops ? */ SETPREF("scr.zoneflags", "true", "Show zoneflags in visual mode before the title (see fz?)"); diff --git a/libr/include/r_cons.h b/libr/include/r_cons.h index 2d13d3763f..5125a2f8df 100644 --- a/libr/include/r_cons.h +++ b/libr/include/r_cons.h @@ -265,6 +265,8 @@ typedef struct r_cons_t { #endif bool flush; bool use_utf8; // use utf8 features + int linesleep; + int pagesize; } RCons; // XXX THIS MUST BE A SINGLETON AND WRAPPED INTO RCons */