diff --git a/libr/cons/cons.c b/libr/cons/cons.c index ff390984ed..994d1d488c 100644 --- a/libr/cons/cons.c +++ b/libr/cons/cons.c @@ -167,7 +167,7 @@ R_API void r_cons_strcat_justify (const char *str, int j, char c) { } } if (len > 1) { - r_cons_memcat (str+o, len); + r_cons_memcat (str + o, len); } } @@ -381,6 +381,7 @@ R_API RCons *r_cons_free() { free (I.buffer); I.buffer = NULL; } + R_FREE (I.break_word); r_stack_free (I.cons_stack); r_stack_free (I.break_stack); return NULL; @@ -828,6 +829,11 @@ R_API void r_cons_memcat(const char *str, int len) { if (I.flush) { r_cons_flush (); } + if (I.break_word) { + if (r_mem_mem ((const ut8*)str, len, (const ut8*)I.break_word, I.break_word_len)) { + I.breaked = true; + } + } } R_API void r_cons_memset(char ch, int len) { @@ -1248,3 +1254,13 @@ R_API const char* r_cons_get_rune(const ut8 ch) { return NULL; } +R_API void r_cons_breakword(const char *s) { + free (I.break_word); + if (s) { + I.break_word = strdup (s); + I.break_word_len = strlen (s); + } else { + I.break_word = NULL; + I.break_word_len = 0; + } +} diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c index ffdf2a3432..c80b08de7f 100644 --- a/libr/core/cconfig.c +++ b/libr/core/cconfig.c @@ -1158,6 +1158,16 @@ static int cb_rgbcolors(void *user, void *data) { return true; } +static int cb_scrbreak(void* user, void* data) { + RConfigNode *node = (RConfigNode*) data; + if (*node->value) { + r_cons_breakword (node->value); + } else { + r_cons_breakword (NULL); + } + return true; +} + static int cb_scrcolumns(void* user, void* data) { RConfigNode *node = (RConfigNode*) data; RCore *core = (RCore*) user; @@ -2099,6 +2109,7 @@ R_API int r_core_config_init(RCore *core) { SETPREF("scr.atport", "false", "V@ starts a background http server and spawns an r2 -C"); SETI("scr.wheelspeed", 4, "Mouse wheel speed"); // DEPRECATED: USES hex.cols now SETI("scr.colpos", 80, "Column position of cmd.cprompt in visual"); + SETCB("scr.break", "", &cb_scrbreak, "Emulate console break (^C) when a word is printed (useful for pD)"); SETICB("scr.columns", 0, &cb_scrcolumns, "Force console column count (width)"); SETCB("scr.rows", "0", &cb_scrrows, "Force console row count (height) "); SETICB("scr.rows", 0, &cb_rows, "Force console row count (height) (duplicate?)"); diff --git a/libr/include/r_cons.h b/libr/include/r_cons.h index 4cf85a7501..b39ab6225e 100644 --- a/libr/include/r_cons.h +++ b/libr/include/r_cons.h @@ -269,6 +269,8 @@ typedef struct r_cons_t { bool use_utf8; // use utf8 features int linesleep; int pagesize; + char *break_word; + int break_word_len; ut64 timeout; } RCons; @@ -429,6 +431,7 @@ typedef void (*RConsBreak)(void *); R_API void r_cons_break_end(void); R_API bool r_cons_is_breaked(); R_API void r_cons_break_timeout(int timeout); +R_API void r_cons_breakword(const char *s); /* pipe */ R_API int r_cons_pipe_open(const char *file, int fdn, int append);