]> git.mdlowis.com Git - archive/afm.git/commitdiff
started integrating list_files
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 18 Jul 2014 22:30:48 +0000 (18:30 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 18 Jul 2014 22:30:48 +0000 (18:30 -0400)
source/main.c

index 9f67b1e8fd773ce20cf59d22493c1f599a429ab6..9de28261d80da1f7ef37b9883077ac410bdef038 100644 (file)
@@ -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;