X-Git-Url: https://git.danieliu.xyz/?p=taskasaur.git;a=blobdiff_plain;f=taskasaur.c;h=647c8489d6791d5ed406c82ea502cebf262d841c;hp=119411e5e790a3e4c715f5f6da7c12970a583a2b;hb=7cd288f609ab7d99e5fb5b8da07d2c1b6f32907d;hpb=f270512184ab1c41eee46c76a149b7cbddb1b131 diff --git a/taskasaur.c b/taskasaur.c index 119411e..647c848 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -1,201 +1,39 @@ -#include -#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_win(int height, int width, int y, int x); -MENU* create_todo_menu(WINDOW* win, char** todo_list, int todo_length); - -void free_todo(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 ch; - - WINDOW* todo_win; - MENU* todo_menu; - - 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; - - case 'n': + /* Board* board; */ + /* board = begin_parse("test_board.md"); */ + /* log_todo(board); */ - // 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); + /* init curses */ + init_tscurses(); - todos = malloc(0); - todo_length = 0; - break; - - case -1: - case '?': - printf("Help string\n"); - return 2; - } - - /* for (int i = 0; i < todo_length; i++) { */ - /* printf("%p\n", todos[i]); */ - /* printf(todos[i]); */ - /* } */ - /* return 0; */ - - // start ncurses - initscr(); - cbreak(); - noecho(); - curs_set(0); - start_color(); - - getmaxyx(stdscr, height, width); - - todo_win = create_win(20, 40, 5, 5); - - todo_menu = create_todo_menu(todo_win, todos, todo_length); - post_menu(todo_menu); - wrefresh(todo_win); - - while ((ch = getch()) != 'q') { - - switch (ch) { - case 'j': - menu_driver(todo_menu, REQ_DOWN_ITEM); - break; - case 'k': - menu_driver(todo_menu, REQ_UP_ITEM); - break; - case 'G': // try to implement gg too - menu_driver(todo_menu, REQ_LAST_ITEM); - break; - } - - wrefresh(todo_win); + 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."); } - endwin(); - - /* Free mem */ - unpost(todo_menu); - free_todo(todos, todo_length); + Menu* menu = create_menu(item_list); - 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; + render_menu(menu); - while ((nread = getline(&lineptr, &len, file)) != -1) { - out_len++; - out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing? + getch(); - lineptr[strcspn(lineptr, "\n")] = 0; // remove newline - out_arr[out_len-1] = lineptr; + exit_tscurses(); - lineptr = NULL; - } + /* 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_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; } -MENU* -create_todo_menu(WINDOW* win, char** todo_list, int todo_length) -{ - MENU* todo_menu; - ITEM** item_list; - ITEM* cur_item; - int wheight, wwidth; - - item_list = malloc((todo_length+1)*sizeof(ITEM*)); - for (int i = 0; i < todo_length; i++) { - item_list[i] = new_item(todo_list[i], ""); - } - item_list[todo_length] = NULL; // last item needs to be a null pointer for some reason? - - todo_menu = new_menu(item_list); - - getmaxyx(stdscr, wheight, wwidth); - set_menu_win(todo_menu, win); - set_menu_sub(todo_menu, derwin(win, wheight, wwidth, 0, 0)); - - box(win, 0, 0); //temp - - return todo_menu; -} - -void -free_todo(char** todo_list, int todo_length) -{ - // probably check if list is too short or too long - for (int i = 0; i < todo_length; i++) { - free(todo_list[i]); - } - free(todo_list); -}