]> git.mdlowis.com Git - archive/afm.git/commitdiff
ls, take1 (no scrolling, no cd)
authora bellenir <a@bellenir.com>
Thu, 17 Jul 2014 20:00:18 +0000 (20:00 +0000)
committera bellenir <a@bellenir.com>
Thu, 17 Jul 2014 20:00:18 +0000 (20:00 +0000)
source/main.c

index 392118c40de5be418db19e676ca4a49687213110..f7280764c44e461ac4ec68afddf5a318336415dd 100644 (file)
@@ -1,6 +1,7 @@
 #include <ncurses.h>
 #include <stdbool.h>
 #include <signal.h>
+#include <stdlib.h>
 
 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");