mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
Add legacy style (for Windows) and make it the default for Windows. Add verbose flag
This commit is contained in:
23
src/args.c
23
src/args.c
@@ -9,26 +9,30 @@
|
||||
#define ARG_STR_COLOR "color"
|
||||
#define ARG_STR_HELP "help"
|
||||
#define ARG_STR_LEVELS "levels"
|
||||
#define ARG_STR_VERBOSE "verbose"
|
||||
#define ARG_STR_VERSION "version"
|
||||
|
||||
#define ARG_CHAR_STYLE 's'
|
||||
#define ARG_CHAR_COLOR 'c'
|
||||
#define ARG_CHAR_HELP 'h'
|
||||
#define ARG_CHAR_LEVELS 'l'
|
||||
#define ARG_CHAR_VERBOSE 'v'
|
||||
#define ARG_CHAR_VERSION 'v'
|
||||
|
||||
#define STYLE_STR_1 "fancy"
|
||||
#define STYLE_STR_2 "retro"
|
||||
#define STYLE_STR_3 "legacy"
|
||||
|
||||
struct args_struct {
|
||||
bool levels_flag;
|
||||
bool help_flag;
|
||||
bool verbose_flag;
|
||||
bool version_flag;
|
||||
STYLE style;
|
||||
struct colors* colors;
|
||||
};
|
||||
|
||||
static const char* SYTLES_STR_LIST[STYLES_COUNT] = { STYLE_STR_1, STYLE_STR_2 };
|
||||
static const char* SYTLES_STR_LIST[STYLES_COUNT] = { STYLE_STR_1, STYLE_STR_2, STYLE_STR_3 };
|
||||
static struct args_struct args;
|
||||
|
||||
STYLE get_style() {
|
||||
@@ -52,7 +56,7 @@ bool show_levels() {
|
||||
}
|
||||
|
||||
bool verbose_enabled() {
|
||||
return false;
|
||||
return args.verbose_flag;
|
||||
}
|
||||
|
||||
STYLE parse_style(char* style) {
|
||||
@@ -96,7 +100,7 @@ bool parse_color(char* optarg, struct colors** cs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
//TODO: Refactor c1->R c2->R ... to c[i]->R
|
||||
if((*c1)->R < 0 || (*c1)->R > 255) {
|
||||
printErr("Red in color 1 is invalid. Must be in range (0, 255)");
|
||||
return false;
|
||||
@@ -120,7 +124,7 @@ bool parse_color(char* optarg, struct colors** cs) {
|
||||
if((*c2)->B < 0 || (*c2)->B > 255) {
|
||||
printErr("Blue in color 2 is invalid. Must be in range (0, 255)");
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -133,6 +137,7 @@ bool parse_args(int argc, char* argv[]) {
|
||||
|
||||
bool color_flag = false;
|
||||
args.levels_flag = false;
|
||||
args.verbose_flag = false;
|
||||
args.help_flag = false;
|
||||
args.style = STYLE_EMPTY;
|
||||
args.colors = NULL;
|
||||
@@ -142,11 +147,12 @@ bool parse_args(int argc, char* argv[]) {
|
||||
{ARG_STR_COLOR, required_argument, 0, ARG_CHAR_COLOR },
|
||||
{ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP },
|
||||
{ARG_STR_LEVELS, no_argument, 0, ARG_CHAR_LEVELS },
|
||||
{ARG_STR_VERBOSE, no_argument, 0, ARG_CHAR_VERBOSE },
|
||||
{ARG_STR_VERSION, no_argument, 0, ARG_CHAR_VERSION },
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long(argc, argv,"",long_options, &option_index);
|
||||
c = getopt_long(argc, argv, "", long_options, &option_index);
|
||||
|
||||
while (c != -1) {
|
||||
if(c == ARG_CHAR_COLOR) {
|
||||
@@ -178,6 +184,13 @@ bool parse_args(int argc, char* argv[]) {
|
||||
}
|
||||
args.help_flag = true;
|
||||
}
|
||||
else if(c == ARG_CHAR_VERBOSE) {
|
||||
if(args.verbose_flag) {
|
||||
printErr("Verbose option specified more than once");
|
||||
return false;
|
||||
}
|
||||
args.verbose_flag = true;
|
||||
}
|
||||
else if(c == ARG_CHAR_LEVELS) {
|
||||
if(args.levels_flag) {
|
||||
printErr("Levels option specified more than once");
|
||||
|
||||
Reference in New Issue
Block a user