From 6a0787c0ddbc3a4ff06c4e01fdb19ef75aa87db2 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 18 Jul 2014 18:30:48 -0400 Subject: [PATCH] started integrating list_files --- source/main.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/source/main.c b/source/main.c index 9f67b1e..9de2826 100644 --- a/source/main.c +++ b/source/main.c @@ -10,9 +10,27 @@ typedef struct { static bool Running = true; static bool Screen_Dirty = true; -void handle_input(char ch) { - if(ch == 'q') - Running = false; +void list_files(void) { + FILE* ls = popen("ls", "r"); + char* filename = NULL; + size_t len = 0; + ssize_t read; + int topbuff=1; /* lines to skip before printing (window border/title) */ + int i = 0; + while ((read = getline(&filename, &len, ls)) != -1){ + if(i==Idx){ + attron(A_STANDOUT); + attron(A_BOLD); + } + mvaddnstr(i+topbuff, 1, filename, COLS-2); /* prevent spilling out of window with long filenames */ + if(i==Idx){ + attroff(A_STANDOUT); + attroff(A_BOLD); + } + i++; + if(i>ROWS) break; /* TODO: implement scrolling to handle when there are more files than lines */ + } + if(filename) free(filename); } void update_screen(void) { @@ -35,6 +53,10 @@ void update_screen(void) { Screen_Dirty = false; } +void handle_input(char ch) { + if(ch == 'q') Running = false; +} + void handle_signal(int sig) { signal(SIGWINCH, handle_signal); Screen_Dirty = true; -- 2.49.0