#include <stdlib.h>
#include <string.h>
+#include <ncurses.h>
#include "input.h"
#include "state.h"
#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);
{ "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;
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++;
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;
+ }
}
#include "state.h"
#include "aardvark.h"
+#define STATUS_LINE_MARGIN (1u)
+
static void screen_place_windows(void);
static void screen_refresh_curr_frame(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 */
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);