From: Daniel Liu Date: Sun, 14 Feb 2021 21:53:11 +0000 (-0500) Subject: work on writing X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;ds=inline;h=a38733c9e166c01710e1732cd6f6354313eb35ea;p=taskasaur.git work on writing --- diff --git a/config.h b/config.h index ad8648d..bffbcea 100644 --- a/config.h +++ b/config.h @@ -37,12 +37,13 @@ static int menu_non_selected_color = COLOR_GREEN; #define BINDING_MOVE_ITEM_LEFT 'H' #define BINDING_MOVE_ITEM_RIGHT 'L' #define BINDING_DELETE_ITEM 'D' -#define BINDING_SELECT '\n' #define BINDING_APPEND_ITEM 'a' #define BINDING_INSERT_ABOVE 'O' #define BINDING_INSERT_BELOW 'o' #define BINDING_MOVE_MENU_LEFT '<' #define BINDING_MOVE_MENU_RIGHT '>' #define BINDING_EDIT_ITEM 'i' +#define BINDING_SELECT '\n' +#define BINDING_WRITE 'w' #endif diff --git a/headers/menu.h b/headers/menu.h index b49e5b0..d1dc51e 100644 --- a/headers/menu.h +++ b/headers/menu.h @@ -36,6 +36,7 @@ extern int set_menu_focus(Menu* menu, bool focus); extern int get_selected_item(Menu* menu); extern int set_selected_item(Menu* menu, int selected_item); extern int get_menu_length(Menu* menu); +extern char* get_menu_name(Menu* menu); extern int insert_item(Menu* menu, MenuItem* menuitem, int index); extern int delete_item(Menu* menu, int index); diff --git a/headers/parser.h b/headers/parser.h index 41520b7..4506364 100644 --- a/headers/parser.h +++ b/headers/parser.h @@ -39,6 +39,7 @@ typedef struct Board { } Board; extern Board* begin_parse(char* board_path); +extern int begin_write(Board* Board); extern void log_todo(Board* board); diff --git a/menu.c b/menu.c index ffb49a6..3067b16 100644 --- a/menu.c +++ b/menu.c @@ -18,6 +18,7 @@ typedef struct MenuItem { char* contents; + char* description; } MenuItem; typedef struct Menu { @@ -146,6 +147,12 @@ get_menu_length(Menu* menu) return menu->menu_length; } +char* +get_menu_name(Menu* menu) +{ + return menu->menu_name; +} + int swap_item(Menu* menu, int src_index, int dest_index) { @@ -330,6 +337,9 @@ render_menu(Menu* menu) cur_line += wrapped_lines; + /* display number of items */ + /* if (menu->menu_items[i]->) */ + free(wrapped_text); } diff --git a/taskasaur.c b/taskasaur.c index 8732678..a679bfb 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -15,6 +15,7 @@ typedef struct BoardMenu { } BoardMenu; BoardMenu* create_board_menu(Board* board); +Board* boardmenu_to_board(BoardMenu* boardmenu); int set_selected_menu(BoardMenu* boardmenu, int index); MenuItem** todolist_to_menuitem(TodoItem** item_list, int list_length); @@ -24,9 +25,12 @@ int swap_menu(BoardMenu* boardmenu, int src_index, int dest_index); int main(int argc, char** argv) { + char* boardfile_name = "test_board.md"; + printf("%c]0;%s - %s%c", '\033', "taskasaur", boardfile_name, '\007'); // need to reset after program exits + /* read from todo file */ Board* board; - board = begin_parse("test_board.md"); + board = begin_parse(boardfile_name); /* log_todo(board); */ /* init curses */ @@ -150,17 +154,22 @@ main(int argc, char** argv) /* boardmenu->selected -= 1; */ /* set_selected_menu(boardmenu, boardmenu->selected); */ -/* break; */ -/* case BINDING_MOVE_MENU_RIGHT: */ -/* if (boardmenu->selected >= boardmenu->menu_count-1) break; */ -/* swap_menu(boardmenu, boardmenu->selected, boardmenu->selected+1); */ + /* break; */ + /* case BINDING_MOVE_MENU_RIGHT: */ + /* if (boardmenu->selected >= boardmenu->menu_count-1) break; */ + /* swap_menu(boardmenu, boardmenu->selected, boardmenu->selected+1); */ /* boardmenu->selected += 1; */ /* set_selected_menu(boardmenu, boardmenu->selected); */ - break; + /* break; */ case BINDING_EDIT_ITEM: menu_driver(active_menu, MENU_EDIT); break; + case BINDING_SELECT: + + break; + case BINDING_WRITE: + break; } for (int i = 0; i < boardmenu->menu_count; i++) { @@ -188,6 +197,35 @@ create_board_menu(Board* board) return new_boardmenu; } +Board* +boardmenu_to_board(BoardMenu* boardmenu) +{ + Board newboard = malloc(sizeof(Board)); + TodoList** todolist_list = malloc(sizeof(TodoList*)); + + for (int i = 0; i < boardmenu->menu_count; i++) { + Menu* curmenu = boardmenu->menu_list[i]; + + TodoList* new_todolist = malloc(sizeof(TodoList)); + TodoItem** item_list = malloc(sizeof(TodoItem*)); + new_todolist->list_name = get_menu_name(curmenu); + new_todolist->item_count = get_menu_length(curmenu); + + /* for (int j = 0; j < get_menu_length(curmenu); j++) { */ + + /* } */ + + new_todolist->item_list = item_list; + + } + + newboard->todolist_list = todolist_list; + newboard->todolist_count = boardmenu->menu_count; + + return newboard; + +} + int set_selected_menu(BoardMenu* boardmenu, int index) { @@ -269,6 +307,7 @@ swap_menu(BoardMenu* boardmenu, int src_index, int dest_index) mvwin(get_menu_win(boardmenu->menu_list[dest_index]), 1, 1+MENU_WIDTH*src_index ); + refresh(); wrefresh(get_menu_win(boardmenu->menu_list[src_index])); wrefresh(get_menu_win(boardmenu->menu_list[dest_index])); /* wclear(get_menu_win(boardmenu->menu_list[src_index])); */