From e3c986f45eeeb1bb3ba5e931ecf042907676b3df Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Tue, 30 Jul 2024 22:12:22 -0500 Subject: COLORS!!! --- src/Makefile | 2 +- src/main.c | 6 ++++++ src/screen.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++----------- src/screen.h | 4 ++++ 4 files changed, 61 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 3ac4f75..e600e47 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 := screen #main encryption.o search.o ll.o +BINARY_FILES := screen main encryption.o search.o ll.o .PHONY: all clean diff --git a/src/main.c b/src/main.c index 7da36b8..2eb512c 100644 --- a/src/main.c +++ b/src/main.c @@ -55,6 +55,12 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { switch(key) { case 'p': + /* Specifying the start option of "-p=" errors out unless this is done. + // Technically a user should use --passphrase= if they want to use the = sign, but I think + // this is how it should work. RMS can suck it */ + if(*arg == '=') + arg++; + args->inputpass = arg; break; diff --git a/src/screen.c b/src/screen.c index 4287da8..6df9cac 100644 --- a/src/screen.c +++ b/src/screen.c @@ -31,6 +31,7 @@ SLOTS HERE #include #include #include +#include #include #include @@ -91,6 +92,22 @@ static struct funcholder userfuncs[] = { {.callback = quit, .type = FH_QUIT, .params = {.quitp = {}}} }; +void intercleanup(int signum, siginfo_t *info, void *ucontext) { + endwin(); + error(0, 0, "[VX-GAMBLEGROUND] Caught interrupt"); + exit(0); + + return; +} + +static const struct sigaction handlers[] = { + { // intercleanup + .sa_flags = SA_SIGINFO, + .sa_mask = SIGINT, + .sa_sigaction = intercleanup + } +}; + static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin; @@ -102,9 +119,9 @@ static int rangemod(int x, int offset, int min, int max) { } static int init_rgb_color(int colornum, int red, int green, int blue) { - int nred = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); - int ngreen = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); - int nblue = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); + int nred = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); + int ngreen = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); + int nblue = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); return init_color(colornum, nred, ngreen, nblue); } @@ -120,6 +137,9 @@ static int doinit(void) { if(initscr() == NULL) // Initialize curses error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen"); + if(sigaction(SIGINT, &handlers[0], NULL) < 0) + error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal handler"); + return 0; } @@ -331,33 +351,52 @@ int main() { int spin(void *spinp) { struct spinp *p = (struct spinp *)spinp; - for(int i = CCP_RED;; i = rangemod(i, 1, CCP_RED, CCP_WHITE)) { + struct timespec sleeper = { + .tv_sec = 0, + .tv_nsec = 1000000000 /* Nanoseconds in 1 second */ / NUMCOLORPAIRS + }; + + for(int color = CCP_RED, i = 0; i < (NUMCOLORPAIRS * NUMCOLORCYCLE); color = rangemod(color, 1, CCP_RED, CCP_WHITE), i++) { // Change the color to testing for the banner - wbkgd(p->bannerwin, COLOR_PAIR(i)); + wbkgd(p->bannerwin, COLOR_PAIR(color)); wnoutrefresh(p->bannerwin); // Change the color to testing for the menu - wbkgd(p->menuholder, COLOR_PAIR(i)); - set_menu_back(p->menu, COLOR_PAIR(i)); + wbkgd(p->menuholder, COLOR_PAIR(color)); + set_menu_back(p->menu, COLOR_PAIR(color)); wnoutrefresh(p->menuholder); doupdate(); - sleep(1); + nanosleep(&sleeper, NULL); } + // Revert colors back to normal + wbkgd(p->bannerwin, COLOR_PAIR(CCP_BANNER)); + wnoutrefresh(p->bannerwin); + + wbkgd(p->menuholder, COLOR_PAIR(CCP_BANNER)); + set_menu_back(p->menu, COLOR_PAIR(CCP_BANNER)); + wnoutrefresh(p->menuholder); + + doupdate(); + return 0; } // Increase number of spins int buy(void *buyp) { endwin(); - error(1, 0, "buy"); + error(0, 0, "buy"); + exit(0); + return 0; } // Quit out int quit(void *quitp) { endwin(); - error(1, 0, "quit"); - return 1; + error(0, 0, "quit"); + exit(0); + + return 0; } \ No newline at end of file diff --git a/src/screen.h b/src/screen.h index a5f51fd..1a59b5b 100644 --- a/src/screen.h +++ b/src/screen.h @@ -62,6 +62,10 @@ enum customcolor_pairs { CCP_TOOBIG }; +#define NUMCOLORCYCLE 4 +#define COLORWIDTH (CCP_WHITE - CCP_RED) +#define NUMCOLORPAIRS (COLORWIDTH + 1) + struct funcholder { int (*callback)(void*); -- cgit v1.2.3