From: Michael D. Lowis Date: Sat, 2 Aug 2014 22:42:19 +0000 (-0400) Subject: Allocated space for the status line and added echoing of typed key combos to it X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c635d102fd66adca5c63dec11146f8e7bd37054e;p=archive%2Fafm.git Allocated space for the status line and added echoing of typed key combos to it --- diff --git a/source/input.c b/source/input.c index aab3cd0..4c0d770 100644 --- a/source/input.c +++ b/source/input.c @@ -1,5 +1,6 @@ #include #include +#include #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; + } } diff --git a/source/screen.c b/source/screen.c index ec71e69..6294e26 100644 --- a/source/screen.c +++ b/source/screen.c @@ -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);