Skip to content

Commit

Permalink
Add legacy style (for Windows) and make it the default for Windows. A…
Browse files Browse the repository at this point in the history
…dd verbose flag
  • Loading branch information
Dr-Noob committed Jul 5, 2020
1 parent 08f79bb commit 7164409
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
23 changes: 18 additions & 5 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -52,7 +56,7 @@ bool show_levels() {
}

bool verbose_enabled() {
return false;
return args.verbose_flag;
}

STYLE parse_style(char* style) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ struct topology* get_topology_info(struct cpuInfo* cpu) {
topo->total_cores = topo->logical_cores; // fallback
}
#endif

switch(cpu->cpu_vendor) {
case VENDOR_INTEL:
if (cpu->maxLevels >= 0x00000004) {
Expand Down
5 changes: 3 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
#include "cpuid.h"
#include "global.h"

static const char* VERSION = "0.57";
static const char* VERSION = "0.59";

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\
--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\
Suggested color (Intel): --color 15,125,194:230,230,230:40,150,220:230,230,230\n\
--style Set the style of the ASCII art:\n\
* fancy \n\
* retro \n\
* legacy \n\
--help Prints this help and exit\n\
--levels Prints CPU model and cpuid levels (debug purposes)\n\
--version Prints cpufetch version and exit\n",
Expand Down
33 changes: 16 additions & 17 deletions src/printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,23 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style, struct colors* cs) {
}
art->ascii_chars[1] = '#';

#ifdef _WIN32
strcpy(art->color1_ascii,COL_NONE);
strcpy(art->color2_ascii,COL_NONE);
strcpy(art->color1_text,COL_NONE);
strcpy(art->color2_text,COL_NONE);
art->reset[0] = '\0';
#else
// If style is emtpy, set the default style
if(style == STYLE_EMPTY) {
#ifdef _WIN32
style = STYLE_LEGACY;
#else
style = STYLE_FANCY;
#endif
}

switch(style) {
case STYLE_EMPTY:
#ifdef _WIN32
strcpy(art->color1_ascii,COL_NONE);
strcpy(art->color2_ascii,COL_NONE);
strcpy(art->color1_text,COL_NONE);
strcpy(art->color2_text,COL_NONE);
art->reset[0] = '\0';
break;
#endif
case STYLE_LEGACY:
strcpy(art->color1_ascii,COL_NONE);
strcpy(art->color2_ascii,COL_NONE);
strcpy(art->color1_text,COL_NONE);
strcpy(art->color2_text,COL_NONE);
art->reset[0] = '\0';
break;
case STYLE_FANCY:
if(cs != NULL) {
COL_FANCY_1 = rgb_to_ansi(cs->c1, true, true);
Expand Down Expand Up @@ -207,7 +207,6 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style, struct colors* cs) {
printBug("Found invalid style (%d)",style);
return NULL;
}
#endif

char tmp[NUMBER_OF_LINES*LINE_SIZE];
if(cpuVendor == VENDOR_INTEL) strcpy(tmp, INTEL_ASCII);
Expand Down
3 changes: 2 additions & 1 deletion src/printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ typedef int STYLE;
#include "args.h"
#include "cpuid.h"

#define STYLES_COUNT 2
#define STYLES_COUNT 3

#define STYLE_INVALID -2
#define STYLE_EMPTY -1
#define STYLE_FANCY 0
#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);

Expand Down

0 comments on commit 7164409

Please sign in to comment.