From: Daniel Liu Date: Wed, 20 Jan 2021 05:26:07 +0000 (-0500) Subject: some init stuff X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=b9f6674ee02c6eb557f2b4a1032774729aa67af0;p=taskasaur.git some init stuff --- diff --git a/headers/parser.h b/headers/parser.h index 950e560..4542eed 100644 --- a/headers/parser.h +++ b/headers/parser.h @@ -37,3 +37,5 @@ typedef struct Board { extern Board* begin_parse(char* board_path); +extern void log_todo(Board* board); + diff --git a/headers/render.h b/headers/render.h new file mode 100644 index 0000000..3a5501f --- /dev/null +++ b/headers/render.h @@ -0,0 +1,12 @@ + +#include + +enum TaskasaurColors { + TS_SELECTED, + TS_NONSELECTED +}; + +/* the ts is used to not conflict with builtin names */ +extern int init_tscurses(void); +extern int exit_tscurses(void); + diff --git a/makefile b/makefile index 6717864..7e2ffd7 100644 --- a/makefile +++ b/makefile @@ -5,7 +5,10 @@ make: taskasaur parser.o: parser.c headers/parser.h $(CC) -c parser.c -taskasaur: taskasaur.c parser.o +render.o: render.c headers/render.h + $(CC) -c render.c + +taskasaur: taskasaur.c parser.o render.o $(CC) -o $@ $^ -lncurses -lmenu -lmd4c clean: diff --git a/parser.c b/parser.c index a005331..9b129d4 100644 --- a/parser.c +++ b/parser.c @@ -43,6 +43,66 @@ const MD_PARSER parser = { &syntax }; + +void +log_todo(Board* board) +{ + for (int i = 0; i < board->todolist_count; i++) { + TodoList* todolist; + printf("List =-=-=-=-=-==-=-=-=-=-=-\n"); + todolist = board->todolist_list[i]; + printf("List name: %s\n", todolist->list_name); + printf("Num of items: %d\n", todolist->item_count); + + for (int j = 0; j < todolist->item_count; j++) { + TodoItem* todoitem; + printf("Item =-=-=-=-=-\n"); + todoitem = todolist->item_list[j]; + printf("Item name: %s\n", todoitem->item_name); + printf("Description: %s\n", todoitem->description); + printf("Num of subtasks: %d\n", todoitem->subtask_count); + + for (int k = 0; k < todoitem->subtask_count; k++) { + SubTask* subtask; + int done; + + subtask = todoitem->subtask_list[k]; + printf("Subtask: %s, %d\n", subtask->subtask_name, subtask->done); + } + } + } +} + +Board* +begin_parse(char* board_path) +{ + const char* input_buffer; + long input_size; + State state; + Board* new_board; + + /* read entire file */ + input_buffer = read_file(board_path, &input_size); + + /* setup state */ + state.cur_todolist = NULL; + state.cur_todoitem = NULL; + + new_board = malloc(sizeof(Board)); + new_board->todolist_list = malloc(0); + new_board->todolist_count = 0; + state.board = new_board; + + md_parse(input_buffer, input_size, &parser, &state); + + /* finish calls */ + exit_todolist(&state); + + free((char*)input_buffer); + + return state.board; +} + char* read_file(char* file_name, long* size) { // apparently using seek isnt the greatest, may change to chunk reading later @@ -78,36 +138,6 @@ read_file(char* file_name, long* size) return output; } -Board* -begin_parse(char* board_path) -{ - const char* input_buffer; - long input_size; - State state; - Board* new_board; - - /* read entire file */ - input_buffer = read_file(board_path, &input_size); - - /* setup state */ - state.cur_todolist = NULL; - state.cur_todoitem = NULL; - - new_board = malloc(sizeof(Board)); - new_board->todolist_list = malloc(0); - new_board->todolist_count = 0; - state.board = new_board; - - md_parse(input_buffer, input_size, &parser, &state); - - /* finish calls */ - exit_todolist(&state); - - free((char*)input_buffer); - - return state.board; -} - void enter_todolist(State* state, char* list_name) { diff --git a/render.c b/render.c new file mode 100644 index 0000000..de22b1d --- /dev/null +++ b/render.c @@ -0,0 +1,60 @@ + +#include "headers/render.h" +#include "config.h" + +int init_tscolors(void); + +int create_todowin(void); + +/* init stuff */ +int +init_tscurses(void) +{ + initscr(); + cbreak(); + noecho(); + curs_set(0); + keypad(stdscr, TRUE); + + /* need to error check this */ + if (has_colors() == FALSE) { + fprintf(stderr, "Your terminal does not support color.\n"); + + /* maybe just return 1 */ + /* exit_tscurses(); */ + /* exit(1); */ + return 1; + } + start_color(); + init_tscolors(); + + return 0; +} + +int +exit_tscurses(void) +{ + endwin(); + + return 0; +} + +int +init_tscolors(void) +{ + init_pair(TS_SELECTED, selected_color, COLOR_BLACK); + init_pair(TS_NONSELECTED, non_selected_color, COLOR_BLACK); + + return 0; +} + +/* wins */ +int +create_todowin(void) +{ + + + + return 0; +} + diff --git a/taskasaur.c b/taskasaur.c index 50b72d4..8925d04 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -1,39 +1,21 @@ + #include "headers/parser.h" +#include "headers/render.h" int main(int argc, char** argv) { - Board* board; - - board = begin_parse("test_board.md"); - - for (int i = 0; i < board->todolist_count; i++) { - TodoList* todolist; - printf("List =-=-=-=-=-==-=-=-=-=-=-\n"); - todolist = board->todolist_list[i]; - printf("List name: %s\n", todolist->list_name); - printf("Num of items: %d\n", todolist->item_count); + /* Board* board; */ + /* board = begin_parse("test_board.md"); */ + /* log_todo(board); */ - for (int j = 0; j < todolist->item_count; j++) { - TodoItem* todoitem; - printf("Item =-=-=-=-=-\n"); - todoitem = todolist->item_list[j]; - printf("Item name: %s\n", todoitem->item_name); - printf("Description: %s\n", todoitem->description); - printf("Num of subtasks: %d\n", todoitem->subtask_count); + /* init curses */ + init_tscurses(); - for (int k = 0; k < todoitem->subtask_count; k++) { - SubTask* subtask; - int done; + getch(); - subtask = todoitem->subtask_list[k]; - printf("Subtask: %s, %d\n", subtask->subtask_name, subtask->done); - } - } - - } - /* printf("%d\n", board->todolist_count); */ - /* printf("%s\n", board->todolist_list[1]->list_name); */ + exit_tscurses(); return 0; } +