command line args
[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     int flag;
16     FILE* board_file;
17     int height, width;
18     int x, y;
19     int ch;
20     WINDOW* todo_win;
21
22     signal(SIGWINCH, winch_handler);
23
24     // read command line args
25     flag = getopt(argc, argv, "o:n::");
26     switch (flag) {
27         case 'o':
28
29             // read from task file (might need to check for read and write permissions)
30             board_file = fopen(optarg, "r");
31             if (!board_file) {
32                 printf("%s does not exist\n", optarg);
33                 return 1;
34             }   
35             break;
36
37         case 'n':
38             /* ; */
39             /* char to_create[]; */
40             /* to_create = (optarg == 0) ? default_board : optarg; */
41
42             // make sure file does not exist
43             // however, it maybe be possible that an different error has occured (besides the file not existing)
44             if (access(optarg, F_OK) == 0) { 
45                 printf("%s already exists\n", optarg);
46                 return 1;
47             }
48             /* printf("Successfully created %s\n", to_create); */
49             break;
50
51         case -1:
52         case '?':
53             printf("Help string\n");
54             return 2;
55
56     }
57
58     return 0;
59
60     // start ncurses 
61     initscr();
62     cbreak();
63     /* raw(); */
64     noecho();
65     start_color();
66     
67     init_pair(1, COLOR_CYAN, COLOR_BLACK); 
68     init_pair(2, COLOR_BLACK, COLOR_CYAN); 
69
70     getmaxyx(stdscr, height, width);
71     x = y = 0;
72     refresh();
73
74     todo_win = create_list_win(20, 20, 5, 5);
75     
76     move(y,x);
77     while ((ch = getch()) != 113) { // while not q
78         
79         // ofc the first thing we need is vim keys 
80         switch (ch) {
81             case 104: // h
82                 x -= 1;
83                 break;
84             case 106: // j
85                 y += 1;
86                 break;
87             case 107: // k
88                 y -= 1;
89                 break;
90             case 108: // l
91                 x += 1;
92                 break;
93         } 
94
95         move(y,x);
96         refresh();
97         /* clear(); */
98     }
99
100     endwin();
101     return 0;
102 }
103
104 void 
105 winch_handler(int sig) 
106 {
107     endwin();
108     refresh();
109 }
110
111 WINDOW* 
112 create_list_win(int height, int width, int y, int x)
113 {
114     WINDOW* new_win = newwin(height, width, y, x);
115     box(new_win, 0, 0);
116     wrefresh(new_win);
117     return new_win;
118 }