From 3b1299c6474b31bbd62e2a40d5c15a81be8ca0e0 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 18 Jul 2014 18:44:40 -0400 Subject: [PATCH] integrated cursor selection code --- source/main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/source/main.c b/source/main.c index 9de2826..be61d22 100644 --- a/source/main.c +++ b/source/main.c @@ -9,6 +9,7 @@ typedef struct { static bool Running = true; static bool Screen_Dirty = true; +static int Idx = 0; /* TODO: this should be per-window */ void list_files(void) { FILE* ls = popen("ls", "r"); @@ -28,7 +29,7 @@ void list_files(void) { attroff(A_BOLD); } i++; - if(i>ROWS) break; /* TODO: implement scrolling to handle when there are more files than lines */ + if(i>LINES) break; /* TODO: implement scrolling to handle when there are more files than lines */ } if(filename) free(filename); } @@ -38,7 +39,7 @@ void update_screen(void) { endwin(); clear(); /* Draw the Contents */ - // TODO + list_files(); /* Draw the Border */ mvaddch(0, 0, ACS_ULCORNER); mvhline(0, 1, ACS_HLINE, COLS-2); @@ -54,7 +55,20 @@ void update_screen(void) { } void handle_input(char ch) { - if(ch == 'q') Running = false; + /* Assume screen is dirty by default */ + bool is_screen_dirty = true; + /* Handle the key press */ + switch(ch) { + case 'q': Running = false; + break; + case 'j': Idx += 1; + break; + case 'k': Idx -= 1; + break; + default: is_screen_dirty = false; // Screen is not actually dirty + break; + }; + Screen_Dirty = Screen_Dirty || is_screen_dirty; } void handle_signal(int sig) { -- 2.49.0