From: Daniel Liu Date: Wed, 3 Feb 2021 05:12:42 +0000 (-0500) Subject: hook up read from file X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=99cc6e19069115197e8101c1ed585fe0ae5de405;p=taskasaur.git hook up read from file --- diff --git a/headers/menu.h b/headers/menu.h index 7db3c07..9de9cb4 100644 --- a/headers/menu.h +++ b/headers/menu.h @@ -22,7 +22,7 @@ typedef struct MenuItem MenuItem; extern MenuItem* create_menuitem(char* contents); -extern Menu* create_menu(MenuItem** item_list); +extern Menu* create_menu(char* menu_name, MenuItem** item_list); extern int set_menu_win(Menu* menu, WINDOW* win); extern MenuItem* get_menu_items(Menu* menu); extern int set_menu_focus(Menu* menu, bool focus); diff --git a/menu.c b/menu.c index 5c79587..d47c553 100644 --- a/menu.c +++ b/menu.c @@ -19,6 +19,7 @@ typedef struct MenuItem { } MenuItem; typedef struct Menu { + char* menu_name; MenuItem** menu_items; int menu_length; int selected_item; @@ -45,11 +46,12 @@ create_menuitem(char* contents) } Menu* -create_menu(MenuItem** item_list) +create_menu(char* menu_name, MenuItem** item_list) { Menu* new_menu; new_menu = malloc(sizeof(Menu)); + new_menu->menu_name = menu_name; new_menu->menu_items = item_list; new_menu->menu_length = array_length(MenuItem*, item_list); new_menu->selected_item = 0; @@ -189,7 +191,7 @@ render_menu(Menu* menu) (menu->focused == true) ? TS_MENU_SELECTED: TS_MENU_NONSELECTED )); - mvwprintw(menu->menu_win, 0, MENU_PAD_LEFT, "TODO"); + mvwprintw(menu->menu_win, 0, MENU_PAD_LEFT, menu->menu_name); wattroff(menu->menu_win, COLOR_PAIR(0)); /* draw inner menu */ diff --git a/taskasaur.c b/taskasaur.c index d8aa46d..22e2f2a 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -5,25 +5,23 @@ #include "headers/utils.h" #include "config.h" +MenuItem** todolist_to_menuitem(TodoItem** item_list, int list_length); + int main(int argc, char** argv) { - char ch; - /* Board* board; */ - /* board = begin_parse("test_board.md"); */ - /* log_todo(board); */ + + /* read from todo file */ + Board* board; + board = begin_parse("test_board.md"); + log_todo(board); /* init curses */ init_tscurses(); - MenuItem** item_list = malloc(5*sizeof(MenuItem*)); - item_list[0] = create_menuitem("Many of you are probably feeling a little sad."); - item_list[1] = create_menuitem("This is ok. Sadness is a normal human emotion."); - item_list[2] = create_menuitem("I encourage you to watch the movie Inside Out"); - item_list[3] = create_menuitem("one of the best movies of all time."); - item_list[4] = 0; - - Menu* menu = create_menu(item_list); + TodoList* todo_list = board->todolist_list[0]; + MenuItem** item_list = todolist_to_menuitem(todo_list->item_list, todo_list->item_count); + Menu* menu = create_menu(todo_list->list_name, item_list); WINDOW* win = newwin(20, 40, 5, 5); set_menu_win(menu, win); set_menu_focus(menu, true); @@ -33,6 +31,7 @@ main(int argc, char** argv) render_menu(menu); + char ch; while ((ch = getch()) != BINDING_QUIT) { switch (ch) { @@ -69,3 +68,19 @@ main(int argc, char** argv) return 0; } +MenuItem** +todolist_to_menuitem(TodoItem** item_list, int list_length) +{ + MenuItem** items; + + items = malloc((list_length+1)*sizeof(MenuItem*)); + for (int i = 0; i < list_length; i++) { + items[i] = create_menuitem(item_list[i]->item_name); + } + + items[list_length] = 0; //null terminate + return items; +} + + +