2 #include "headers/parser.h"
3 #include "headers/render.h"
4 #include "headers/menu.h"
5 #include "headers/utils.h"
8 char* boardfile_name = "test_board.md";
10 void normal_handleinput(BoardMenu* boardmenu, int ch);
11 void popup_handleinput(BoardMenu* boardmenu, int ch);
12 void generic_handleinput(Menu* menu, int ch);
14 void normal_renderstep(BoardMenu* boardmenu);
15 void popup_renderstep(BoardMenu* boardmenu);
16 void save_to_file(char* filepath, BoardMenu* boardmenu);
18 void exit_step(BoardMenu* boardmenu);
21 main(int argc, char** argv)
23 printf("%c]0;%s - %s%c", '\033', "taskasaur", boardfile_name, '\007'); // need to reset after program exits
25 /* read from todo file */
27 board = begin_parse(boardfile_name);
28 /* log_todo(board); */
34 boardmenu = create_board_menu(board);
36 /* need to render before user presses anything */
37 normal_renderstep(boardmenu);
44 if (boardmenu->popup_open == 0) {
45 normal_handleinput(boardmenu, ch);
46 normal_renderstep(boardmenu);
48 popup_handleinput(boardmenu, ch);
49 popup_renderstep(boardmenu);
54 /* save on exit - this causes weird stuff to happen, maybe it's not given enough time to write before program exits? */
55 /* save_to_file(boardfile_name, boardmenu); */
61 normal_handleinput(BoardMenu* boardmenu, int ch)
65 active_menu = boardmenu->menu_list[boardmenu->selected];
69 case BINDING_SCROLL_LEFT:
70 if (boardmenu->selected-1 < 0) break;
71 set_selected_menu(boardmenu, boardmenu->selected-1);
73 case BINDING_SCROLL_RIGHT:
74 if (boardmenu->selected+1 > boardmenu->menu_count-1) break;
75 set_selected_menu(boardmenu, boardmenu->selected+1);
77 case BINDING_MOVE_ITEM_LEFT:
78 if (boardmenu->selected-1 < 0) break;
79 if (get_menu_length(boardmenu->menu_list[boardmenu->selected]) == 0) break;
84 from_menu = boardmenu->menu_list[boardmenu->selected];
85 to_menu = boardmenu->menu_list[boardmenu->selected-1];
91 get_selected_item(from_menu)
94 get_selected_item(from_menu),
95 get_menu_length(to_menu)
100 get_selected_item(from_menu)
102 set_selected_menu(boardmenu, boardmenu->selected-1);
106 case BINDING_MOVE_ITEM_RIGHT:
107 if (boardmenu->selected >= boardmenu->menu_count-1) break;
108 if (get_menu_length(boardmenu->menu_list[boardmenu->selected]) == 0) break;
109 // this is legit cpy paste please fix this
114 from_menu = boardmenu->menu_list[boardmenu->selected];
115 to_menu = boardmenu->menu_list[boardmenu->selected+1];
121 get_selected_item(from_menu)
124 get_selected_item(from_menu),
125 get_menu_length(to_menu)
130 get_selected_item(from_menu)
132 set_selected_menu(boardmenu, boardmenu->selected+1);
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); */
154 TodoItem* sel_itemdata;
156 sel_menu = boardmenu->menu_list[boardmenu->selected];
157 sel_itemdata = (TodoItem*)get_menuitem_userdata(
158 get_menu_item(sel_menu, get_selected_item(sel_menu))
161 /* set mode to popup */
162 boardmenu->popupmenu = make_popupmenu(sel_itemdata);
163 boardmenu->popup_open = 1;
168 save_to_file(boardfile_name, boardmenu);
171 exit_step(boardmenu);
177 /* getmaxyx(stdscr, y, x); */
178 /* sprintf(out, "%d,%d", y, x); */
180 /* mvprintw(20, 20, out); */
181 /* resize_term(y, x); */
185 generic_handleinput(active_menu, ch);
191 popup_handleinput(BoardMenu* boardmenu, int ch)
193 Menu* popupmenu_menu;
195 popupmenu_menu = boardmenu->popupmenu->menu;
200 boardmenu->popup_open = 0;
204 case BINDING_TOGGLE_DONE:
206 SubTask* curitem_data = (SubTask*)get_menuitem_userdata(get_menu_item(popupmenu_menu, get_selected_item(popupmenu_menu)));
207 curitem_data->done = (curitem_data->done == SubTaskState_todo) ? SubTaskState_done : SubTaskState_todo;
213 generic_handleinput(popupmenu_menu, ch);
218 generic_handleinput(Menu* menu, int ch)
222 case BINDING_SCROLL_UP:
223 menu_driver(menu, MENU_UP);
225 case BINDING_SCROLL_DOWN:
226 menu_driver(menu, MENU_DOWN);
228 case BINDING_JUMP_TOP:
229 menu_driver(menu, MENU_TOP);
231 case BINDING_JUMP_BOTTOM:
232 menu_driver(menu, MENU_BOTTOM);
234 case BINDING_MOVE_ITEM_UP:
235 menu_driver(menu, MENU_MOVE_UP);
237 case BINDING_MOVE_ITEM_DOWN:
238 menu_driver(menu, MENU_MOVE_DOWN);
240 case BINDING_DELETE_ITEM:
241 menu_driver(menu, MENU_DELETE);
243 case BINDING_APPEND_ITEM:
244 menu_driver(menu, MENU_APPEND);
246 case BINDING_INSERT_ABOVE:
247 menu_driver(menu, MENU_INSERT_ABOVE);
249 case BINDING_INSERT_BELOW:
250 menu_driver(menu, MENU_INSERT_BELOW);
252 case BINDING_EDIT_ITEM:
253 menu_driver(menu, MENU_EDIT);
259 normal_renderstep(BoardMenu* boardmenu)
261 for (int i = 0; i < boardmenu->menu_count; i++) {
263 Menu* curmenu = boardmenu->menu_list[i];
265 /* update the descriptions - maybe not do this here */
266 for (int j = 0; j < get_menu_length(curmenu); j++) {
267 update_menuitem_descrip(get_menu_item(curmenu, j));
270 render_menu(curmenu);
275 popup_renderstep(BoardMenu* boardmenu)
277 if (boardmenu->popupmenu == NULL) return;
279 render_popupmenu(boardmenu->popupmenu);
283 save_to_file(char* filepath, BoardMenu* boardmenu)
286 writeboard = boardmenu_to_board(boardmenu);
288 begin_write(filepath, writeboard);
289 free_board(writeboard);
293 exit_step(BoardMenu* boardmenu)