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:
@@ -1,20 +1,22 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "printer.h"
|
||||
#include "ascii.h"
|
||||
#include "global.h"
|
||||
|
||||
#define COL_NONE ""
|
||||
#define COL_INTEL_DEFAULT_1 "\x1b[36;1m"
|
||||
#define COL_INTEL_DEFAULT_2 "\x1b[37;1m"
|
||||
#define COL_INTEL_DARK_1 "\x1b[34;1m"
|
||||
#define COL_INTEL_DARK_2 "\x1b[30m"
|
||||
#define COL_AMD_DEFAULT_1 "\x1b[37;1m"
|
||||
#define COL_AMD_DEFAULT_2 "\x1b[31;1m"
|
||||
#define COL_AMD_DARK_1 "\x1b[30;1m"
|
||||
#define COL_AMD_DARK_2 "\x1b[32;1m"
|
||||
#define RESET "\x1b[0m"
|
||||
#define COL_INTEL_DARK_1 "\x1b[34;1m"
|
||||
#define COL_INTEL_DARK_2 "\x1b[30m"
|
||||
#define COL_AMD_DEFAULT_1 "\x1b[37;1m"
|
||||
#define COL_AMD_DEFAULT_2 "\x1b[31;1m"
|
||||
#define COL_AMD_DARK_1 "\x1b[30;1m"
|
||||
#define COL_AMD_DARK_2 "\x1b[32;1m"
|
||||
#define RESET "\x1b[0m"
|
||||
|
||||
#define TITLE_NAME "Name: "
|
||||
#define TITLE_FREQUENCY "Frequency: "
|
||||
@@ -53,14 +55,14 @@ struct ascii {
|
||||
VENDOR vendor;
|
||||
};
|
||||
|
||||
int setAttribute(struct ascii* art, int type, char* value) {
|
||||
void setAttribute(struct ascii* art, int type, char* value) {
|
||||
int i = 0;
|
||||
while(i < ATTRIBUTE_COUNT && type != ATTRIBUTE_LIST[i])
|
||||
i++;
|
||||
if(i == ATTRIBUTE_COUNT)
|
||||
return BOOLEAN_FALSE;
|
||||
art->atributes[i] = value;
|
||||
return BOOLEAN_TRUE;
|
||||
if(i != ATTRIBUTE_COUNT)
|
||||
art->atributes[i] = value;
|
||||
else
|
||||
printBug("Setting attribute failed because it was not found");
|
||||
}
|
||||
|
||||
struct ascii* set_ascii(VENDOR cpuVendor, STYLE style) {
|
||||
@@ -73,9 +75,9 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style) {
|
||||
|
||||
struct ascii* art = malloc(sizeof(struct ascii));
|
||||
art->vendor = cpuVendor;
|
||||
|
||||
if(cpuVendor == VENDOR_INTEL) {
|
||||
/*** CHECK STYLE ***/
|
||||
switch (style) {
|
||||
switch (style) {
|
||||
case STYLE_EMPTY:
|
||||
case STYLE_DEFAULT:
|
||||
strcpy(art->color1,COL_INTEL_DEFAULT_1);
|
||||
@@ -85,35 +87,16 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style) {
|
||||
strcpy(art->color1,COL_INTEL_DARK_1);
|
||||
strcpy(art->color2,COL_INTEL_DARK_2);
|
||||
break;
|
||||
case STYLE_NONE:
|
||||
strcpy(art->color1,COL_NONE);
|
||||
strcpy(art->color2,COL_NONE);
|
||||
break;
|
||||
default:
|
||||
printBug("Found invalid style (%d)",style);
|
||||
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 {
|
||||
/*** CHECK STYLE ***/
|
||||
switch (style) {
|
||||
case STYLE_EMPTY:
|
||||
case STYLE_DEFAULT:
|
||||
@@ -124,37 +107,27 @@ struct ascii* set_ascii(VENDOR cpuVendor, STYLE style) {
|
||||
strcpy(art->color1,COL_AMD_DARK_1);
|
||||
strcpy(art->color2,COL_AMD_DARK_2);
|
||||
break;
|
||||
case STYLE_NONE:
|
||||
strcpy(art->color1,COL_NONE);
|
||||
strcpy(art->color2,COL_NONE);
|
||||
break;
|
||||
default:
|
||||
printBug("Found invalid style (%d)",style);
|
||||
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;
|
||||
}
|
||||
|
||||
void print_ascii_intel(struct ascii* art) {
|
||||
int flag = BOOLEAN_FALSE;
|
||||
bool flag = false;
|
||||
|
||||
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++) {
|
||||
if(flag) {
|
||||
if(art->art[n][i] == ' ') {
|
||||
flag = BOOLEAN_FALSE;
|
||||
flag = false;
|
||||
printf("%c",art->art[n][i]);
|
||||
}
|
||||
else
|
||||
@@ -170,7 +143,7 @@ void print_ascii_intel(struct ascii* art) {
|
||||
}
|
||||
else {
|
||||
if(art->art[n][i] != ' ') {
|
||||
flag = BOOLEAN_TRUE;
|
||||
flag = true;
|
||||
printf("%s%c" RESET,art->color2,art->art[n][i]);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user