working on command line args
[taskasaur.git] / main.cpp
1 #include <iostream>
2 #include <fstream>
3 #include <unistd.h>
4 #include <string>
5 #include <ncurses.h>
6 using namespace std;
7
8 bool file_exists(const char* file_name) {
9     ifstream test_file(file_name);
10     return (bool)test_file;
11 }
12
13 int main(int argc, char** argv) {
14     
15     // read command line args
16     if (argc < 2) {
17         cout << "Taskasaur options\n-o [board_name]\n-n [new_board+name]";
18         return 1;
19     }
20    
21     int flag; 
22     while ((flag = getopt(argc, argv, "o:n:")) != -1) {
23         if (flag == 'o') {
24
25             char* file_name = optarg;
26             printf("Opening %s\n", file_name);
27
28             // check if file exists
29             if (!file_exists(file_name)) {
30                 printf("%s does not exist.\n", file_name);
31                 return 1;
32             }
33
34         } else if (flag == 'n') {
35
36             char* new_file_name = optarg;
37             printf("Creating %s\n", new_file_name);
38
39             if (file_exists(new_file_name)) {
40                 printf("The board %s already exist.\n", new_file_name);
41                 return 1;
42             }
43
44             ofstream new_file;
45             new_file.open(new_file_name);
46             new_file << "# Taskasaur\n";
47             new_file.close();
48
49         }
50     }   
51     return 0;
52
53    
54     // start ncurses 
55     initscr();
56     cbreak();
57     /* raw(); */
58     noecho();
59     start_color();
60     
61     init_pair(1, COLOR_CYAN, COLOR_BLACK); 
62     init_pair(2, COLOR_BLACK, COLOR_CYAN); 
63
64     int height, width;
65     getmaxyx(stdscr, height, width);
66
67     WINDOW * win = newwin(10,20,5,10); 
68     WINDOW * todo_win = newwin(20,20,5,35);
69     WINDOW * bottombar = newwin(1,width,height-1,0); 
70     refresh();
71     
72     int x, y;
73     x = y = 0;
74
75     string todo_list[3] = {"Contemplate life", "Question life", "Ponder about life"};
76
77     while (true) {
78         int ch = getch();
79         
80         //ofc the first thing we need is vim keys 
81         switch (ch) {
82             case 104: // h
83                 x -= 1;
84                 break;
85             case 106: // j
86                 y += 1;
87                 break;
88             case 107: // k
89                 y -= 1;
90                 break;
91             case 108: // l
92                 x += 1;
93                 break;
94         } 
95         if (ch == 113) break; // q for quit
96
97         box(win, 0, 0);
98         wattron(win,COLOR_PAIR(1));
99         wattron(win, A_BOLD);
100         mvwprintw(win, 0, 1, "lmao");
101         wattroff(win, A_BOLD);
102         wattroff(win,COLOR_PAIR(1));
103         mvwprintw(win, 1, 2, "poopoopeepee");
104         wrefresh(win);
105
106         for (int i = 0; i < sizeof(todo_list)/sizeof(string); i++) {
107             mvwprintw(todo_win, 2*i, 0, todo_list[i].c_str());
108         }
109         wrefresh(todo_win);
110
111         wbkgd(bottombar, COLOR_PAIR(2));        
112         mvwprintw(bottombar, 0, 2, "BOTTOM TEXT");
113         wrefresh(bottombar);
114
115         move(y,x);
116         refresh();
117         /* clear(); */
118     }
119
120     endwin();
121
122     return 0;
123 }
124
125