Add legacy style (for Windows) and make it the default for Windows. Add verbose flag

This commit is contained in:
Dr-Noob
2020-07-06 01:30:14 +02:00
parent 08f79bb914
commit 7164409ca2
5 changed files with 40 additions and 26 deletions

View File

@@ -9,26 +9,30 @@
#define ARG_STR_COLOR "color" #define ARG_STR_COLOR "color"
#define ARG_STR_HELP "help" #define ARG_STR_HELP "help"
#define ARG_STR_LEVELS "levels" #define ARG_STR_LEVELS "levels"
#define ARG_STR_VERBOSE "verbose"
#define ARG_STR_VERSION "version" #define ARG_STR_VERSION "version"
#define ARG_CHAR_STYLE 's' #define ARG_CHAR_STYLE 's'
#define ARG_CHAR_COLOR 'c' #define ARG_CHAR_COLOR 'c'
#define ARG_CHAR_HELP 'h' #define ARG_CHAR_HELP 'h'
#define ARG_CHAR_LEVELS 'l' #define ARG_CHAR_LEVELS 'l'
#define ARG_CHAR_VERBOSE 'v'
#define ARG_CHAR_VERSION 'v' #define ARG_CHAR_VERSION 'v'
#define STYLE_STR_1 "fancy" #define STYLE_STR_1 "fancy"
#define STYLE_STR_2 "retro" #define STYLE_STR_2 "retro"
#define STYLE_STR_3 "legacy"
struct args_struct { struct args_struct {
bool levels_flag; bool levels_flag;
bool help_flag; bool help_flag;
bool verbose_flag;
bool version_flag; bool version_flag;
STYLE style; STYLE style;
struct colors* colors; 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; static struct args_struct args;
STYLE get_style() { STYLE get_style() {
@@ -52,7 +56,7 @@ bool show_levels() {
} }
bool verbose_enabled() { bool verbose_enabled() {
return false; return args.verbose_flag;
} }
STYLE parse_style(char* style) { STYLE parse_style(char* style) {
@@ -96,7 +100,7 @@ bool parse_color(char* optarg, struct colors** cs) {
return false; return false;
} }
/* //TODO: Refactor c1->R c2->R ... to c[i]->R
if((*c1)->R < 0 || (*c1)->R > 255) { if((*c1)->R < 0 || (*c1)->R > 255) {
printErr("Red in color 1 is invalid. Must be in range (0, 255)"); printErr("Red in color 1 is invalid. Must be in range (0, 255)");
return false; return false;
@@ -120,7 +124,7 @@ bool parse_color(char* optarg, struct colors** cs) {
if((*c2)->B < 0 || (*c2)->B > 255) { if((*c2)->B < 0 || (*c2)->B > 255) {
printErr("Blue in color 2 is invalid. Must be in range (0, 255)"); printErr("Blue in color 2 is invalid. Must be in range (0, 255)");
return false; return false;
}*/ }
return true; return true;
} }
@@ -133,6 +137,7 @@ bool parse_args(int argc, char* argv[]) {
bool color_flag = false; bool color_flag = false;
args.levels_flag = false; args.levels_flag = false;
args.verbose_flag = false;
args.help_flag = false; args.help_flag = false;
args.style = STYLE_EMPTY; args.style = STYLE_EMPTY;
args.colors = NULL; 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_COLOR, required_argument, 0, ARG_CHAR_COLOR },
{ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP }, {ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP },
{ARG_STR_LEVELS, no_argument, 0, ARG_CHAR_LEVELS }, {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 }, {ARG_STR_VERSION, no_argument, 0, ARG_CHAR_VERSION },
{0, 0, 0, 0} {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) { while (c != -1) {
if(c == ARG_CHAR_COLOR) { if(c == ARG_CHAR_COLOR) {
@@ -178,6 +184,13 @@ bool parse_args(int argc, char* argv[]) {
} }
args.help_flag = true; 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) { else if(c == ARG_CHAR_LEVELS) {
if(args.levels_flag) { if(args.levels_flag) {
printErr("Levels option specified more than once"); printErr("Levels option specified more than once");

View File

@@ -288,7 +288,7 @@ struct topology* get_topology_info(struct cpuInfo* cpu) {
topo->total_cores = topo->logical_cores; // fallback topo->total_cores = topo->logical_cores; // fallback
} }
#endif #endif
switch(cpu->cpu_vendor) { switch(cpu->cpu_vendor) {
case VENDOR_INTEL: case VENDOR_INTEL:
if (cpu->maxLevels >= 0x00000004) { if (cpu->maxLevels >= 0x00000004) {

View File

@@ -6,10 +6,10 @@
#include "cpuid.h" #include "cpuid.h"
#include "global.h" #include "global.h"
static const char* VERSION = "0.57"; static const char* VERSION = "0.59";
void print_help(char *argv[]) { void print_help(char *argv[]) {
printf("Usage: %s [--version] [--help] [--levels] [--style fancy|retro] [--color 'R,G,B:R,G,B:R,G,B:R,G,B']\n\ printf("Usage: %s [--version] [--help] [--levels] [--style fancy|retro|legacy] [--color 'R,G,B:R,G,B:R,G,B:R,G,B']\n\
Options: \n\ Options: \n\
--color Set text color. 4 colors (in RGB format) must be specified in the form: R,G,B:R,G,B:...\n\ --color Set text color. 4 colors (in RGB format) must be specified in the form: R,G,B:R,G,B:...\n\
These colors correspond to the ASCII art color (2 colors) and for the text colors (next 2)\n\ These colors correspond to the ASCII art color (2 colors) and for the text colors (next 2)\n\
@@ -17,6 +17,7 @@ Options: \n\
--style Set the style of the ASCII art:\n\ --style Set the style of the ASCII art:\n\
* fancy \n\ * fancy \n\
* retro \n\ * retro \n\
* legacy \n\
--help Prints this help and exit\n\ --help Prints this help and exit\n\
--levels Prints CPU model and cpuid levels (debug purposes)\n\ --levels Prints CPU model and cpuid levels (debug purposes)\n\
--version Prints cpufetch version and exit\n", --version Prints cpufetch version and exit\n",

View File

@@ -147,23 +147,23 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style, struct colors* cs) {
} }
art->ascii_chars[1] = '#'; art->ascii_chars[1] = '#';
#ifdef _WIN32 // If style is emtpy, set the default style
strcpy(art->color1_ascii,COL_NONE); if(style == STYLE_EMPTY) {
strcpy(art->color2_ascii,COL_NONE); #ifdef _WIN32
strcpy(art->color1_text,COL_NONE); style = STYLE_LEGACY;
strcpy(art->color2_text,COL_NONE); #else
art->reset[0] = '\0'; style = STYLE_FANCY;
#else #endif
}
switch(style) { switch(style) {
case STYLE_EMPTY: case STYLE_LEGACY:
#ifdef _WIN32 strcpy(art->color1_ascii,COL_NONE);
strcpy(art->color1_ascii,COL_NONE); strcpy(art->color2_ascii,COL_NONE);
strcpy(art->color2_ascii,COL_NONE); strcpy(art->color1_text,COL_NONE);
strcpy(art->color1_text,COL_NONE); strcpy(art->color2_text,COL_NONE);
strcpy(art->color2_text,COL_NONE); art->reset[0] = '\0';
art->reset[0] = '\0'; break;
break;
#endif
case STYLE_FANCY: case STYLE_FANCY:
if(cs != NULL) { if(cs != NULL) {
COL_FANCY_1 = rgb_to_ansi(cs->c1, true, true); COL_FANCY_1 = rgb_to_ansi(cs->c1, true, true);
@@ -207,7 +207,6 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style, struct colors* cs) {
printBug("Found invalid style (%d)",style); printBug("Found invalid style (%d)",style);
return NULL; return NULL;
} }
#endif
char tmp[NUMBER_OF_LINES*LINE_SIZE]; char tmp[NUMBER_OF_LINES*LINE_SIZE];
if(cpuVendor == VENDOR_INTEL) strcpy(tmp, INTEL_ASCII); if(cpuVendor == VENDOR_INTEL) strcpy(tmp, INTEL_ASCII);

View File

@@ -6,12 +6,13 @@ typedef int STYLE;
#include "args.h" #include "args.h"
#include "cpuid.h" #include "cpuid.h"
#define STYLES_COUNT 2 #define STYLES_COUNT 3
#define STYLE_INVALID -2 #define STYLE_INVALID -2
#define STYLE_EMPTY -1 #define STYLE_EMPTY -1
#define STYLE_FANCY 0 #define STYLE_FANCY 0
#define STYLE_RETRO 1 #define STYLE_RETRO 1
#define STYLE_LEGACY 2
bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* freq, struct topology* topo, STYLE s, struct colors* cs); bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* freq, struct topology* topo, STYLE s, struct colors* cs);