]> git.mdlowis.com Git - archive/afm.git/commitdiff
Allocated space for the status line and added echoing of typed key combos to it
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 2 Aug 2014 22:42:19 +0000 (18:42 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 2 Aug 2014 22:42:19 +0000 (18:42 -0400)
source/input.c
source/screen.c

index aab3cd04bf6ba48d2e094ad13cdad14e5593b90e..4c0d77043619dcea43db612a5e97491d83dee536 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <string.h>
+#include <ncurses.h>
 
 #include "input.h"
 #include "state.h"
@@ -7,7 +8,11 @@
 #include "screen.h"
 #include "frame.h"
 
-#define ESC 27
+#define ESC (27)
+
+#define KEY_BUFFER_LENGTH (1024)
+
+static void print_status(void);
 
 typedef void (*key_cb_t)(void);
 
@@ -117,7 +122,7 @@ static binding_t Default_Bindings[] = {
     { "R",  &handle_force_redraw }
 };
 
-static char Key_Buffer[16] = {0};
+static char Key_Buffer[KEY_BUFFER_LENGTH] = {0};
 
 void input_handle_key(char ch) {
     bool more_matches = false;
@@ -125,16 +130,19 @@ void input_handle_key(char ch) {
     size_t num_entries = (sizeof(Default_Bindings) / sizeof(binding_t));
     unsigned int len = strlen(Key_Buffer);
 
-    /* If no more room then reset the buffer */
-    if (len+1 >= 16) {
+    /* Escape key puts us back into normal mode */
+    if (ch == 27u)
+    {
+        Key_Buffer[0] = '\0';
+        state_set_mode(MODE_NORMAL);
+    }
+    /* If no more room then alert the user */
+    else if (len+1 >= KEY_BUFFER_LENGTH) {
         beep();
         flash();
-        len = 0;
-        Key_Buffer[0] = '\0';
     }
-
     /* If we got a valid key then process it */
-    if((char)ERR != ch) {
+    else if((char)ERR != ch) {
         unsigned int i;
         /* Put the key in the buffer */
         len++;
@@ -170,5 +178,26 @@ void input_handle_key(char ch) {
             Key_Buffer[0] = '\0';
         }
     }
+    print_status();
+}
+
+static void print_status(void) {
+    int lines, cols;
+    getmaxyx(stdscr, lines, cols);
+    (void)cols;
+    move(lines-1, 0);
+    clrtoeol();
+    switch(state_get_mode()) {
+        case MODE_NORMAL:
+            printw(Key_Buffer);
+            break;
+
+        case MODE_SEARCH:
+            printw("/%s", Key_Buffer);
+            break;
+
+        default:
+            break;
+    }
 }
 
index ec71e6965274e742365868c3c5130a7aa0781d26..6294e2610b7a56706f3a7edeccf07c1a07f9a33e 100644 (file)
@@ -15,6 +15,8 @@
 #include "state.h"
 #include "aardvark.h"
 
+#define STATUS_LINE_MARGIN (1u)
+
 static void screen_place_windows(void);
 static void screen_refresh_curr_frame(void);
 
@@ -90,7 +92,7 @@ static void screen_place_windows(void) {
     /* Print the master frame */
     p_frame = list_at(Frame_List,0)->contents;
     frame_move(p_frame, 0, 0);
-    frame_resize(p_frame, lines, (num_frames > 1) ? cols/2 : cols);
+    frame_resize(p_frame, lines-STATUS_LINE_MARGIN, (num_frames > 1) ? cols/2 : cols);
     frame_draw(p_frame);
 
     /* Print any other frames we might have */
@@ -99,8 +101,8 @@ static void screen_place_windows(void) {
     id = 1;
     while(p_node != NULL) {
         /* Get the frame and it's properties */
-        int remain = (lines % (num_frames-1));
-        int height = (lines / (num_frames-1)) + (id <= remain ? 1 : 0);
+        int remain = ((lines - STATUS_LINE_MARGIN) % (num_frames-1));
+        int height = ((lines - STATUS_LINE_MARGIN) / (num_frames-1)) + (id <= remain ? 1 : 0);
         p_frame = p_node->contents;
         /* Place the frame */
         frame_move(p_frame, pos, cols/2);