2 #include "headers/parser.h"
3 #include "headers/render.h"
4 #include "headers/menu.h"
5 #include "headers/utils.h"
8 void render_step(BoardMenu* boardmenu);
9 void save_to_file(char* filepath, BoardMenu* boardmenu);
12 main(int argc, char** argv)
14 char* boardfile_name = "test_board.md";
15 printf("%c]0;%s - %s%c", '\033', "taskasaur", boardfile_name, '\007'); // need to reset after program exits
17 /* read from todo file */
19 board = begin_parse(boardfile_name);
20 /* log_todo(board); */
26 boardmenu = create_board_menu(board);
28 /* need to render before user presses anything */
29 render_step(boardmenu);
32 while ((ch = getch()) != BINDING_QUIT) {
35 active_menu = boardmenu->menu_list[boardmenu->selected];
39 case BINDING_SCROLL_UP:
40 menu_driver(active_menu, MENU_UP);
42 case BINDING_SCROLL_DOWN:
43 menu_driver(active_menu, MENU_DOWN);
45 case BINDING_SCROLL_LEFT:
46 if (boardmenu->selected-1 < 0) break;
47 set_selected_menu(boardmenu, boardmenu->selected-1);
49 case BINDING_SCROLL_RIGHT:
50 if (boardmenu->selected+1 > boardmenu->menu_count-1) break;
51 set_selected_menu(boardmenu, boardmenu->selected+1);
53 case BINDING_JUMP_TOP:
54 menu_driver(active_menu, MENU_TOP);
56 case BINDING_JUMP_BOTTOM:
57 menu_driver(active_menu, MENU_BOTTOM);
59 case BINDING_MOVE_ITEM_UP:
60 menu_driver(active_menu, MENU_MOVE_UP);
62 case BINDING_MOVE_ITEM_DOWN:
63 menu_driver(active_menu, MENU_MOVE_DOWN);
65 case BINDING_MOVE_ITEM_LEFT:
66 if (boardmenu->selected-1 < 0) break;
67 if (get_menu_length(boardmenu->menu_list[boardmenu->selected]) == 0) break;
72 from_menu = boardmenu->menu_list[boardmenu->selected];
73 to_menu = boardmenu->menu_list[boardmenu->selected-1];
79 get_selected_item(from_menu)
82 get_selected_item(from_menu),
83 get_menu_length(to_menu)
88 get_selected_item(from_menu)
90 set_selected_menu(boardmenu, boardmenu->selected-1);
94 case BINDING_MOVE_ITEM_RIGHT:
95 if (boardmenu->selected >= boardmenu->menu_count-1) break;
96 if (get_menu_length(boardmenu->menu_list[boardmenu->selected]) == 0) break;
97 // this is legit cpy paste please fix this
102 from_menu = boardmenu->menu_list[boardmenu->selected];
103 to_menu = boardmenu->menu_list[boardmenu->selected+1];
109 get_selected_item(from_menu)
112 get_selected_item(from_menu),
113 get_menu_length(to_menu)
118 get_selected_item(from_menu)
120 set_selected_menu(boardmenu, boardmenu->selected+1);
124 case BINDING_DELETE_ITEM:
125 menu_driver(active_menu, MENU_DELETE);
127 case BINDING_APPEND_ITEM:
128 menu_driver(active_menu, MENU_APPEND);
130 case BINDING_INSERT_ABOVE:
131 menu_driver(active_menu, MENU_INSERT_ABOVE);
133 case BINDING_INSERT_BELOW:
134 menu_driver(active_menu, MENU_INSERT_BELOW);
136 /* case BINDING_MOVE_MENU_LEFT: */
137 /* if (boardmenu->selected-1 < 0) break; */
139 /* swap_menu(boardmenu, boardmenu->selected, boardmenu->selected-1); */
140 /* boardmenu->selected -= 1; */
141 /* set_selected_menu(boardmenu, boardmenu->selected); */
144 /* case BINDING_MOVE_MENU_RIGHT: */
145 /* if (boardmenu->selected >= boardmenu->menu_count-1) break; */
146 /* swap_menu(boardmenu, boardmenu->selected, boardmenu->selected+1); */
147 /* boardmenu->selected += 1; */
148 /* set_selected_menu(boardmenu, boardmenu->selected); */
151 case BINDING_EDIT_ITEM:
152 menu_driver(active_menu, MENU_EDIT);
157 save_to_file(boardfile_name, boardmenu);
163 /* getmaxyx(stdscr, y, x); */
164 /* sprintf(out, "%d,%d", y, x); */
166 /* mvprintw(20, 20, out); */
167 /* resize_term(y, x); */
171 render_step(boardmenu);
175 /* save on exit - this causes weird stuff to happen, maybe it's not given enough time to write before program exits? */
176 /* save_to_file(boardfile_name, boardmenu); */
183 render_step(BoardMenu* boardmenu)
185 for (int i = 0; i < boardmenu->menu_count; i++) {
187 Menu* curmenu = boardmenu->menu_list[i];
189 /* update the descriptions - maybe not do this here */
190 for (int j = 0; j < get_menu_length(curmenu); j++) {
191 update_menuitem_descrip(get_menu_item(curmenu, j));
194 render_menu(curmenu);
199 save_to_file(char* filepath, BoardMenu* boardmenu)
202 writeboard = boardmenu_to_board(boardmenu);
204 begin_write(filepath, writeboard);
205 free_board(writeboard);