feature made light theme work
This commit is contained in:
+53
-18
@@ -10,17 +10,18 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define RESET "\x1b[37;0m" // color 0
|
char *RESET = "\x1b[0m";
|
||||||
#define RED "\x1b[37;41m" // color 1
|
char *RED = "\x1b[31m";
|
||||||
#define GREEN "\x1b[37;42m" // color 2
|
char *GREEN = "\x1b[32m";
|
||||||
#define YELLOW "\x1b[37;43m" // color 3
|
char *YELLOW = "\x1b[33m";
|
||||||
#define GRAY "\x1b[37;90m" // color gray
|
char *GRAY = "\x1b[7m";
|
||||||
|
|
||||||
char wordlist_path[1024];
|
char wordlist_path[1024];
|
||||||
char wordlist[16384][6]; // 2^14
|
char wordlist[16384][6]; // 2^14
|
||||||
int len_wordlist = 0;
|
int len_wordlist = 0;
|
||||||
int flag_verbose = 0;
|
int flag_verbose = 0;
|
||||||
int flag_worldlist = 0;
|
int flag_worldlist = 0;
|
||||||
|
int flag_light_theme = 0;
|
||||||
char playfield[6][5] = {
|
char playfield[6][5] = {
|
||||||
{ ' ', ' ', ' ', ' ', ' ' },
|
{ ' ', ' ', ' ', ' ', ' ' },
|
||||||
{ ' ', ' ', ' ', ' ', ' ' },
|
{ ' ', ' ', ' ', ' ', ' ' },
|
||||||
@@ -72,11 +73,12 @@ void print_help_and_usage() {
|
|||||||
"Help and usage for wordlec:\n"
|
"Help and usage for wordlec:\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Help:\n"
|
"Help:\n"
|
||||||
"--wordlist <path_to_wordlist_file> ........... specify a custom wordlist\n"
|
"-w/--wordlist <path_to_wordlist_file> ........... specify a custom wordlist\n"
|
||||||
" RULES: five characters on each line (no empty lines),\n"
|
" RULES: five characters on each line (no empty lines),\n"
|
||||||
" each new line is separated by '\\n' (Enter/Return)\n"
|
" each new line is separated by '\\n' (Enter/Return)\n"
|
||||||
"--verbose .................................... be verbose (show what the program is doing aka debug info)\n"
|
"-l/--light-theme ................................ activate light theme\n"
|
||||||
"--help ....................................... show this help screen\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() {
|
void show() {
|
||||||
clear();
|
clear();
|
||||||
printf(GRAY "╔═══╦═══╦═══╦═══╦═══╗" RESET "\n");
|
printf("%s╔═══╦═══╦═══╦═══╦═══╗%s\n", GRAY, RESET);
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
for (int j = 0; j < 5; j++) {
|
for (int j = 0; j < 5; j++) {
|
||||||
switch (pf_props[i][j][1]) {
|
switch (pf_props[i][j][1]) {
|
||||||
case '0':
|
case '0':
|
||||||
printf(GRAY "║" RESET " %c ", playfield[i][j]);
|
printf("%s║ %c ", GRAY, playfield[i][j]);
|
||||||
break;
|
break;
|
||||||
case '1':
|
case '1':
|
||||||
printf(GRAY "║" RED " %c " RESET, playfield[i][j]);
|
printf("%s║%s %c %s", GRAY, RED, playfield[i][j], RESET);
|
||||||
break;
|
break;
|
||||||
case '2':
|
case '2':
|
||||||
printf(GRAY "║" GREEN " %c " RESET, playfield[i][j]);
|
printf("%s║%s %c %s", GRAY, GREEN, playfield[i][j], RESET);
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
printf(GRAY "║" YELLOW " %c " RESET, playfield[i][j]);
|
printf("%s║%s %c %s", GRAY, YELLOW, playfield[i][j], RESET);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf(GRAY "║" RESET "\n");
|
printf("%s║%s\n", GRAY, RESET);
|
||||||
if (i < 5) printf(GRAY "╠═══╬═══╬═══╬═══╬═══╣" RESET "\n");
|
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
|
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]);
|
fprintf(stderr, "Invalid argument %s\n", argv[i]);
|
||||||
flag_error = 1;
|
flag_error = 1;
|
||||||
}
|
}
|
||||||
@@ -309,6 +311,17 @@ int argparse(int argc, char *argv[]) {
|
|||||||
flag_verbose = 1;
|
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
|
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);
|
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[]) {
|
int main(int argc, char *argv[]) {
|
||||||
// pass the arguments
|
// pass the arguments
|
||||||
int args = argparse(argc, argv);
|
int args = argparse(argc, argv);
|
||||||
switch (args) {
|
switch (args) {
|
||||||
case 1:
|
case 1:
|
||||||
return 1;
|
return 1; // error occured
|
||||||
case 2:
|
case 2:
|
||||||
return 0; // --help passed
|
return 0; // --help passed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set light/dark theme
|
||||||
|
set_theme();
|
||||||
|
|
||||||
// prerequisite 1
|
// prerequisite 1
|
||||||
get_random_word(word_to_guess, wordlist_path);
|
get_random_word(word_to_guess, wordlist_path);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user