summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2024-07-30 22:12:22 -0500
committer@syxhe <https://t.me/syxhe>2024-07-30 22:12:22 -0500
commite3c986f45eeeb1bb3ba5e931ecf042907676b3df (patch)
treea3f96c3eaa9f31ea3ad18549429a7d0fc700d055
parentf6f5e09d00e2054e1f159bdbb3fdb2fe11794876 (diff)
COLORS!!!
-rw-r--r--src/Makefile2
-rw-r--r--src/main.c6
-rw-r--r--src/screen.c61
-rw-r--r--src/screen.h4
4 files changed, 61 insertions, 12 deletions
diff --git a/src/Makefile b/src/Makefile
index 3ac4f75..e600e47 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,7 +2,7 @@ CC = gcc
2CFLAGS = -Wall -Wextra -Wpedantic -fanalyzer -Wanalyzer-too-complex -Og -g3 -ggdb 2CFLAGS = -Wall -Wextra -Wpedantic -fanalyzer -Wanalyzer-too-complex -Og -g3 -ggdb
3 3
4SHELL := /usr/bin/env -S bash 4SHELL := /usr/bin/env -S bash
5BINARY_FILES := screen #main encryption.o search.o ll.o 5BINARY_FILES := screen main encryption.o search.o ll.o
6 6
7.PHONY: all clean 7.PHONY: all clean
8 8
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) {
55 55
56 switch(key) { 56 switch(key) {
57 case 'p': 57 case 'p':
58 /* Specifying the start option of "-p=<phrase>" errors out unless this is done.
59 // Technically a user should use --passphrase=<phrase> if they want to use the = sign, but I think
60 // this is how it should work. RMS can suck it */
61 if(*arg == '=')
62 arg++;
63
58 args->inputpass = arg; 64 args->inputpass = arg;
59 break; 65 break;
60 66
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
31#include <errno.h> 31#include <errno.h>
32#include <error.h> 32#include <error.h>
33#include <menu.h> 33#include <menu.h>
34#include <time.h>
34 35
35#include <stdio.h> 36#include <stdio.h>
36#include <stdlib.h> 37#include <stdlib.h>
@@ -91,6 +92,22 @@ static struct funcholder userfuncs[] = {
91 {.callback = quit, .type = FH_QUIT, .params = {.quitp = {}}} 92 {.callback = quit, .type = FH_QUIT, .params = {.quitp = {}}}
92}; 93};
93 94
95void intercleanup(int signum, siginfo_t *info, void *ucontext) {
96 endwin();
97 error(0, 0, "[VX-GAMBLEGROUND] Caught interrupt");
98 exit(0);
99
100 return;
101}
102
103static const struct sigaction handlers[] = {
104 { // intercleanup
105 .sa_flags = SA_SIGINFO,
106 .sa_mask = SIGINT,
107 .sa_sigaction = intercleanup
108 }
109};
110
94static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { 111static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) {
95 // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range 112 // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range
96 return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin; 113 return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin;
@@ -102,9 +119,9 @@ static int rangemod(int x, int offset, int min, int max) {
102} 119}
103 120
104static int init_rgb_color(int colornum, int red, int green, int blue) { 121static int init_rgb_color(int colornum, int red, int green, int blue) {
105 int nred = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); 122 int nred = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX);
106 int ngreen = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); 123 int ngreen = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX);
107 int nblue = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); 124 int nblue = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX);
108 125
109 return init_color(colornum, nred, ngreen, nblue); 126 return init_color(colornum, nred, ngreen, nblue);
110} 127}
@@ -120,6 +137,9 @@ static int doinit(void) {
120 if(initscr() == NULL) // Initialize curses 137 if(initscr() == NULL) // Initialize curses
121 error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen"); 138 error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen");
122 139
140 if(sigaction(SIGINT, &handlers[0], NULL) < 0)
141 error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal handler");
142
123 return 0; 143 return 0;
124} 144}
125 145
@@ -331,33 +351,52 @@ int main() {
331int spin(void *spinp) { 351int spin(void *spinp) {
332 struct spinp *p = (struct spinp *)spinp; 352 struct spinp *p = (struct spinp *)spinp;
333 353
334 for(int i = CCP_RED;; i = rangemod(i, 1, CCP_RED, CCP_WHITE)) { 354 struct timespec sleeper = {
355 .tv_sec = 0,
356 .tv_nsec = 1000000000 /* Nanoseconds in 1 second */ / NUMCOLORPAIRS
357 };
358
359 for(int color = CCP_RED, i = 0; i < (NUMCOLORPAIRS * NUMCOLORCYCLE); color = rangemod(color, 1, CCP_RED, CCP_WHITE), i++) {
335 // Change the color to testing for the banner 360 // Change the color to testing for the banner
336 wbkgd(p->bannerwin, COLOR_PAIR(i)); 361 wbkgd(p->bannerwin, COLOR_PAIR(color));
337 wnoutrefresh(p->bannerwin); 362 wnoutrefresh(p->bannerwin);
338 363
339 // Change the color to testing for the menu 364 // Change the color to testing for the menu
340 wbkgd(p->menuholder, COLOR_PAIR(i)); 365 wbkgd(p->menuholder, COLOR_PAIR(color));
341 set_menu_back(p->menu, COLOR_PAIR(i)); 366 set_menu_back(p->menu, COLOR_PAIR(color));
342 wnoutrefresh(p->menuholder); 367 wnoutrefresh(p->menuholder);
343 368
344 doupdate(); 369 doupdate();
345 sleep(1); 370 nanosleep(&sleeper, NULL);
346 } 371 }
347 372
373 // Revert colors back to normal
374 wbkgd(p->bannerwin, COLOR_PAIR(CCP_BANNER));
375 wnoutrefresh(p->bannerwin);
376
377 wbkgd(p->menuholder, COLOR_PAIR(CCP_BANNER));
378 set_menu_back(p->menu, COLOR_PAIR(CCP_BANNER));
379 wnoutrefresh(p->menuholder);
380
381 doupdate();
382
348 return 0; 383 return 0;
349} 384}
350 385
351// Increase number of spins 386// Increase number of spins
352int buy(void *buyp) { 387int buy(void *buyp) {
353 endwin(); 388 endwin();
354 error(1, 0, "buy"); 389 error(0, 0, "buy");
390 exit(0);
391
355 return 0; 392 return 0;
356} 393}
357 394
358// Quit out 395// Quit out
359int quit(void *quitp) { 396int quit(void *quitp) {
360 endwin(); 397 endwin();
361 error(1, 0, "quit"); 398 error(0, 0, "quit");
362 return 1; 399 exit(0);
400
401 return 0;
363} \ No newline at end of file 402} \ 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 {
62 62
63 CCP_TOOBIG 63 CCP_TOOBIG
64}; 64};
65#define NUMCOLORCYCLE 4
66#define COLORWIDTH (CCP_WHITE - CCP_RED)
67#define NUMCOLORPAIRS (COLORWIDTH + 1)
68
65 69
66struct funcholder { 70struct funcholder {
67 int (*callback)(void*); 71 int (*callback)(void*);