X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;ds=sidebyside;f=main.c;h=6295b35d9bc722ffbdb48bcd6a6c73ce8c249f5b;hb=6afa85b8f5d9a77abaab11d47d7b8ab93f40d95d;hp=e4ef06bdd1e2ab5aa49e677adf32ca7d292cab25;hpb=12a770aa60e7d8647187edcd38fa7d3e876558c7;p=taskasaur.git diff --git a/main.c b/main.c index e4ef06b..6295b35 100644 --- a/main.c +++ b/main.c @@ -3,7 +3,59 @@ #include #include -int main(int argc, char** argv) { +void winch_handler(int sig); + +WINDOW* create_list_win(int height, int width, int y, int x); + +#include "config.h" + +int +main(int argc, char** argv) +{ + int flag; + FILE* board_file; + int height, width; + int x, y; + int ch; + WINDOW* todo_win; + + signal(SIGWINCH, winch_handler); + + // read command line args + flag = getopt(argc, argv, "o:n::"); + switch (flag) { + case 'o': + + // read from task file (might need to check for read and write permissions) + board_file = fopen(optarg, "r"); + if (!board_file) { + printf("%s does not exist\n", optarg); + return 1; + } + break; + + case 'n': + /* ; */ + /* char to_create[]; */ + /* to_create = (optarg == 0) ? default_board : optarg; */ + + // make sure file does not exist + // however, it maybe be possible that an different error has occured (besides the file not existing) + if (access(optarg, F_OK) == 0) { + printf("%s already exists\n", optarg); + return 1; + } + /* printf("Successfully created %s\n", to_create); */ + break; + + case -1: + case '?': + printf("Help string\n"); + return 2; + + } + + return 0; // start ncurses initscr(); @@ -15,21 +67,16 @@ int main(int argc, char** argv) { init_pair(1, COLOR_CYAN, COLOR_BLACK); init_pair(2, COLOR_BLACK, COLOR_CYAN); - int height, width; getmaxyx(stdscr, height, width); - - WINDOW * win = newwin(10,20,5,10); - WINDOW * todo_win = newwin(20,20,5,35); - WINDOW * bottombar = newwin(1,width,height-1,0); - refresh(); - - int x, y; x = y = 0; + refresh(); - while (true) { - int ch = getch(); + todo_win = create_list_win(20, 20, 5, 5); + + move(y,x); + while ((ch = getch()) != 113) { // while not q - //ofc the first thing we need is vim keys + // ofc the first thing we need is vim keys switch (ch) { case 104: // h x -= 1; @@ -44,22 +91,6 @@ int main(int argc, char** argv) { x += 1; break; } - if (ch == 113) break; // q for quit - - box(win, 0, 0); - wattron(win,COLOR_PAIR(1)); - wattron(win, A_BOLD); - mvwprintw(win, 0, 1, "lmao"); - wattroff(win, A_BOLD); - wattroff(win,COLOR_PAIR(1)); - mvwprintw(win, 1, 2, "poopoopeepee"); - wrefresh(win); - - wrefresh(todo_win); - - wbkgd(bottombar, COLOR_PAIR(2)); - mvwprintw(bottombar, 0, 2, "BOTTOM TEXT"); - wrefresh(bottombar); move(y,x); refresh(); @@ -69,3 +100,19 @@ int main(int argc, char** argv) { endwin(); return 0; } + +void +winch_handler(int sig) +{ + endwin(); + refresh(); +} + +WINDOW* +create_list_win(int height, int width, int y, int x) +{ + WINDOW* new_win = newwin(height, width, y, x); + box(new_win, 0, 0); + wrefresh(new_win); + return new_win; +}