Fix bug which caused you couldnt use --version. Change --style to be more user friendly. Update --help

This commit is contained in:
Dr-Noob
2020-09-01 11:00:11 +02:00
parent 1f80566f63
commit de8952b4ea
3 changed files with 57 additions and 22 deletions

View File

@@ -12,17 +12,20 @@
#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 ARG_CHAR_STYLE 0
#define ARG_CHAR_COLOR 1
#define ARG_CHAR_HELP 2
#define ARG_CHAR_LEVELS 3
#define ARG_CHAR_VERBOSE 4
#define ARG_CHAR_VERSION 5
#define STYLE_STR_1 "fancy"
#define STYLE_STR_2 "retro"
#define STYLE_STR_3 "legacy"
#define COLOR_STR_INTEL "intel"
#define COLOR_STR_AMD "amd"
struct args_struct {
bool levels_flag;
bool help_flag;
@@ -88,8 +91,25 @@ bool parse_color(char* optarg, struct colors** cs) {
struct color** c3 = &((*cs)->c3);
struct color** c4 = &((*cs)->c4);
int32_t ret;
char* str_to_parse = NULL;
bool free_ptr;
ret = sscanf(optarg, "%d,%d,%d:%d,%d,%d:%d,%d,%d:%d,%d,%d",
if(strcmp(optarg, COLOR_STR_INTEL) == 0) {
str_to_parse = malloc(sizeof(char) * 46);
strcpy(str_to_parse, COLOR_DEFAULT_INTEL);
free_ptr = true;
}
else if(strcmp(optarg, COLOR_STR_AMD) == 0) {
str_to_parse = malloc(sizeof(char) * 44);
strcpy(str_to_parse, COLOR_DEFAULT_AMD);
free_ptr = true;
}
else {
str_to_parse = optarg;
free_ptr = false;
}
ret = sscanf(str_to_parse, "%d,%d,%d:%d,%d,%d:%d,%d,%d:%d,%d,%d",
&(*c1)->R, &(*c1)->G, &(*c1)->B,
&(*c2)->R, &(*c2)->G, &(*c2)->B,
&(*c3)->R, &(*c3)->G, &(*c3)->B,
@@ -124,7 +144,9 @@ 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;
}
}
if(free_ptr) free (str_to_parse);
return true;
}

View File

@@ -6,23 +6,33 @@
#include "cpuid.h"
#include "global.h"
static const char* VERSION = "0.64";
static const char* VERSION = "0.65";
void print_help(char *argv[]) {
printf("Usage: %s [--version] [--help] [--levels] [--style fancy|retro|legacy] [--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 \"intel\"|\"amd\"|'R,G,B:R,G,B:R,G,B:R,G,B']\n\n\
Options: \n\
--color Set a custom color scheme. 4 colors must be specified in RGB with the format: 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\
Suggested color (AMD): --color 250,250,250:0,154,102:250,250,250:0,154,102\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\
--verbose Prints extra information (if available) about how cpufetch tried fetching information\n\
--version Prints cpufetch version and exit\n",
--color Set the color scheme. By default, cpufetch uses the system color scheme. This option \n\
lets the user use different colors to print the CPU art: \n\
* \"intel\": Use to intel color scheme \n\
* \"amd\": Use amd default color scheme \n\
* custom: If color do not match \"intel\" or \"amd\", a custom scheme can be specified: \n\
4 colors must be given in RGB with the format: R,G,B:R,G,B:... \n\
These colors correspond to CPU art color (2 colors) and for the text colors (following 2) \n\
For example: --color 239,90,45:210,200,200:100,200,45:0,200,200 \n\n\
--style Set the style of CPU art: \n\
* \"fancy\" (default style) \n\
* \"retro\" (old cpufetch style) \n\
* \"legacy\" \n\n\
--levels Prints CPU model and cpuid levels (debug purposes)\n\n\
--verbose Prints extra information (if available) about how cpufetch tried fetching information\n\n\
--help Prints this help and exit\n\n\
--version Prints cpufetch version and exit\n\n\
\n\
NOTES: \n\
- Bugs or improvements should be submitted to: github.com/Dr-Noob/cpufetch/issues \n\
- Peak performance information is NOT accurate. cpufetch computes peak performance using the max \n\
frequency. However, to properly compute peak performance, you need to know the frequency of the \n\
CPU running AVX code, which is not be fetched by cpufetch since it depends on each specific CPU. \n",
argv[0]);
}

View File

@@ -14,6 +14,9 @@ typedef int STYLE;
#define STYLE_RETRO 1
#define STYLE_LEGACY 2
#define COLOR_DEFAULT_INTEL "15,125,194:230,230,230:40,150,220:230,230,230"
#define COLOR_DEFAULT_AMD "250,250,250:0,154,102:250,250,250:0,154,102"
bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* freq, struct topology* topo, STYLE s, struct colors* cs);
#endif