From: Daniel Liu Date: Sat, 23 Jan 2021 18:46:40 +0000 (-0500) Subject: generic array list helper X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=82204679646dbb05f22adf6dca9bca18943ea9f6;p=taskasaur.git generic array list helper --- diff --git a/headers/menu.h b/headers/menu.h index e678c1e..8ccd1fb 100644 --- a/headers/menu.h +++ b/headers/menu.h @@ -1,9 +1,15 @@ + +#ifndef __MENU_H__ +#define __MENU_H__ + /* ncurses doesn't support multiline menu items, * so i wrote my own menu lib */ typedef struct Menu Menu; typedef struct MenuItem MenuItem; -extern Menu* create_menu(MenuItem* item_list); -extern int set_menu_items(Menu* menu, MenuItem* item_list); +extern Menu* create_menu(MenuItem** item_list); +extern int set_menu_items(Menu* menu, MenuItem** item_list); extern MenuItem* get_menu_items(Menu* menu); + +#endif diff --git a/headers/parser.h b/headers/parser.h index 4542eed..41520b7 100644 --- a/headers/parser.h +++ b/headers/parser.h @@ -1,4 +1,7 @@ +#ifndef __PARSER_H__ +#define __PARSER_H__ + #include #include #include @@ -39,3 +42,4 @@ extern Board* begin_parse(char* board_path); extern void log_todo(Board* board); +#endif diff --git a/headers/render.h b/headers/render.h index 3a5501f..c3407f9 100644 --- a/headers/render.h +++ b/headers/render.h @@ -1,4 +1,7 @@ +#ifndef __RENDER_H__ +#define __RENDER_H__ + #include enum TaskasaurColors { @@ -10,3 +13,4 @@ enum TaskasaurColors { extern int init_tscurses(void); extern int exit_tscurses(void); +#endif diff --git a/headers/utils.h b/headers/utils.h new file mode 100644 index 0000000..0d23060 --- /dev/null +++ b/headers/utils.h @@ -0,0 +1,21 @@ + +#ifndef __UTILS_H__ +#define __UTILS_H__ + +#define \ +array_length(type, array) \ +({ \ + type* m_arr; \ + int m_len; \ + \ + m_arr = (type*)array; \ + m_len = 0; \ + \ + while (m_arr[m_len] != 0) { \ + m_len += 1; \ + } \ + \ + m_len; \ +}) + +#endif diff --git a/makefile b/makefile index 6cb7cf7..4e10dde 100644 --- a/makefile +++ b/makefile @@ -2,6 +2,8 @@ CC=gcc make: taskasaur +all: taskasaur + parser.o: parser.c headers/parser.h $(CC) -c parser.c @@ -11,7 +13,10 @@ render.o: render.c headers/render.h menu.o: menu.c headers/menu.h $(CC) -c menu.c -taskasaur: taskasaur.c parser.o render.o menu.o +utils.o: utils.c headers/utils.h + $(CC) -c utils.c + +taskasaur: taskasaur.c parser.o render.o menu.o utils.o $(CC) -o $@ $^ -lncurses -lmd4c clean: diff --git a/menu.c b/menu.c index 07605c9..ddcd8de 100644 --- a/menu.c +++ b/menu.c @@ -1,27 +1,40 @@ +#include #include +#include #include "headers/menu.h" +#include "headers/utils.h" typedef struct MenuItem { char* contents; } MenuItem; typedef struct Menu { - MenuItem* menu_items; + MenuItem** menu_items; int menu_length; int selected_item; + WINDOW* menu_win; } Menu; +int render_menu(Menu* menu); Menu* -create_menu(MenuItem* item_list) +create_menu(MenuItem** item_list) { + Menu *new_menu; + + new_menu = malloc(sizeof(Menu)); + new_menu->menu_items = item_list; + new_menu->menu_length = array_length(MenuItem*, item_list); + new_menu->selected_item = 0; + WINDOW* menu_win = NULL; + return NULL; } int -set_menu_items(Menu* menu, MenuItem* item_list) +set_menu_items(Menu* menu, MenuItem** item_list) { return 0; } @@ -31,3 +44,18 @@ get_menu_items(Menu* menu) { return NULL; } + +int +render_menu(Menu* menu) +{ + + for (int i = 0; i < menu->menu_length; i++) { + + /* color selected item */ + + } + + return 0; +} + + diff --git a/taskasaur.c b/taskasaur.c index 8925d04..eee0edb 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -1,6 +1,8 @@ #include "headers/parser.h" #include "headers/render.h" +#include "headers/menu.h" +#include "headers/utils.h" int main(int argc, char** argv) @@ -15,6 +17,7 @@ main(int argc, char** argv) getch(); exit_tscurses(); + return 0; } diff --git a/utils.c b/utils.c new file mode 100644 index 0000000..2f5c53b --- /dev/null +++ b/utils.c @@ -0,0 +1,4 @@ + +#include "headers/utils.h" + +