* Import the cons_interactive functionality of r1 cons

This commit is contained in:
pancake 2009-02-27 00:18:19 +00:00
parent ea44bb103a
commit 8a3349400b
2 changed files with 23 additions and 19 deletions

View File

@ -35,6 +35,7 @@ static char *r_cons_buffer = NULL;
char *r_cons_filterline = NULL; char *r_cons_filterline = NULL;
char *r_cons_teefile = NULL; char *r_cons_teefile = NULL;
int r_cons_is_html = 0; int r_cons_is_html = 0;
int r_cons_interactive = 1;
int r_cons_lines = 0; int r_cons_lines = 0;
int r_cons_noflush = 0; int r_cons_noflush = 0;
@ -160,7 +161,6 @@ void r_cons_clear()
r_cons_lines = 0; r_cons_lines = 0;
} }
void r_cons_reset() void r_cons_reset()
{ {
if (r_cons_buffer) if (r_cons_buffer)
@ -228,6 +228,15 @@ void r_cons_flush()
if (r_cons_noflush) if (r_cons_noflush)
return; return;
if (r_cons_interactive) {
if (r_cons_buffer_len > CONS_MAX_USER) {
if (r_cons_yesno('n', "Do you want to print %d bytes? (y/N)", r_cons_buffer_len)== 0) {
r_cons_reset();
return;
}
}
}
if (!STR_IS_NULL(r_cons_buffer)) { if (!STR_IS_NULL(r_cons_buffer)) {
char *file = r_cons_filterline; char *file = r_cons_filterline;
char *tee = r_cons_teefile; char *tee = r_cons_teefile;
@ -503,30 +512,24 @@ int r_cons_get_real_columns()
#endif #endif
} }
#ifdef RADARE_CORE int r_cons_yesno(int def, const char *fmt, ...)
int yesno(int def, const char *fmt, ...)
{ {
va_list ap; va_list ap;
int key = def; int key = def;
if (config.visual) va_start(ap, fmt);
key='y'; vfprintf(stderr, fmt, ap);
else D { va_end(ap);
va_start(ap, fmt); fflush(stderr);
vfprintf(stderr, fmt, ap); r_cons_set_raw(1);
va_end(ap); read(0, &key, 1); write(2, "\n", 1);
fflush(stderr); r_cons_set_raw(0);
r_cons_set_raw(1); if (key=='\n'||key=='\r')
read(0, &key, 1); write(2, "\n", 1); key = def;
r_cons_set_raw(0); else key = 'y';
if (key=='\n'||key=='\r')
key = def;
} else
key = 'y';
return key=='y'; return key=='y';
} }
#endif
/** /**
* *

View File

@ -9,6 +9,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#define CONS_MAX_USER 102400
#define CONS_BUFSZ 0x4f00 #define CONS_BUFSZ 0x4f00
#define STR_IS_NULL(x) (!x || !x[0]) #define STR_IS_NULL(x) (!x || !x[0])
#define IS_PRINTABLE(x) (x>=' '&&x<='~') #define IS_PRINTABLE(x) (x>=' '&&x<='~')
@ -136,6 +137,6 @@ const char *r_cons_get_buffer();
void r_cons_grep(const char *str); void r_cons_grep(const char *str);
void r_cons_invert(int set, int color); void r_cons_invert(int set, int color);
int r_cons_yesno(int def, const char *fmt, ...);
#endif #endif