feature made light theme work

This commit is contained in:
bePrivate
2023-10-31 14:41:30 +01:00
parent 269dcce5e7
commit a1e71bd372
2 changed files with 55 additions and 20 deletions
BIN
View File
Binary file not shown.
+55 -20
View File
@@ -10,17 +10,18 @@
#include <unistd.h>
#include <time.h>
#define RESET "\x1b[37;0m" // color 0
#define RED "\x1b[37;41m" // color 1
#define GREEN "\x1b[37;42m" // color 2
#define YELLOW "\x1b[37;43m" // color 3
#define GRAY "\x1b[37;90m" // color gray
char *RESET = "\x1b[0m";
char *RED = "\x1b[31m";
char *GREEN = "\x1b[32m";
char *YELLOW = "\x1b[33m";
char *GRAY = "\x1b[7m";
char wordlist_path[1024];
char wordlist[16384][6]; // 2^14
int len_wordlist = 0;
int flag_verbose = 0;
int flag_worldlist = 0;
int flag_light_theme = 0;
char playfield[6][5] = {
{ ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ' },
@@ -72,11 +73,12 @@ void print_help_and_usage() {
"Help and usage for wordlec:\n"
"\n"
"Help:\n"
"--wordlist <path_to_wordlist_file> ........... specify a custom wordlist\n"
" RULES: five characters on each line (no empty lines),\n"
" each new line is separated by '\\n' (Enter/Return)\n"
"--verbose .................................... be verbose (show what the program is doing aka debug info)\n"
"--help ....................................... show this help screen\n"
"-w/--wordlist <path_to_wordlist_file> ........... specify a custom wordlist\n"
" RULES: five characters on each line (no empty lines),\n"
" each new line is separated by '\\n' (Enter/Return)\n"
"-l/--light-theme ................................ activate light theme\n"
"-v/--verbose .................................... be verbose (show what the program is doing aka debug info)\n"
"-h/--help ....................................... show this help screen\n"
);
}
@@ -122,28 +124,28 @@ void clear() {
*/
void show() {
clear();
printf(GRAY "╔═══╦═══╦═══╦═══╦═══╗" RESET "\n");
printf("%s╔═══╦═══╦═══╦═══╦═══╗%s\n", GRAY, RESET);
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 5; j++) {
switch (pf_props[i][j][1]) {
case '0':
printf(GRAY "" RESET " %c ", playfield[i][j]);
printf("%s║ %c ", GRAY, playfield[i][j]);
break;
case '1':
printf(GRAY "" RED " %c " RESET, playfield[i][j]);
printf("%s║%s %c %s", GRAY, RED, playfield[i][j], RESET);
break;
case '2':
printf(GRAY "" GREEN " %c " RESET, playfield[i][j]);
printf("%s║%s %c %s", GRAY, GREEN, playfield[i][j], RESET);
break;
case '3':
printf(GRAY "" YELLOW " %c " RESET, playfield[i][j]);
printf("%s║%s %c %s", GRAY, YELLOW, playfield[i][j], RESET);
break;
}
}
printf(GRAY "" RESET "\n");
if (i < 5) printf(GRAY "╠═══╬═══╬═══╬═══╬═══╣" RESET "\n");
printf("%s║%s\n", GRAY, RESET);
if (i < 5) printf("%s╠═══╬═══╬═══╬═══╬═══╣%s\n", GRAY, RESET);
}
printf(GRAY "╚═══╩═══╩═══╩═══╩═══╝" RESET "\n");
printf("%s╚═══╩═══╩═══╩═══╩═══╝%s\n", GRAY, RESET);
}
/*
@@ -279,7 +281,7 @@ int argparse(int argc, char *argv[]) {
/*
look for invalid arguments
*/
if (strcmp(argv[i], argv[0]) != 0 && strcmp(argv[i], "--wordlist") != 0 && strcmp(argv[i-1], "--wordlist") != 0 && strcmp(argv[i], "--verbose") != 0 && strcmp(argv[i], "--help") != 0 && strcmp(argv[i], "-h") != 0 && strcmp(argv[i], "-w") != 0 && strcmp(argv[i-1], "-w") != 0 && strcmp(argv[i], "-v") != 0) {
if (strcmp(argv[i], argv[0]) != 0 && strcmp(argv[i], "--wordlist") != 0 && strcmp(argv[i-1], "--wordlist") != 0 && strcmp(argv[i], "--verbose") != 0 && strcmp(argv[i], "--help") != 0 && strcmp(argv[i], "-h") != 0 && strcmp(argv[i], "-w") != 0 && strcmp(argv[i-1], "-w") != 0 && strcmp(argv[i], "-v") != 0 && strcmp(argv[i], "-l") != 0 && strcmp(argv[i], "--light-theme") != 0) {
fprintf(stderr, "Invalid argument %s\n", argv[i]);
flag_error = 1;
}
@@ -309,6 +311,17 @@ int argparse(int argc, char *argv[]) {
flag_verbose = 1;
}
/*
deciding on light/dark theme
*/
if (strcmp(argv[i], "--light-theme") == 0 && flag_light_theme == 0) {
flag_light_theme = 1;
}
// --------------------------------------------------------------
if (strcmp(argv[i], "-l") == 0 && flag_light_theme == 0) {
flag_light_theme = 1;
}
/*
getting the path to the wordlist
*/
@@ -356,16 +369,38 @@ void show_win_lose_message() {
if (win == 0 && lose == 1) fprintf(stdout, "You lost. :( The word was %s.\n", word_to_guess);
}
/*
set the theme (light/dark)
*/
void set_theme() {
if (flag_light_theme == 1) {
RESET = "\x1b[0;0m";
RED = "\x1b[0;41m";
GREEN = "\x1b[0;42m";
YELLOW = "\x1b[0;43m";
GRAY = "\x1b[0;7m";
} else {
RESET = "\x1b[37;0m";
RED = "\x1b[37;41m";
GREEN = "\x1b[37;42m";
YELLOW = "\x1b[37;43m";
GRAY = "\x1b[37;90m";
}
}
int main(int argc, char *argv[]) {
// pass the arguments
int args = argparse(argc, argv);
switch (args) {
case 1:
return 1;
return 1; // error occured
case 2:
return 0; // --help passed
}
// set light/dark theme
set_theme();
// prerequisite 1
get_random_word(word_to_guess, wordlist_path);