From d4e83e96369aa87d592438b7d99137a42a7bf7c2 Mon Sep 17 00:00:00 2001 From: a bellenir Date: Thu, 17 Jul 2014 20:00:18 +0000 Subject: [PATCH] ls, take1 (no scrolling, no cd) --- source/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/source/main.c b/source/main.c index 392118c..f728076 100644 --- a/source/main.c +++ b/source/main.c @@ -1,6 +1,7 @@ #include #include #include +#include static bool Running = true; //static int Term_X = 0; @@ -8,6 +9,22 @@ static bool Running = true; static WINDOW* WindowLeft; static WINDOW* WindowRight; +void list_files(WINDOW* win) { + FILE* ls = popen("ls", "r"); + char* filename = NULL; + size_t len = 0; + ssize_t read; + int i = 1; + int rows, cols; + getmaxyx(win, rows, cols); + while ((read = getline(&filename, &len, ls)) != -1){ + mvwaddnstr(win, i, 1, filename, cols-2); /* prevent spilling out of window with long filenames */ + i++; + if(i>rows) break; /* TODO: implement scrolling to handle when there are more files than lines */ + } + if(filename) free(filename); +} + void handle_input(char ch) { if(ch == 'q') Running = false; @@ -33,6 +50,7 @@ void update_screen(void) { /* Create the left and right windows */ WindowLeft = create_window(0,0,LINES,COLS/2); wprintw(WindowLeft, "\rLeft"); + list_files(WindowLeft); wrefresh(WindowLeft); WindowRight = create_window(COLS/2,0,LINES,COLS/2); wprintw(WindowRight, "\rRight"); -- 2.49.0