From 72839bcfca470f3840697e2215edff02d3e42ab1 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Tue, 23 Jul 2024 13:18:22 -0500 Subject: Toil endlessly on menus because they're shit --- src/Makefile | 6 +++--- src/screen.c | 64 +++++++++++++++++++++++++++++++++++++----------------------- src/screen.h | 27 +++++++++++++++++-------- 3 files changed, 62 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 55268aa..a828be2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ CC = gcc CFLAGS = -Wall -Wextra -Wpedantic -fanalyzer -Wanalyzer-too-complex -Og -g3 -ggdb SHELL := /usr/bin/env -S bash -BINARY_FILES := main encryption.o search.o ll.o +BINARY_FILES := screen #main encryption.o search.o ll.o .PHONY: all clean @@ -14,9 +14,9 @@ clean: main: main.c search.o encryption.o ll.o -encryption.o: encryption.c encryption.h screen: screen.c screen.h - set -e -o pipefail && $(CC) $(CFLAGS) $$(pkg-config --cflags libsodium) screen.c -o screen -lncurses -lmenu $$(pkg-config --libs libsodium) + set -e -o pipefail && $(CC) $(CFLAGS) $$(pkg-config --cflags libsodium) screen.c -o screen $$(pkg-config --libs libsodium) -lmenu $$(pkg-config --libs ncurses) +encryption.o: encryption.c encryption.h search.o: search.c search.h ll.o: ll.c ll.h \ No newline at end of file diff --git a/src/screen.c b/src/screen.c index 9cdac02..5ca2dc2 100644 --- a/src/screen.c +++ b/src/screen.c @@ -31,6 +31,7 @@ SLOTS HERE #include #include +#include static const char *phrases[] = { // By @syxhe on telegram @@ -78,8 +79,7 @@ static const char *phrases[] = { static const char *menu_choices[] = { "Spin", "Buy spins", - "Quit", - NULL + "Quit" }; static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { @@ -115,16 +115,17 @@ int main() { // curses colors made this go away. Also VSCode's terminal theming is fucking with it as well, so // use a normal terminal for accurate colors */ - init_rgb_color(CC_RED, 255, 0, 0); - init_rgb_color(CC_ORANGE, 255, 128, 0); - init_rgb_color(CC_YELLOW, 255, 255, 0); - init_rgb_color(CC_GREEN, 0, 255, 0); - init_rgb_color(CC_BLUE, 0, 0, 255); - init_rgb_color(CC_PURPLE, 255, 0, 255); - init_rgb_color(CC_WHITE, 255, 255, 255); - - init_pair(1, CC_WHITE, CURSES_BLUE); - + init_rgb_color(CC_RED, 255, 0, 0); + init_rgb_color(CC_ORANGE, 255, 128, 0); + init_rgb_color(CC_YELLOW, 255, 255, 0); + init_rgb_color(CC_GREEN, 0, 255, 0); + init_rgb_color(CC_BLUE, 0, 0, 255); + init_rgb_color(CC_PURPLE, 155, 0, 255); + init_rgb_color(CC_MAGENTA, 255, 0, 255); + init_rgb_color(CC_WHITE, 255, 255, 255); + + init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE); + init_pair(CCP_TESTING, CC_RED, CC_WHITE); } cbreak(); // Disables character buffering @@ -134,7 +135,8 @@ int main() { int row = -1, col = -1; getmaxyx(stdscr, row, col); - + if(row < 0 || col < 0) + error(1, 0, "[VX-GAMBLEGROUND] Couldn't get max terminal size for some reason"); int randomnum = randombytes_uniform(STATIC_ARRSIZE(phrases)); if(randomnum < 0) @@ -146,37 +148,43 @@ int main() { if(phrase == NULL) error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); - wbkgd(phrase, COLOR_PAIR(1)); + if(has_colors()) + wbkgd(phrase, COLOR_PAIR(1)); + mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); waddstr(phrase, phrases[randomnum]); wrefresh(phrase); - //* Dummy test for fun. Shows how windows can't be overlapping or things get weird + /* Dummy test for fun. Shows how windows can't be overlapping or things get weird (and that row offsets matter) WINDOW *test = newwin(row - 1, col, 1, 0); + int rand1, rand2; + for(int c = wgetch(test);; c = wgetch(test)) { - mvwaddch(test, c % row, c % col, c | (A_BOLD * (randombytes_random() % 2 > 0))); + rand1 = randombytes_uniform(row - 1); + rand2 = randombytes_uniform(col); + + mvwaddch(test, rand1, rand2, c | (A_BOLD * (randombytes_random() % 2 > 0))); } //*/ - /* Menu example - ITEM **items; + //* Menu example (fuck menus got damn) + ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; MENU *menu; - items = calloc(STATIC_ARRSIZE(menu_choices) + 1, sizeof(ITEM*)); - if(items == NULL) - error(-1, errno, "Could not allocate space for menu items"); - for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++) items[i] = new_item(menu_choices[i], menu_choices[i]); items[STATIC_ARRSIZE(menu_choices)] = NULL; menu = new_menu(items); - mvprintw(LINES - 2, 0, "F1 to Exit"); + if(menu == NULL) + error(1, errno, "Could not create menu"); + + // set_menu_format(menu, 3, col); post_menu(menu); refresh(); int c; - while((c = getch()) != KEY_F(1)) { + while((c = getch()) != KEY_F(4)) { switch(c) { case KEY_DOWN: menu_driver(menu, REQ_DOWN_ITEM); @@ -186,6 +194,14 @@ int main() { menu_driver(menu, REQ_UP_ITEM); break; + case KEY_LEFT: + menu_driver(menu, REQ_LEFT_ITEM); + break; + + case KEY_RIGHT: + menu_driver(menu, REQ_RIGHT_ITEM); + break; + case KEY_ENTER: break; } diff --git a/src/screen.h b/src/screen.h index a4ecf5a..78e2077 100644 --- a/src/screen.h +++ b/src/screen.h @@ -26,19 +26,30 @@ enum custom_colors { CURSES_CYAN = COLOR_CYAN, // ncurses' default cyan CURSES_WHITE = COLOR_WHITE, // ncurses' default white - CC_RED, - CC_ORANGE, - CC_YELLOW, - CC_GREEN, - CC_BLUE, - CC_PURPLE, - CC_MAGENTA, - CC_WHITE, + /* Start custom color definitions */ + + CC_RED, // RGB: 255, 0, 0 + CC_ORANGE, // RGB: 255, 128, 0 + CC_YELLOW, // RGB: 255, 255, 0 + CC_GREEN, // RGB: 0, 255, 0 + CC_BLUE, // RGB: 0, 0, 255 + CC_PURPLE, // RGB: 155, 0, 255 + CC_MAGENTA, // RGB: 255, 0, 255 + CC_WHITE, // RGB: 255, 255, 255 // This isn't actually a color, even if you try to use it as one CC_TOOBIG }; +enum customcolor_pairs { + CCP_UNDEFINED, + + CCP_BANNER, + CCP_TESTING, + + CCP_TOOBIG +}; + // Converts value from within the range of [oldmin, oldmax] to a value within the range [newmin, newmax] static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax); -- cgit v1.2.3