83b5aa048c79a627dc34865378d56751ff0d095e
[taskasaur.git] / main.c
1 #include <stdio.h>
2 #include <ncurses.h>
3 #include <signal.h>
4 #include <unistd.h>
5
6 void winch_handler(int sig); 
7
8 WINDOW* create_list_win(int height, int width, int y, int x);
9
10 #include "config.h"
11
12 int 
13 main(int argc, char** argv) 
14 {
15     FILE* board_file;
16     int height, width;
17     int x, y;
18     int ch;
19     WINDOW* todo_win;
20
21     signal(SIGWINCH, winch_handler);
22
23     // read from task file
24     board_file = fopen(default_board_file, "r");
25     if (!board_file) {
26         printf("File does not exist\n");
27         return 1;
28     }   
29     fclose(board_file);
30
31     // start ncurses 
32     initscr();
33     cbreak();
34     /* raw(); */
35     noecho();
36     start_color();
37     
38     init_pair(1, COLOR_CYAN, COLOR_BLACK); 
39     init_pair(2, COLOR_BLACK, COLOR_CYAN); 
40
41     getmaxyx(stdscr, height, width);
42     x = y = 0;
43     refresh();
44
45     todo_win = create_list_win(20, 20, 5, 5);
46     
47     move(y,x);
48     while ((ch = getch()) != 113) { // while not q
49         
50         // ofc the first thing we need is vim keys 
51         switch (ch) {
52             case 104: // h
53                 x -= 1;
54                 break;
55             case 106: // j
56                 y += 1;
57                 break;
58             case 107: // k
59                 y -= 1;
60                 break;
61             case 108: // l
62                 x += 1;
63                 break;
64         } 
65
66         move(y,x);
67         refresh();
68         /* clear(); */
69     }
70
71     endwin();
72     return 0;
73 }
74
75 void 
76 winch_handler(int sig) 
77 {
78     endwin();
79     refresh();
80 }
81
82 WINDOW* 
83 create_list_win(int height, int width, int y, int x)
84 {
85     WINDOW* new_win = newwin(height, width, y, x);
86     box(new_win, 0, 0);
87     wrefresh(new_win);
88     return new_win;
89 }