From 103d9d622254eb6257565bd08da27376c12510fd Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Sun, 13 Dec 2020 18:14:35 -0500 Subject: [PATCH] menu test --- makefile | 7 +++-- menutest.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ taskasaur | Bin 17952 -> 17984 bytes taskasaur.c | 29 +++++++++---------- 4 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 menutest.c diff --git a/makefile b/makefile index 60abac4..1c1c3e9 100644 --- a/makefile +++ b/makefile @@ -3,7 +3,10 @@ CC=gcc make: taskasaur taskasaur: - $(CC) -lncurses taskasaur.c -o taskasaur + $(CC) -lncurses -lmenu taskasaur.c -o taskasaur + +menutest: + $(CC) -lncurses -lmenu menutest.c -o menutest clean: - rm taskasaur + rm taskasaur menutest diff --git a/menutest.c b/menutest.c new file mode 100644 index 0000000..e76568e --- /dev/null +++ b/menutest.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include + +WINDOW* create_list_win(int height, int width, int y, int x); + +int +main(int argc, char** argv) +{ + int height, width; + int ch; + + WINDOW* todo_win; + char* todos[] = {"eat bread", "eat milk", "eat cheese"}; + int todo_length; + ITEM** todo_items; + MENU* todo_menu; + ITEM* cur_item; + + // start ncurses + initscr(); + cbreak(); + noecho(); + curs_set(0); + start_color(); + + getmaxyx(stdscr, height, width); + refresh(); + + /* init todo menu stuff */ + + todo_win = create_list_win(20, 40, 5, 5); + todo_length = sizeof(todos)/sizeof(todos[0]); + + todo_items = malloc((todo_length+1)*sizeof(ITEM*)); + for (int i = 0; i < todo_length; i++) { + todo_items[i] = new_item(todos[i], ""); + } + todo_items[todo_length] = NULL; // last item needs to be a null pointer for some reason? + + todo_menu = new_menu(todo_items); + post_menu(todo_menu); + + /* todo_menu = new_menu(); */ + + /* for (int i = 0; i < todo_length; i++) { */ + /* mvwprintw(todo_win, i, 0, todos[i]); */ + /* } */ + wrefresh(todo_win); + + while ((ch = getch()) != 113) { // while not q + + // ofc the first thing we need is vim keys + switch (ch) { + case 106: // j + menu_driver(todo_menu, REQ_DOWN_ITEM); + break; + case 107: // k + menu_driver(todo_menu, REQ_UP_ITEM); + break; + } + + refresh(); + /* clear(); */ + } + + endwin(); + + return 0; +} + +WINDOW* +create_list_win(int height, int width, int y, int x) +{ + WINDOW* new_win = newwin(height, width, y, x); + wrefresh(new_win); + return new_win; +} diff --git a/taskasaur b/taskasaur index 700edbfe6776d527e1afe34b062bbcfc4b778561..275b6ee81722c63c5187b4f641d7839a9b5b5613 100755 GIT binary patch delta 1633 zcmZ`(eN0XZc;bRLG=Ej6{ ze!O&Kkdu)qF@l*}{KH805_O9)3`i(Sq(nk+Vge?bDyYSMfUL>$-1lBhw#1v<_q*qu z-~HWl&b#l8UZ4{f=%AG&6+;KF@_q3{8GS=Pyy`M=su4wERBeh7i!)$T?Lhg%SgBL( z9_XiLI8M`c5lxA3aFf2mH>z>c2nV=2%m2wZwM|ZVk1I2^oSFWk;fuhAZRb-*_LI(+ zK7R4~Z7Ia{QTiba>CDg<(?c(_6&+HZR~2uieh{qsGzjU};iuTg`L@@)J5RN?cXh*7 z>}X8e%k5qmh&%B#Arwsny0wFrmqWQcTtvo?aJ1ZVXv}S{9lJO*U5tLkp z&*H8dZ*w#QeoVS%dI76&4|t~Cej(%*m)zn^s2_%t>$xooza=-&X(%_PQ4x-sF2&C= z4Zkoa3IVup+FKaJ!`z|}_OtD^t0)n6i{CMcJ1pYYZ{{K26Y$s0sqT6hNU^;cpzDb~ zVUDiH``YlS_Xz9lis&NbqZHlWyA&~ ze#uhBq_$h!dAs*n(dg2L-p9b~RHnx*{^Is+7{%U5C`~=XqKS&&Nfl@vjHG57hS_FhsGyV-nnD?$5TQsc6IRZC%}8+G ze4y;}ZPfQo=cv18LQ7~5&Q9&gCU^E^?YN$OW}tk1A0e)zHR6)XQzPDUHM+!z$30+M zkv7dI47Kdm;~gS_zhwDc#Md@uxf8MZZ&@Bk9K9#YLBvVKFyioiSvKN({vI(Ov1dz` zk06E+FT+^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6hB%8SssdP1l?Csr zp6Y&!`eRKSsB6}~1ibOuVsX%HaS$hJD<4iZoJhlkz6#OHUkg26+~lhiQ+t%F9`n5k zP>&veab~|enZZ)H8XNt^V(LHq)$ diff --git a/taskasaur.c b/taskasaur.c index 3b28bad..39eaca6 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -1,8 +1,9 @@ #include -#include -#include #include +#include #include +#include +#include void winch_handler(int sig); @@ -10,6 +11,8 @@ char** read_todo(FILE* file, int* length); WINDOW* create_list_win(int height, int width, int y, int x); +void draw_todo(WINDOW* todo_win, char** todo_list, int todo_length); + #include "config.h" int @@ -85,10 +88,7 @@ main(int argc, char** argv) refresh(); todo_win = create_list_win(20, 40, 5, 5); - for (int i = 0; i < todo_length; i++) { - mvwprintw(todo_win, i+1, 2, todos[i]); - } - wrefresh(todo_win); + draw_todo(todo_win, todos, todo_length); move(y,x); while ((ch = getch()) != 113) { // while not q @@ -146,13 +146,6 @@ read_todo(FILE* file, int* length) while ((nread = getline(&lineptr, &len, file)) != -1) { out_len++; out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing? - // remove new line character (maybe just write own new line func later) - /* lineptr = realloc(*lineptr, len-2); */ - /* *(lineptr+len-1) = '\0'; */ - /* printf(lineptr); */ - /* lineptr = realloc(lineptr, len-1); //maybe watch out for empty lines */ - /* *(lineptr+len-3) = '\0'; */ - out_arr[out_len-1] = lineptr; lineptr = NULL; @@ -167,7 +160,15 @@ WINDOW* create_list_win(int height, int width, int y, int x) { WINDOW* new_win = newwin(height, width, y, x); - box(new_win, 0, 0); wrefresh(new_win); return new_win; } + +void +draw_todo(WINDOW* todo_win, char** todo_list, int todo_length) { + for (int i = 0; i < todo_length; i++) { + mvwprintw(todo_win, i+1, 2, todo_list[i]); + } + box(todo_win, 0, 0); + wrefresh(todo_win); +} -- 2.20.1