about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-02-27 00:48:55 +0000
committerJames Booth <boothj5@gmail.com>2012-02-27 00:48:55 +0000
commit8f4868593099d852d320c63f8546bd5af44c6023 (patch)
treecf0f95a0cb0bfc5f5a4332bfcba19356daffc6ab
parent2379ae895f77b859da2adc1fb733529b66b33a76 (diff)
downloadprofani-tty-8f4868593099d852d320c63f8546bd5af44c6023.tar.gz
Allow forwards though input history
-rw-r--r--input_buffer.c27
-rw-r--r--input_buffer.h3
-rw-r--r--input_win.c14
3 files changed, 36 insertions, 8 deletions
diff --git a/input_buffer.c b/input_buffer.c
index 98d19952..0e659ad3 100644
--- a/input_buffer.c
+++ b/input_buffer.c
@@ -26,12 +26,12 @@
 
 static char *_inp_buf[BUFMAX];
 static int _buf_size;
-static int _buf_prev;
+static int _buf_pos;
 
 void inpbuf_init(void)
 {
     _buf_size = 0;
-    _buf_prev = -1;
+    _buf_pos = -1;
 }
 
 void inpbuf_append(char *inp)
@@ -39,16 +39,31 @@ void inpbuf_append(char *inp)
     if (_buf_size < BUFMAX) {
         _inp_buf[_buf_size] = (char*) malloc(strlen(inp) * sizeof(char));
         strcpy(_inp_buf[_buf_size], inp);
-        _buf_prev = _buf_size;
+        _buf_pos = _buf_size;
         _buf_size++;
     }
 }
 
-char *inpbuf_get_previous(void)
+char *inpbuf_previous(void)
 {
-    if (_buf_size == 0 || _buf_prev == -1)
+    if (_buf_size == 0 || _buf_pos == -1)
         return NULL;
-    return _inp_buf[_buf_prev--];
+
+    return _inp_buf[_buf_pos--];
 }
 
+char *inpbuf_next(void)
+{
+    if (_buf_size == 0)
+        return NULL;
+    if (_buf_pos == (_buf_size - 1))
+        return NULL;
+    if (_buf_pos + 2 >= _buf_size)
+        return NULL;
+    
+    int pos = _buf_pos + 2;
+    _buf_pos++;
+ 
+    return _inp_buf[pos];
+}
 
diff --git a/input_buffer.h b/input_buffer.h
index 63a5e028..c4384220 100644
--- a/input_buffer.h
+++ b/input_buffer.h
@@ -26,6 +26,7 @@
 
 void inpbuf_init(void);
 void inpbuf_append(char *inp);
-char *inpbuf_get_previous(void);
+char *inpbuf_previous(void);
+char *inpbuf_next(void);
 
 #endif
diff --git a/input_win.c b/input_win.c
index 8becfcc9..91d98caa 100644
--- a/input_win.c
+++ b/input_win.c
@@ -125,7 +125,7 @@ void inp_poll_char(int *ch, char *input, int *size)
 
     // up arrow
     } else if (*ch == KEY_UP) {
-        char *prev = inpbuf_get_previous();
+        char *prev = inpbuf_previous();
         if (prev) {
             strcpy(input, prev);
             *size = strlen(input);
@@ -135,6 +135,18 @@ void inp_poll_char(int *ch, char *input, int *size)
                 waddch(inp_win, input[i]);
         }
 
+    // down arrow
+    } else if (*ch == KEY_DOWN) {
+        char *next = inpbuf_next();
+        if (next) {
+            strcpy(input, next);
+            *size = strlen(input);
+            inp_clear();
+            int i;
+            for (i = 0; i < *size; i++)
+                waddch(inp_win, input[i]);
+        }
+
     // else if not error, newline or special key, 
     // show it and store it
     } else if (*ch != ERR &&