INCS = -Isource/
CPPFLAGS = -D_XOPEN_SOURCE=700
CFLAGS = ${INCS} ${CPPFLAGS}
-LDFLAGS = ${LIBS}
+LDFLAGS = ${LIBS} -lncurses
# commands
COMPILE = @echo CC $@; ${CC} ${CFLAGS} -c -o $@ $<
/* Includes
*****************************************************************************/
#include <util.h>
+#include <ncurses.h>
/* Type Definitions
*****************************************************************************/
/* Globals
*****************************************************************************/
File Curr_File = { .name = NULL, .first = NULL, .last = NULL };
+int Max_Row = 0;
+int Max_Col = 0;
/* Declarations
*****************************************************************************/
*****************************************************************************/
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;
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