mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
Add "none" style (useful for non colored terminals). Refactoring in printer
This commit is contained in:
27
src/args.c
27
src/args.c
@@ -11,6 +11,7 @@
|
|||||||
#define ARG_CHAR_VERSION 'v'
|
#define ARG_CHAR_VERSION 'v'
|
||||||
#define STYLE_STR_1 "default"
|
#define STYLE_STR_1 "default"
|
||||||
#define STYLE_STR_2 "dark"
|
#define STYLE_STR_2 "dark"
|
||||||
|
#define STYLE_STR_3 "none"
|
||||||
|
|
||||||
struct args_struct {
|
struct args_struct {
|
||||||
int help_flag;
|
int help_flag;
|
||||||
@@ -18,7 +19,7 @@ struct args_struct {
|
|||||||
STYLE style;
|
STYLE style;
|
||||||
};
|
};
|
||||||
|
|
||||||
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 parseStyle(char* style) {
|
STYLE parseStyle(char* style) {
|
||||||
@@ -47,13 +48,13 @@ bool verbose_enabled() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parseArgs(int argc, char* argv[]) {
|
bool parseArgs(int argc, char* argv[]) {
|
||||||
int c;
|
int c;
|
||||||
int digit_optind = 0;
|
int digit_optind = 0;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
|
|
||||||
args.help_flag = BOOLEAN_FALSE;
|
args.help_flag = false;
|
||||||
args.style = STYLE_EMPTY;
|
args.style = STYLE_EMPTY;
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
@@ -69,31 +70,31 @@ int parseArgs(int argc, char* argv[]) {
|
|||||||
if(c == ARG_CHAR_STYLE) {
|
if(c == ARG_CHAR_STYLE) {
|
||||||
if(args.style != STYLE_EMPTY) {
|
if(args.style != STYLE_EMPTY) {
|
||||||
printf("ERROR: Style option specified more than once\n");
|
printf("ERROR: Style option specified more than once\n");
|
||||||
return BOOLEAN_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
args.style = parseStyle(optarg);
|
args.style = parseStyle(optarg);
|
||||||
if(args.style == STYLE_INVALID) {
|
if(args.style == STYLE_INVALID) {
|
||||||
printf("ERROR: Invalid style '%s'\n",optarg);
|
printf("ERROR: Invalid style '%s'\n",optarg);
|
||||||
return BOOLEAN_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(c == ARG_CHAR_HELP) {
|
else if(c == ARG_CHAR_HELP) {
|
||||||
if(args.help_flag) {
|
if(args.help_flag) {
|
||||||
printf("ERROR: Help option specified more than once\n");
|
printf("ERROR: Help option specified more than once\n");
|
||||||
return BOOLEAN_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
args.help_flag = BOOLEAN_TRUE;
|
args.help_flag = true;
|
||||||
}
|
}
|
||||||
else if (c == ARG_CHAR_VERSION) {
|
else if (c == ARG_CHAR_VERSION) {
|
||||||
if(args.version_flag) {
|
if(args.version_flag) {
|
||||||
printf("ERROR: Version option specified more than once\n");
|
printf("ERROR: Version option specified more than once\n");
|
||||||
return BOOLEAN_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
args.version_flag = BOOLEAN_TRUE;
|
args.version_flag = true;
|
||||||
}
|
}
|
||||||
else if(c == '?') {
|
else if(c == '?') {
|
||||||
printf("WARNING: Invalid options\n");
|
printf("WARNING: Invalid options\n");
|
||||||
args.help_flag = BOOLEAN_TRUE;
|
args.help_flag = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -105,13 +106,13 @@ int parseArgs(int argc, char* argv[]) {
|
|||||||
|
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
printf("WARNING: Invalid options\n");
|
printf("WARNING: Invalid options\n");
|
||||||
args.help_flag = BOOLEAN_TRUE;
|
args.help_flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((args.help_flag + args.version_flag + (args.style != STYLE_EMPTY)) > 1) {
|
if((args.help_flag + args.version_flag + (args.style != STYLE_EMPTY)) > 1) {
|
||||||
printf("WARNING: You should specify just one option\n");
|
printf("WARNING: You should specify just one option\n");
|
||||||
args.help_flag = BOOLEAN_TRUE;
|
args.help_flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BOOLEAN_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "printer.h"
|
#include "printer.h"
|
||||||
|
|
||||||
int parseArgs(int argc, char* argv[]);
|
bool parseArgs(int argc, char* argv[]);
|
||||||
STYLE getStyle();
|
STYLE getStyle();
|
||||||
int showHelp();
|
int showHelp();
|
||||||
int showVersion();
|
int showVersion();
|
||||||
|
|||||||
84
src/ascii.h
84
src/ascii.h
@@ -2,48 +2,50 @@
|
|||||||
#define __ASCII__
|
#define __ASCII__
|
||||||
|
|
||||||
#define NUMBER_OF_LINES 20
|
#define NUMBER_OF_LINES 20
|
||||||
#define LINE_SIZE 63
|
#define LINE_SIZE 62
|
||||||
|
|
||||||
#define AMD1 " \0"
|
#define AMD_ASCII \
|
||||||
#define AMD2 " \0"
|
" \
|
||||||
#define AMD3 " \0"
|
\
|
||||||
#define AMD4 " \0"
|
\
|
||||||
#define AMD5 " \0"
|
\
|
||||||
#define AMD6 " \0"
|
\
|
||||||
#define AMD7 " @@@@ @@@ @@@ @@@@@@@@ ############ \0"
|
\
|
||||||
#define AMD8 " @@@@@@ @@@@@ @@@@ @@@ @@@@ ########## \0"
|
@@@@ @@@ @@@ @@@@@@@@ ############ \
|
||||||
#define AMD9 " @@@ @@@ @@@@@@@@@@@@@ @@@ @@ # #### \0"
|
@@@@@@ @@@@@ @@@@ @@@ @@@@ ########## \
|
||||||
#define AMD10 " @@@ @@@ @@@ @@@ @@@ @@@ @@@ ### #### \0"
|
@@@ @@@ @@@@@@@@@@@@@ @@@ @@ # #### \
|
||||||
#define AMD11 " @@@@@@@@@@@@ @@@ @@@ @@@ @@@ #### ## ### \0"
|
@@@ @@@ @@@ @@@ @@@ @@@ @@@ ### #### \
|
||||||
#define AMD12 " @@@ @@@ @@@ @@@ @@@@@@@@@ ######## ## \0"
|
@@@@@@@@@@@@ @@@ @@@ @@@ @@@ #### ## ### \
|
||||||
#define AMD13 " \0"
|
@@@ @@@ @@@ @@@ @@@@@@@@@ ######## ## \
|
||||||
#define AMD14 " \0"
|
\
|
||||||
#define AMD15 " \0"
|
\
|
||||||
#define AMD16 " \0"
|
\
|
||||||
#define AMD17 " \0"
|
\
|
||||||
#define AMD18 " \0"
|
\
|
||||||
#define AMD19 " \0"
|
\
|
||||||
#define AMD20 " \0"
|
\
|
||||||
|
"
|
||||||
|
|
||||||
#define INTEL1 " ################ \0"
|
#define INTEL_ASCII \
|
||||||
#define INTEL2 " ####### ####### \0"
|
" ################ \
|
||||||
#define INTEL3 " #### #### \0"
|
####### ####### \
|
||||||
#define INTEL4 " ### #### \0"
|
#### #### \
|
||||||
#define INTEL5 " ### ### \0"
|
### #### \
|
||||||
#define INTEL6 " ### ### \0"
|
### ### \
|
||||||
#define INTEL7 " # ### ### ### \0"
|
### ### \
|
||||||
#define INTEL8 " ## ### ######### ###### ###### ### ### \0"
|
# ### ### ### \
|
||||||
#define INTEL9 " ## ### ### ### ### #### #### ### ### \0"
|
## ### ######### ###### ###### ### ### \
|
||||||
#define INTEL10 " ## ### ### ### ### ### ### ### ### \0"
|
## ### ### ### ### #### #### ### ### \
|
||||||
#define INTEL11 "## ### ### ### ### ########## ### #### \0"
|
## ### ### ### ### ### ### ### ### \
|
||||||
#define INTEL12 "## ### ### ### ### ### ### ##### \0"
|
## ### ### ### ### ########## ### #### \
|
||||||
#define INTEL13 "## ## ### ### ##### ######### ## ### \0"
|
## ### ### ### ### ### ### ##### \
|
||||||
#define INTEL14 "### \0"
|
## ## ### ### ##### ######### ## ### \
|
||||||
#define INTEL15 " ### \0"
|
### \
|
||||||
#define INTEL16 " #### #### \0"
|
### \
|
||||||
#define INTEL17 " ##### ########## \0"
|
#### #### \
|
||||||
#define INTEL18 " ########## ################ \0"
|
##### ########## \
|
||||||
#define INTEL19 " ############################### \0"
|
########## ################ \
|
||||||
#define INTEL20 " \0"
|
############################### \
|
||||||
|
"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Options: \n\
|
|||||||
--style Set logo style color\n\
|
--style Set logo style color\n\
|
||||||
default: Default style color\n\
|
default: Default style color\n\
|
||||||
dark: Dark style color\n\
|
dark: Dark style color\n\
|
||||||
|
none: Don't use colors\n\
|
||||||
--help Print this help and exit\n\
|
--help Print this help and exit\n\
|
||||||
--version Print cpufetch version and exit\n",
|
--version Print cpufetch version and exit\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "printer.h"
|
#include "printer.h"
|
||||||
#include "ascii.h"
|
#include "ascii.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
|
#define COL_NONE ""
|
||||||
#define COL_INTEL_DEFAULT_1 "\x1b[36;1m"
|
#define COL_INTEL_DEFAULT_1 "\x1b[36;1m"
|
||||||
#define COL_INTEL_DEFAULT_2 "\x1b[37;1m"
|
#define COL_INTEL_DEFAULT_2 "\x1b[37;1m"
|
||||||
#define COL_INTEL_DARK_1 "\x1b[34;1m"
|
#define COL_INTEL_DARK_1 "\x1b[34;1m"
|
||||||
#define COL_INTEL_DARK_2 "\x1b[30m"
|
#define COL_INTEL_DARK_2 "\x1b[30m"
|
||||||
#define COL_AMD_DEFAULT_1 "\x1b[37;1m"
|
#define COL_AMD_DEFAULT_1 "\x1b[37;1m"
|
||||||
#define COL_AMD_DEFAULT_2 "\x1b[31;1m"
|
#define COL_AMD_DEFAULT_2 "\x1b[31;1m"
|
||||||
#define COL_AMD_DARK_1 "\x1b[30;1m"
|
#define COL_AMD_DARK_1 "\x1b[30;1m"
|
||||||
#define COL_AMD_DARK_2 "\x1b[32;1m"
|
#define COL_AMD_DARK_2 "\x1b[32;1m"
|
||||||
#define RESET "\x1b[0m"
|
#define RESET "\x1b[0m"
|
||||||
|
|
||||||
#define TITLE_NAME "Name: "
|
#define TITLE_NAME "Name: "
|
||||||
#define TITLE_FREQUENCY "Frequency: "
|
#define TITLE_FREQUENCY "Frequency: "
|
||||||
@@ -53,14 +55,14 @@ struct ascii {
|
|||||||
VENDOR vendor;
|
VENDOR vendor;
|
||||||
};
|
};
|
||||||
|
|
||||||
int setAttribute(struct ascii* art, int type, char* value) {
|
void setAttribute(struct ascii* art, int type, char* value) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i < ATTRIBUTE_COUNT && type != ATTRIBUTE_LIST[i])
|
while(i < ATTRIBUTE_COUNT && type != ATTRIBUTE_LIST[i])
|
||||||
i++;
|
i++;
|
||||||
if(i == ATTRIBUTE_COUNT)
|
if(i != ATTRIBUTE_COUNT)
|
||||||
return BOOLEAN_FALSE;
|
art->atributes[i] = value;
|
||||||
art->atributes[i] = value;
|
else
|
||||||
return BOOLEAN_TRUE;
|
printBug("Setting attribute failed because it was not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ascii* set_ascii(VENDOR cpuVendor, STYLE style) {
|
struct ascii* set_ascii(VENDOR cpuVendor, STYLE style) {
|
||||||
@@ -73,8 +75,8 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style) {
|
|||||||
|
|
||||||
struct ascii* art = malloc(sizeof(struct ascii));
|
struct ascii* art = malloc(sizeof(struct ascii));
|
||||||
art->vendor = cpuVendor;
|
art->vendor = cpuVendor;
|
||||||
|
|
||||||
if(cpuVendor == VENDOR_INTEL) {
|
if(cpuVendor == VENDOR_INTEL) {
|
||||||
/*** CHECK STYLE ***/
|
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case STYLE_EMPTY:
|
case STYLE_EMPTY:
|
||||||
case STYLE_DEFAULT:
|
case STYLE_DEFAULT:
|
||||||
@@ -85,35 +87,16 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style) {
|
|||||||
strcpy(art->color1,COL_INTEL_DARK_1);
|
strcpy(art->color1,COL_INTEL_DARK_1);
|
||||||
strcpy(art->color2,COL_INTEL_DARK_2);
|
strcpy(art->color2,COL_INTEL_DARK_2);
|
||||||
break;
|
break;
|
||||||
|
case STYLE_NONE:
|
||||||
|
strcpy(art->color1,COL_NONE);
|
||||||
|
strcpy(art->color2,COL_NONE);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
printBug("Found invalid style (%d)",style);
|
printBug("Found invalid style (%d)",style);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** COPY ASCII-ART ***/
|
|
||||||
strcpy(art->art[0],INTEL1);
|
|
||||||
strcpy(art->art[1],INTEL2);
|
|
||||||
strcpy(art->art[2],INTEL3);
|
|
||||||
strcpy(art->art[3],INTEL4);
|
|
||||||
strcpy(art->art[4],INTEL5);
|
|
||||||
strcpy(art->art[5],INTEL6);
|
|
||||||
strcpy(art->art[6],INTEL7);
|
|
||||||
strcpy(art->art[7],INTEL8);
|
|
||||||
strcpy(art->art[8],INTEL9);
|
|
||||||
strcpy(art->art[9],INTEL10);
|
|
||||||
strcpy(art->art[10],INTEL11);
|
|
||||||
strcpy(art->art[11],INTEL12);
|
|
||||||
strcpy(art->art[12],INTEL13);
|
|
||||||
strcpy(art->art[13],INTEL14);
|
|
||||||
strcpy(art->art[14],INTEL15);
|
|
||||||
strcpy(art->art[15],INTEL16);
|
|
||||||
strcpy(art->art[16],INTEL17);
|
|
||||||
strcpy(art->art[17],INTEL18);
|
|
||||||
strcpy(art->art[18],INTEL19);
|
|
||||||
strcpy(art->art[19],INTEL20);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/*** CHECK STYLE ***/
|
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case STYLE_EMPTY:
|
case STYLE_EMPTY:
|
||||||
case STYLE_DEFAULT:
|
case STYLE_DEFAULT:
|
||||||
@@ -124,37 +107,27 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style) {
|
|||||||
strcpy(art->color1,COL_AMD_DARK_1);
|
strcpy(art->color1,COL_AMD_DARK_1);
|
||||||
strcpy(art->color2,COL_AMD_DARK_2);
|
strcpy(art->color2,COL_AMD_DARK_2);
|
||||||
break;
|
break;
|
||||||
|
case STYLE_NONE:
|
||||||
|
strcpy(art->color1,COL_NONE);
|
||||||
|
strcpy(art->color2,COL_NONE);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
printBug("Found invalid style (%d)",style);
|
printBug("Found invalid style (%d)",style);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(art->art[0],AMD1);
|
|
||||||
strcpy(art->art[1],AMD2);
|
|
||||||
strcpy(art->art[2],AMD3);
|
|
||||||
strcpy(art->art[3],AMD4);
|
|
||||||
strcpy(art->art[4],AMD5);
|
|
||||||
strcpy(art->art[5],AMD6);
|
|
||||||
strcpy(art->art[6],AMD7);
|
|
||||||
strcpy(art->art[7],AMD8);
|
|
||||||
strcpy(art->art[8],AMD9);
|
|
||||||
strcpy(art->art[9],AMD10);
|
|
||||||
strcpy(art->art[10],AMD11);
|
|
||||||
strcpy(art->art[11],AMD12);
|
|
||||||
strcpy(art->art[12],AMD13);
|
|
||||||
strcpy(art->art[13],AMD14);
|
|
||||||
strcpy(art->art[14],AMD15);
|
|
||||||
strcpy(art->art[15],AMD16);
|
|
||||||
strcpy(art->art[16],AMD17);
|
|
||||||
strcpy(art->art[17],AMD18);
|
|
||||||
strcpy(art->art[18],AMD19);
|
|
||||||
strcpy(art->art[19],AMD20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char tmp[NUMBER_OF_LINES*LINE_SIZE];
|
||||||
|
if(cpuVendor == VENDOR_INTEL) strcpy(tmp, INTEL_ASCII);
|
||||||
|
else strcpy(tmp, AMD_ASCII);
|
||||||
|
for(int i=0; i < NUMBER_OF_LINES; i++)
|
||||||
|
strncpy(art->art[i], tmp + i*LINE_SIZE, LINE_SIZE);
|
||||||
|
|
||||||
return art;
|
return art;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_ascii_intel(struct ascii* art) {
|
void print_ascii_intel(struct ascii* art) {
|
||||||
int flag = BOOLEAN_FALSE;
|
bool flag = false;
|
||||||
|
|
||||||
for(int n=0;n<NUMBER_OF_LINES;n++) {
|
for(int n=0;n<NUMBER_OF_LINES;n++) {
|
||||||
|
|
||||||
@@ -162,7 +135,7 @@ void print_ascii_intel(struct ascii* art) {
|
|||||||
for(int i=0;i<LINE_SIZE;i++) {
|
for(int i=0;i<LINE_SIZE;i++) {
|
||||||
if(flag) {
|
if(flag) {
|
||||||
if(art->art[n][i] == ' ') {
|
if(art->art[n][i] == ' ') {
|
||||||
flag = BOOLEAN_FALSE;
|
flag = false;
|
||||||
printf("%c",art->art[n][i]);
|
printf("%c",art->art[n][i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -170,7 +143,7 @@ void print_ascii_intel(struct ascii* art) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(art->art[n][i] != ' ') {
|
if(art->art[n][i] != ' ') {
|
||||||
flag = BOOLEAN_TRUE;
|
flag = true;
|
||||||
printf("%s%c" RESET,art->color2,art->art[n][i]);
|
printf("%s%c" RESET,art->color2,art->art[n][i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -4,10 +4,7 @@
|
|||||||
#include "standart.h"
|
#include "standart.h"
|
||||||
#include "ascii.h"
|
#include "ascii.h"
|
||||||
|
|
||||||
#define BOOLEAN_TRUE 1
|
#define ATTRIBUTE_COUNT 12
|
||||||
#define BOOLEAN_FALSE 0
|
|
||||||
|
|
||||||
#define ATTRIBUTE_COUNT 12
|
|
||||||
#define ATTRIBUTE_NAME 0
|
#define ATTRIBUTE_NAME 0
|
||||||
#define ATTRIBUTE_FREQUENCY 1
|
#define ATTRIBUTE_FREQUENCY 1
|
||||||
#define ATTRIBUTE_NCORES 2
|
#define ATTRIBUTE_NCORES 2
|
||||||
@@ -22,18 +19,19 @@
|
|||||||
#define ATTRIBUTE_PEAK 11
|
#define ATTRIBUTE_PEAK 11
|
||||||
|
|
||||||
typedef int STYLE;
|
typedef int STYLE;
|
||||||
#define STYLES_COUNT 2
|
#define STYLES_COUNT 3
|
||||||
|
|
||||||
#define STYLE_EMPTY -2
|
#define STYLE_EMPTY -2
|
||||||
#define STYLE_INVALID -1
|
#define STYLE_INVALID -1
|
||||||
#define STYLE_DEFAULT 0
|
#define STYLE_DEFAULT 0
|
||||||
#define STYLE_DARK 1
|
#define STYLE_DARK 1
|
||||||
|
#define STYLE_NONE 2
|
||||||
|
|
||||||
struct ascii;
|
struct ascii;
|
||||||
|
|
||||||
static const int STYLES_CODE_LIST [STYLES_COUNT] = {STYLE_DEFAULT, STYLE_DARK};
|
static const int STYLES_CODE_LIST [STYLES_COUNT] = {STYLE_DEFAULT, STYLE_DARK};
|
||||||
struct ascii* set_ascii(VENDOR cpuVendor, STYLE style);
|
struct ascii* set_ascii(VENDOR cpuVendor, STYLE style);
|
||||||
void print_ascii(struct ascii* art);
|
void print_ascii(struct ascii* art);
|
||||||
int setAttribute(struct ascii* art, int type, char* value);
|
void setAttribute(struct ascii* art, int type, char* value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user