]> git.mdlowis.com Git - projs/tide.git/commitdiff
Implemented simple paging mechanism
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 1 Jan 2016 18:00:20 +0000 (13:00 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 1 Jan 2016 18:00:20 +0000 (13:00 -0500)
Makefile
source/main.c

index 50ba670804d729fb60de27717a0e7eede096ca8d..304fa69d36d47d6c65923ad224a91581b72fb049 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ LD = ${CC}
 INCS     = -Isource/
 CPPFLAGS = -D_XOPEN_SOURCE=700
 CFLAGS   = ${INCS} ${CPPFLAGS}
-LDFLAGS  = ${LIBS}
+LDFLAGS  = ${LIBS} -lncurses
 
 # commands
 COMPILE = @echo CC $@; ${CC} ${CFLAGS} -c -o $@ $<
index 2184c8bfefb3846493b2a8a7532b54bb33728c7a..860c43f00c982d156ad4ded9c1a490f3387e8a4e 100644 (file)
@@ -1,6 +1,7 @@
 /* Includes
  *****************************************************************************/
 #include <util.h>
+#include <ncurses.h>
 
 /* Type Definitions
  *****************************************************************************/
@@ -20,6 +21,8 @@ typedef struct {
 /* Globals
  *****************************************************************************/
 File Curr_File = { .name = NULL, .first = NULL, .last = NULL };
+int Max_Row = 0;
+int Max_Col = 0;
 
 /* Declarations
  *****************************************************************************/
@@ -32,10 +35,18 @@ static void edit(void);
  *****************************************************************************/
 static void setup(void)
 {
+    initscr();
+    getmaxyx(stdscr, Max_Row, Max_Col);
+    raw();
+    keypad(stdscr, true);
+    noecho();
 }
 
 static void cleanup(void)
 {
+    /* shutdown ncurses */
+    endwin();
+    /* free up malloced data */
     Line* line = Curr_File.first;
     while (line) {
         Line* deadite = line;
@@ -65,11 +76,29 @@ static void load(char* fname)
 
 static void edit(void)
 {
-    Line* line = Curr_File.first;
-    while (line) {
-        printf("%s", line->text);
-        line = line->next;
-    }
+    Line* start = Curr_File.first;
+    int ch = 0;
+    do {
+        /* Handle input */
+        switch (ch) {
+            case 'k':
+            case KEY_UP:
+                if(start->prev) start = start->prev;
+                break;
+            case 'j':
+            case KEY_DOWN:
+                if(start->next) start = start->next;
+                break;
+        }
+
+        /* Refresh the screen */
+        clear();
+        Line* line = start;
+        for (int i = 0; (i < Max_Row) && line; i++, line = line->next) {
+            mvprintw(i, 0, "%s", line->text);
+        }
+        refresh();
+    } while((ch = getch()) != 'q');
 }
 
 /* Main Routine