Fix prompt history issues reported in #34

This commit is contained in:
pancake 2012-11-20 12:32:19 +01:00
parent 83ea1201e9
commit 3a93f8bbbd
2 changed files with 6 additions and 2 deletions

View File

@ -74,6 +74,9 @@ R_API int r_line_hist_add(const char *line) {
inithist ();
if (I.history.top>=I.history.size)
I.history.top = I.history.index = 0; // workaround
/* ignore dup */
if (I.history.index>0 && !strcmp (line, I.history.data[I.history.index-1]))
return R_FALSE;
if (line && *line) { // && I.history.index < I.history.size) {
I.history.data[I.history.top++] = strdup (line);
I.history.index = I.history.top;
@ -98,12 +101,12 @@ static int r_line_hist_down() {
if (!I.history.data)
inithist ();
if (I.history.index<I.history.size) {
if (I.history.data[I.history.index] == NULL) {
if (I.history.data[I.history.index+1] == NULL) {
I.buffer.data[0]='\0';
I.buffer.index = I.buffer.length = 0;
return 0;
}
strncpy (I.buffer.data, I.history.data[I.history.index++], R_LINE_BUFSIZE-1);
strncpy (I.buffer.data, I.history.data[++I.history.index], R_LINE_BUFSIZE-1);
I.buffer.index = I.buffer.length = strlen (I.buffer.data);
return R_TRUE;
}

View File

@ -87,6 +87,7 @@ R_API void r_core_visual_prompt (RCore *core) {
#endif
r_cons_show_cursor (R_TRUE);
r_cons_fgets (buf, sizeof (buf), 0, NULL);
r_line_hist_add (buf);
r_core_cmd (core, buf, 0);
r_cons_any_key ();
r_cons_clear00 ();