From: Daniel Liu Date: Fri, 5 Feb 2021 06:14:05 +0000 (-0500) Subject: working on add X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=bc8adcf5e271186d94f15fc0c4c5db678055c5ef;p=taskasaur.git working on add --- diff --git a/config.h b/config.h index 88b50d6..7fbd972 100644 --- a/config.h +++ b/config.h @@ -36,5 +36,6 @@ static int menu_non_selected_color = COLOR_GREEN; #define BINDING_MOVE_ITEM_DOWN 'J' #define BINDING_DELETE_ITEM 'D' #define BINDING_SELECT '\n' +#define BINDING_APPEND_ITEM 'a' #endif diff --git a/headers/menu.h b/headers/menu.h index 48e5bdd..10a739f 100644 --- a/headers/menu.h +++ b/headers/menu.h @@ -14,7 +14,8 @@ typedef enum { MENU_BOTTOM, MENU_MOVE_UP, MENU_MOVE_DOWN, - MENU_DELETE + MENU_DELETE, + MENU_APPEND } MenuAction; typedef struct Menu Menu; diff --git a/headers/render.h b/headers/render.h index ac094aa..453c525 100644 --- a/headers/render.h +++ b/headers/render.h @@ -15,4 +15,7 @@ enum TaskasaurColors { extern int init_tscurses(void); extern int exit_tscurses(void); +extern int curs_on(void); +extern int curs_off(void); + #endif diff --git a/menu.c b/menu.c index 4d27ec4..eadfefb 100644 --- a/menu.c +++ b/menu.c @@ -14,6 +14,8 @@ #define MENU_PAD_LEFT 2 #define MENU_PAD_RIGHT 1 +#define MAX_CONTENTS_LENGTH 256 + typedef struct MenuItem { char* contents; } MenuItem; @@ -33,6 +35,7 @@ typedef struct Menu { int swap_item(Menu* menu, int src_index, int dest_index); int delete_item(Menu* menu, int index); +int insert_item(Menu* menu, int index); MenuItem* create_menuitem(char* contents) @@ -155,6 +158,43 @@ delete_item(Menu* menu, int index) return 0; } +int +insert_item(Menu* menu, int index) +{ // note, this func does not validate index + + char* new_content; + MenuItem* new_menuitem; + + // remember null char + /* new_content = malloc((MAX_CONTENTS_LENGTH+1)*sizeof(char)); */ + new_content = malloc(10); + new_content = "abcdefghi"; + + new_menuitem = create_menuitem(new_content); + + /* resize array and insert */ + /* char out[100]; */ + /* sprintf(out, "%d\n", menu->menu_length); */ + /* mvprintw(0, 0, out); */ + /* menu->menu_items = realloc(menu->menu_items, (menu->menu_length+1)*sizeof(MenuItem*)); */ + + /* int temp_size = (menu->menu_length-index)*sizeof(MenuItem*); */ + /* MenuItem* temp[temp_size]; */ + + /* memcpy(temp, menu->menu_items[index], temp_size); */ + /* menu->menu_items[index] = new_menuitem; */ + /* memcpy(menu->menu_items[index+1], temp, temp_size); */ + + /* menu->menu_items[menu->menu_length] = 0; // remember null at end */ + /* menu->menu_length += 1; */ + + + /* move cursor pos */ + /* menu->selected_item = index; */ + + return 0; +} + int menu_driver(Menu* menu, MenuAction action) { @@ -193,6 +233,14 @@ menu_driver(Menu* menu, MenuAction action) wclear(menu->sub_win); break; + case MENU_APPEND: + /* curs_on(); */ + /* curs_off(); */ + /* insert_item(menu, menu->selected_item); */ + insert_item(menu, 0); + wclear(menu->sub_win); + break; + default: // This is here for debug, disable later fprintf(stderr, "Invalid menu action"); } diff --git a/render.c b/render.c index c4812af..b0fb21a 100644 --- a/render.c +++ b/render.c @@ -12,8 +12,7 @@ init_tscurses(void) { initscr(); cbreak(); - noecho(); - curs_set(0); + curs_off(); keypad(stdscr, TRUE); /* need to error check this */ @@ -50,6 +49,23 @@ init_tscolors(void) return 0; } +/* cursor */ +int +curs_on(void) +{ + echo(); + curs_set(1); + return 0; +} + +int +curs_off(void) +{ + noecho(); + curs_set(0); + return 0; +} + /* wins */ int create_todowin(void) diff --git a/taskasaur.c b/taskasaur.c index 793f0fa..c9bddb8 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -73,12 +73,16 @@ main(int argc, char** argv) case BINDING_DELETE_ITEM: menu_driver(active_menu, MENU_DELETE); break; + case BINDING_APPEND_ITEM: + menu_driver(active_menu, MENU_APPEND); + break; } for (int i = 0; i < boardmenu->menu_count; i++) { render_menu(boardmenu->menu_list[i]); } + } exit_tscurses();