X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=taskasaur.c;h=3987cc7ddefa982ca31c6b3baea94a6238c590b9;hb=28b77363ab45af4b933097364f511a4748648264;hp=83bbab1c8fdbcb4428dc794a868894ccd980ea72;hpb=d2a1f7b30ab6a1c4dce0e66a79f030e3949680c2;p=taskasaur.git diff --git a/taskasaur.c b/taskasaur.c index 83bbab1..3987cc7 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -11,10 +11,23 @@ void winch_handler(int sig); char** read_todo(FILE* file, int* length); WINDOW* create_win(int height, int width, int y, int x); -MENU* create_todo_menu(char** todo_list, int todo_length); +MENU* create_todo_menu(WINDOW* win, char** todo_list, int todo_length); + +void on_select(char *item); + +void free_todo(char** todo_list, int todo_length); + +struct todo_item { + char* name; + char* description; + char** items; +}; #include "config.h" +#define SELECTED_COLOR 1 +#define NON_SELECTED_COLOR 2 + int main(int argc, char** argv) { @@ -73,48 +86,53 @@ main(int argc, char** argv) return 2; } - /* for (int i = 0; i < todo_length; i++) { */ - /* printf("%p\n", todos[i]); */ - /* printf(todos[i]); */ - /* } */ - /* return 0; */ - // start ncurses initscr(); cbreak(); noecho(); curs_set(0); + keypad(stdscr, TRUE); start_color(); + /* colors */ + init_pair(SELECTED_COLOR, selected_color, COLOR_BLACK); + init_pair(NON_SELECTED_COLOR, non_selected_color, COLOR_BLACK); + getmaxyx(stdscr, height, width); - refresh(); - /* todo_win = create_win(20, 40, 5, 5); */ - char* test_todo[] = {"1lmao", "2pee", "3poo", "4feces"}; - /* todo_menu = create_todo_menu(test_todo, 4); */ - todo_menu = create_todo_menu(todos, todo_length); + todo_win = create_win(20, 40, 5, 5); + todo_menu = create_todo_menu(todo_win, todos, todo_length); post_menu(todo_menu); + refresh(); + wrefresh(todo_win); - while ((ch = getch()) != 'q') { + while ((ch = getch()) != BINDING_QUIT) { switch (ch) { - case 'j': + case BINDING_SCROLL_UP: + menu_driver(todo_menu, REQ_UP_ITEM); + break; + case BINDING_SCROLL_DOWN: menu_driver(todo_menu, REQ_DOWN_ITEM); break; - case 'k': - menu_driver(todo_menu, REQ_UP_ITEM); + case BINDING_JUMP_TOP: + menu_driver(todo_menu, REQ_FIRST_ITEM); break; - case 'G': // try to implement gg too + case BINDING_JUMP_BOTTOM: menu_driver(todo_menu, REQ_LAST_ITEM); break; + case BINDING_SELECT: + break; } + wrefresh(todo_win); } endwin(); /* Free mem */ - free(todos); // prob need to free each string in list too + unpost_menu(todo_menu); + free_todo(todos, todo_length); return 0; } @@ -145,7 +163,6 @@ read_todo(FILE* file, int* length) out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing? lineptr[strcspn(lineptr, "\n")] = 0; // remove newline - out_arr[out_len-1] = lineptr; lineptr = NULL; @@ -164,20 +181,47 @@ create_win(int height, int width, int y, int x) } MENU* -create_todo_menu(char** todo_list, int todo_length) +create_todo_menu(WINDOW* win, char** todo_list, int todo_length) { MENU* todo_menu; ITEM** item_list; ITEM* cur_item; + int wheight, wwidth; item_list = malloc((todo_length+1)*sizeof(ITEM*)); for (int i = 0; i < todo_length; i++) { - printf(todo_list[i]); item_list[i] = new_item(todo_list[i], ""); + set_item_userptr(item_list[i], on_select); } item_list[todo_length] = NULL; // last item needs to be a null pointer for some reason? todo_menu = new_menu(item_list); + getmaxyx(win, wheight, wwidth); + set_menu_win(todo_menu, win); + set_menu_sub(todo_menu, derwin(win, wheight-2, wwidth-2, 1, 2)); + set_menu_mark(todo_menu, ""); + set_menu_spacing(todo_menu, 1, 2, 1); + set_menu_fore(todo_menu, COLOR_PAIR(SELECTED_COLOR)); + set_menu_back(todo_menu, COLOR_PAIR(NON_SELECTED_COLOR)); + + box(win, 0, 0); //temp + return todo_menu; } + +void +on_select(char *item) +{ + printf("lol"); +} + +void +free_todo(char** todo_list, int todo_length) +{ + // probably check if list is too short or too long + for (int i = 0; i < todo_length; i++) { + free(todo_list[i]); + } + free(todo_list); +}