Skip to content

Commit 7164409

Browse files
committed
Add legacy style (for Windows) and make it the default for Windows. Add verbose flag
1 parent 08f79bb commit 7164409

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

src/args.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,30 @@
99
#define ARG_STR_COLOR "color"
1010
#define ARG_STR_HELP "help"
1111
#define ARG_STR_LEVELS "levels"
12+
#define ARG_STR_VERBOSE "verbose"
1213
#define ARG_STR_VERSION "version"
1314

1415
#define ARG_CHAR_STYLE 's'
1516
#define ARG_CHAR_COLOR 'c'
1617
#define ARG_CHAR_HELP 'h'
1718
#define ARG_CHAR_LEVELS 'l'
19+
#define ARG_CHAR_VERBOSE 'v'
1820
#define ARG_CHAR_VERSION 'v'
1921

2022
#define STYLE_STR_1 "fancy"
2123
#define STYLE_STR_2 "retro"
24+
#define STYLE_STR_3 "legacy"
2225

2326
struct args_struct {
2427
bool levels_flag;
2528
bool help_flag;
29+
bool verbose_flag;
2630
bool version_flag;
2731
STYLE style;
2832
struct colors* colors;
2933
};
3034

31-
static const char* SYTLES_STR_LIST[STYLES_COUNT] = { STYLE_STR_1, STYLE_STR_2 };
35+
static const char* SYTLES_STR_LIST[STYLES_COUNT] = { STYLE_STR_1, STYLE_STR_2, STYLE_STR_3 };
3236
static struct args_struct args;
3337

