X-Git-Url: https://git.danieliu.xyz/?p=taskasaur.git;a=blobdiff_plain;f=taskasaur.c;h=647c8489d6791d5ed406c82ea502cebf262d841c;hp=39eaca6e9ba669a8c1b76bb14fbd06fbd040d389;hb=7cd288f609ab7d99e5fb5b8da07d2c1b6f32907d;hpb=103d9d622254eb6257565bd08da27376c12510fd diff --git a/taskasaur.c b/taskasaur.c index 39eaca6..647c848 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -1,174 +1,39 @@ -#include -#include -#include -#include -#include -#include -void winch_handler(int sig); +#include "headers/parser.h" +#include "headers/render.h" +#include "headers/menu.h" +#include "headers/utils.h" -char** read_todo(FILE* file, int* length); - -WINDOW* create_list_win(int height, int width, int y, int x); - -void draw_todo(WINDOW* todo_win, char** todo_list, int todo_length); - -#include "config.h" - -int -main(int argc, char** argv) +int +main(int argc, char** argv) { - int flag; - FILE* board_file; - char** todos; - int todo_length; - 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; - } - - todos = read_todo(board_file, &todo_length); - fclose(board_file); - - break; + /* Board* board; */ + /* board = begin_parse("test_board.md"); */ + /* log_todo(board); */ - case 'n': + /* init curses */ + init_tscurses(); - // 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; - } - // create a file here - board_file = fopen(optarg, "w"); - // write init stuff here - fclose(board_file); - printf("Successfully created %s\n", optarg); - todos = malloc(0); - todo_length = 0; - - break; - - case -1: - case '?': - printf("Help string\n"); - return 2; + MenuItem** item_list = malloc(4*sizeof(MenuItem*)); + for (int i = 0; i < 3; i++) { + item_list[i] = create_menuitem("Many of you are probably feeling a little sad."); } + Menu* menu = create_menu(item_list); - // start ncurses - initscr(); - cbreak(); - /* raw(); */ - noecho(); - curs_set(0); - start_color(); - - init_pair(1, COLOR_CYAN, COLOR_BLACK); - init_pair(2, COLOR_BLACK, COLOR_CYAN); - - getmaxyx(stdscr, height, width); - x = y = 0; - refresh(); + render_menu(menu); - todo_win = create_list_win(20, 40, 5, 5); - draw_todo(todo_win, todos, todo_length); - - move(y,x); - while ((ch = getch()) != 113) { // while not q - - // ofc the first thing we need is vim keys - switch (ch) { - case 104: // h - x -= 1; - break; - case 106: // j - y += 1; - break; - case 107: // k - y -= 1; - break; - case 108: // l - x += 1; - break; - } - - move(y,x); - refresh(); - /* clear(); */ - } + getch(); - endwin(); + exit_tscurses(); - /* Free mem */ - free(todos); // prob need to free each string in list too - - return 0; -} - -void -winch_handler(int sig) -{ - endwin(); - refresh(); -} - -char** -read_todo(FILE* file, int* length) -{ // apparently getline isn't rly that portable, so consider other options - char** out_arr; - int out_len; - char* lineptr; - size_t len; - ssize_t nread; - - out_arr = NULL; - out_len = 0; - lineptr = NULL; - len = 0; - - while ((nread = getline(&lineptr, &len, file)) != -1) { - out_len++; - out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing? - out_arr[out_len-1] = lineptr; - - lineptr = NULL; - len = 0; - } + /* int out; */ + /* printf("%s", wrap_text("ayylmaooooxdxdxdxdxd", 3, &out)); */ + /* printf("%d\n", out); */ + /* wrap_text("ayylmaooooxdxdxdxdxd", 3, &out); */ - *length = out_len; - return out_arr; -} -WINDOW* -create_list_win(int height, int width, int y, int x) -{ - WINDOW* new_win = newwin(height, width, y, x); - wrefresh(new_win); - return new_win; + return 0; } -void -draw_todo(WINDOW* todo_win, char** todo_list, int todo_length) { - for (int i = 0; i < todo_length; i++) { - mvwprintw(todo_win, i+1, 2, todo_list[i]); - } - box(todo_win, 0, 0); - wrefresh(todo_win); -}