Skip to content

Commit de8952b

Browse files
committed
Fix bug which caused you couldnt use --version. Change --style to be more user friendly. Update --help
1 parent 1f80566 commit de8952b

File tree

3 files changed

+57
-22
lines changed

3 files changed

+57
-22
lines changed

src/args.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212
#define ARG_STR_VERBOSE "verbose"
1313
#define ARG_STR_VERSION "version"
1414

15-
#define ARG_CHAR_STYLE 's'
16-
#define ARG_CHAR_COLOR 'c'
17-
#define ARG_CHAR_HELP 'h'
18-
#define ARG_CHAR_LEVELS 'l'
19-
#define ARG_CHAR_VERBOSE 'v'
20-
#define ARG_CHAR_VERSION 'v'
15+
#define ARG_CHAR_STYLE 0
16+
#define ARG_CHAR_COLOR 1
17+
#define ARG_CHAR_HELP 2
18+
#define ARG_CHAR_LEVELS 3
19+
#define ARG_CHAR_VERBOSE 4
20+
#define ARG_CHAR_VERSION 5
2121

2222
#define STYLE_STR_1 "fancy"
2323
#define STYLE_STR_2 "retro"
2424
#define STYLE_STR_3 "legacy"
2525

26+
#define COLOR_STR_INTEL "intel"
27+
#define COLOR_STR_AMD "amd"
28+
2629
struct args_struct {
2730
bool levels_flag;
2831
bool help_flag;
@@ -88,8 +91,25 @@ bool parse_color(char* optarg, struct colors** cs) {
8891
struct color** c3 = &((*cs)->c3);
8992
struct color** c4 = &((*cs)->c4);
9093
int32_t ret;
94+
char* str_to_parse = NULL;
95+
bool free_ptr;
9196

92-
ret = sscanf(optarg, "%d,%d,%d:%d,%d,%d:%d,%d,%d:%d,%d,%d",
97+
if(strcmp(optarg, COLOR_STR_INTEL) == 0) {
98+
str_to_parse = malloc(sizeof(char) * 46);
99+
strcpy(str_to_parse, COLOR_DEFAULT_INTEL);
100+
free_ptr = true;
101+
}
102+
else if(strcmp(optarg, COLOR_STR_AMD) == 0) {
103+
str_to_parse = malloc(sizeof(char) * 44);
104+
strcpy(str_to_parse, COLOR_DEFAULT_AMD);
105+
free_ptr = true;
106+
}
107+
else {
108+
str_to_parse = optarg;
109+
free_ptr = false;
110+
}
111+
112+
ret = sscanf(str_to_parse, "%d,%d,%d:%d,%d,%d:%d,%d,%d:%d,%d,%d",
93113
&(*c1)->R, &(*c1)->G, &(*c1)->B,
94114
&(*c2)->R, &(*c2)->G, &(*c2)->B,
95115
&(*c3)->R, &(*c3)->G, &(*c3)->B,
@@ -124,7 +144,9 @@ bool parse_color(char* optarg, struct colors** cs) {
124144
if((*c2)->B < 0 || (*c2)->B > 255) {
125145
printErr("Blue in color 2 is invalid. Must be in range (0, 255)");
126146
return false;
127-
}
147+
}
148+
149+
if(free_ptr) free (str_to_parse);
128150

129151
return true;
130152
}

src/main.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,33 @@
66
#include "cpuid.h"
77
#include "global.h"
88

9-
static const char* VERSION = "0.64";
9+
static const char* VERSION = "0.65";
1010

1111
void print_help(char *argv[]) {
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\
12+
printf("Usage: %s [--version] [--help] [--levels] [--style \"fancy\"|\"retro\"|\"legacy\"] [--color \"intel\"|\"amd\"|'R,G,B:R,G,B:R,G,B:R,G,B']\n\n\
1313
Options: \n\
14-
--color Set a custom color scheme. 4 colors must be specified in RGB with the format: R,G,B:R,G,B:...\n\
15-
These colors correspond to the ASCII art color (2 colors) and for the text colors (next 2)\n\
16-
Suggested color (Intel): --color 15,125,194:230,230,230:40,150,220:230,230,230\n\
17-
Suggested color (AMD): --color 250,250,250:0,154,102:250,250,250:0,154,102\n\
18-
--style Set the style of the ASCII art:\n\
19-
* fancy \n\
20-
* retro \n\
21-
* legacy \n\
22-
--help Prints this help and exit\n\
23-
--levels Prints CPU model and cpuid levels (debug purposes)\n\
24-
--verbose Prints extra information (if available) about how cpufetch tried fetching information\n\
25-
--version Prints cpufetch version and exit\n",
14+
--color Set the color scheme. By default, cpufetch uses the system color scheme. This option \n\
15+
lets the user use different colors to print the CPU art: \n\
16+
* \"intel\": Use to intel color scheme \n\
17+
* \"amd\": Use amd default color scheme \n\
18+
* custom: If color do not match \"intel\" or \"amd\", a custom scheme can be specified: \n\
19+
4 colors must be given in RGB with the format: R,G,B:R,G,B:... \n\
20+
These colors correspond to CPU art color (2 colors) and for the text colors (following 2) \n\
21+
For example: --color 239,90,45:210,200,200:100,200,45:0,200,200 \n\n\
22+
--style Set the style of CPU art: \n\
23+
* \"fancy\" (default style) \n\
24+
* \"retro\" (old cpufetch style) \n\
25+
* \"legacy\" \n\n\
26+
--levels Prints CPU model and cpuid levels (debug purposes)\n\n\
27+
--verbose Prints extra information (if available) about how cpufetch tried fetching information\n\n\
28+
--help Prints this help and exit\n\n\
29+
--version Prints cpufetch version and exit\n\n\
30+
\n\
31+
NOTES: \n\
32+
- Bugs or improvements should be submitted to: github.com/Dr-Noob/cpufetch/issues \n\
33+
- Peak performance information is NOT accurate. cpufetch computes peak performance using the max \n\
34+
frequency. However, to properly compute peak performance, you need to know the frequency of the \n\
35+
CPU running AVX code, which is not be fetched by cpufetch since it depends on each specific CPU. \n",
2636
argv[0]);
2737
}
2838

src/printer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ typedef int STYLE;
1414
#define STYLE_RETRO 1
1515
#define STYLE_LEGACY 2
1616

17+
#define COLOR_DEFAULT_INTEL "15,125,194:230,230,230:40,150,220:230,230,230"
18+
#define COLOR_DEFAULT_AMD "250,250,250:0,154,102:250,250,250:0,154,102"
19+
1720
bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* freq, struct topology* topo, STYLE s, struct colors* cs);
1821

1922
#endif

0 commit comments

Comments
 (0)