3438
STYLE get_style() {
@@ -52,7 +56,7 @@ bool show_levels() {
5256
}
5357

5458
bool verbose_enabled() {
55-
return false;
59+
return args.verbose_flag;
5660
}
5761

5862
STYLE parse_style(char* style) {
@@ -96,7 +100,7 @@ bool parse_color(char* optarg, struct colors** cs) {
96100
return false;
97101
}
98102

99-
/*
103+
//TODO: Refactor c1->R c2->R ... to c[i]->R
100104
if((*c1)->R < 0 || (*c1)->R > 255) {
101105
printErr("Red in color 1 is invalid. Must be in range (0, 255)");
102106
return false;
@@ -120,7 +124,7 @@ bool parse_color(char* optarg, struct colors** cs) {
120124
if((*c2)->B < 0 || (*c2)->B > 255) {
121125
printErr("Blue in color 2 is invalid. Must be in range (0, 255)");
122126
return false;
123-
}*/
127+
}
124128

125129
return true;
126130
}
@@ -133,6 +137,7 @@ bool parse_args(int argc, char* argv[]) {
133137

134138
bool color_flag = false;
135139
args.levels_flag = false;
140+
args.verbose_flag = false;
136141
args.help_flag = false;
137142
args.style = STYLE_EMPTY;
138143
args.colors = NULL;
@@ -142,11 +147,12 @@ bool parse_args(int argc, char* argv[]) {
142147
{ARG_STR_COLOR, required_argument, 0, ARG_CHAR_COLOR },
143148
{ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP },
144149
{ARG_STR_LEVELS, no_argument, 0, ARG_CHAR_LEVELS },
150+
{ARG_STR_VERBOSE, no_argument, 0, ARG_CHAR_VERBOSE },
145151
{ARG_STR_VERSION, no_argument, 0, ARG_CHAR_VERSION },
146152
{0, 0, 0, 0}
147153
};
148154

149-
c = getopt_long(argc, argv,"",long_options, &option_index);
155+
c = getopt_long(argc, argv, "", long_options, &option_index);
150156

151157
while (c != -1) {
152158
if(c == ARG_CHAR_COLOR) {
@@ -178,6 +184,13 @@ bool parse_args(int argc, char* argv[]) {
178184
}
179185
args.help_flag = true;
180186
}
187+
else if(c == ARG_CHAR_VERBOSE) {
188+
if(args.verbose_flag) {
189+
printErr("Verbose option specified more than once");
190+
return false;
191+
}
192+
args.verbose_flag = true;
193+
}
181194
else if(c == ARG_CHAR_LEVELS) {
182195
if(args.levels_flag) {
183196
printErr("Levels option specified more than once");

src/cpuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ struct topology* get_topology_info(struct cpuInfo* cpu) {
288288
topo->total_cores = topo->logical_cores; // fallback
289289
}
290290
#endif
291-
291+
292292
switch(cpu->cpu_vendor) {
293293
case VENDOR_INTEL:
294294
if (cpu->maxLevels >= 0x00000004) {

src/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
#include "cpuid.h"
77
#include "global.h"
88

9-
static const char* VERSION = "0.57";
9+
static const char* VERSION = "0.59";
1010

1111
void print_help(char *argv[]) {
12-
printf("Usage: %s [--version] [--help] [--levels] [--style fancy|retro] [--color 'R,G,B:R,G,B:R,G,B:R,G,B']\n\
12+
printf("Usage: %s [--version] [--help] [--levels] [--style fancy|retro|legacy] [--color 'R,G,B:R,G,B:R,G,B:R,G,B']\n\
1313
Options: \n\
1414
--color Set text color. 4 colors (in RGB format) must be specified in the form: R,G,B:R,G,B:...\n\
1515
These colors correspond to the ASCII art color (2 colors) and for the text colors (next 2)\n\
1616
Suggested color (Intel): --color 15,125,194:230,230,230:40,150,220:230,230,230\n\
1717
--style Set the style of the ASCII art:\n\
1818
* fancy \n\
1919
* retro \n\
20+
* legacy \n\
2021
--help Prints this help and exit\n\
2122
--levels Prints CPU model and cpuid levels (debug purposes)\n\
2223
--version Prints cpufetch version and exit\n",

src/printer.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,23 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style, struct colors* cs) {
147147
}
148148
art->ascii_chars[1] = '#';
149149

150-
#ifdef _WIN32
151-
strcpy(art->color1_ascii,COL_NONE);
152-
strcpy(art->color2_ascii,COL_NONE);
153-
strcpy(art->color1_text,COL_NONE);
154-
strcpy(art->color2_text,COL_NONE);
155-
art->reset[0] = '\0';
156-
#else
150+
// If style is emtpy, set the default style
151+
if(style == STYLE_EMPTY) {
152+
#ifdef _WIN32
153+
style = STYLE_LEGACY;
154+
#else
155+
style = STYLE_FANCY;
156+
#endif
157+
}
158+
157159
switch(style) {
158-
case STYLE_EMPTY:
159-
#ifdef _WIN32
160-
strcpy(art->color1_ascii,COL_NONE);
161-
strcpy(art->color2_ascii,COL_NONE);
162-
strcpy(art->color1_text,COL_NONE);
163-
strcpy(art->color2_text,COL_NONE);
164-
art->reset[0] = '\0';
165-
break;
166-
#endif
160+
case STYLE_LEGACY:
161+
strcpy(art->color1_ascii,COL_NONE);
162+
strcpy(art->color2_ascii,COL_NONE);
163+
strcpy(art->color1_text,COL_NONE);
164+
strcpy(art->color2_text,COL_NONE);
165+
art->reset[0] = '\0';
166+
break;
167167
case STYLE_FANCY:
168168
if(cs != NULL) {
169169
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) {
207207
printBug("Found invalid style (%d)",style);
208208
return NULL;
209209
}
210-
#endif
211210

212211
char tmp[NUMBER_OF_LINES*LINE_SIZE];
213212
if(cpuVendor == VENDOR_INTEL) strcpy(tmp, INTEL_ASCII);

src/printer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ typedef int STYLE;
66
#include "args.h"
77
#include "cpuid.h"
88

9-
#define STYLES_COUNT 2
9+
#define STYLES_COUNT 3
1010

1111
#define STYLE_INVALID -2
1212
#define STYLE_EMPTY -1
1313
#define STYLE_FANCY 0
1414
#define STYLE_RETRO 1
15+
#define STYLE_LEGACY 2
1516

1617
bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* freq, struct topology* topo, STYLE s, struct colors* cs);
1718

0 commit comments

Comments
 (0)