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