mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[v0.99] Center automatically logo and text, when logo is longer than text and viceversa (before this commit only the first case was supported)
This commit is contained in:
@@ -19,25 +19,12 @@ struct ascii_logo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define ASCII_AMD \
|
#define ASCII_AMD \
|
||||||
" \
|
"$C1 @@@@ @@@ @@@ @@@@@@@@ $C2############ \
|
||||||
\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
$C1 @@@@ @@@ @@@ @@@@@@@@ $C2############ \
|
|
||||||
$C1 @@@@@@ @@@@@ @@@@@ @@@ @@@ $C2########## \
|
$C1 @@@@@@ @@@@@ @@@@@ @@@ @@@ $C2########## \
|
||||||
$C1 @@@ @@@ @@@@@@@@@@@@@ @@@ @@ $C2# ##### \
|
$C1 @@@ @@@ @@@@@@@@@@@@@ @@@ @@ $C2# ##### \
|
||||||
$C1 @@@ @@@ @@@ @@@ @@@ @@@ @@ $C2### ##### \
|
$C1 @@@ @@@ @@@ @@@ @@@ @@@ @@ $C2### ##### \
|
||||||
$C1 @@@@@@@@@@@@ @@@ @@@ @@@ @@@ $C2######### ### \
|
$C1 @@@@@@@@@@@@ @@@ @@@ @@@ @@@ $C2######### ### \
|
||||||
$C1 @@@ @@@ @@@ @@@ @@@@@@@@@ $C2######## ## \
|
$C1 @@@ @@@ @@@ @@@ @@@@@@@@@ $C2######## ## "
|
||||||
\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
"
|
|
||||||
|
|
||||||
// 1 2 3 4 5 6
|
// 1 2 3 4 5 6
|
||||||
// 123456789012345678901234567890123456789012345678901234567890
|
// 123456789012345678901234567890123456789012345678901234567890
|
||||||
@@ -234,7 +221,7 @@ $C1 ######################### \
|
|||||||
|
|
||||||
// LOGO W H COLORS LOGO (>0 && <10) COLORS TEXT (=2)
|
// LOGO W H COLORS LOGO (>0 && <10) COLORS TEXT (=2)
|
||||||
// --------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------
|
||||||
static struct ascii_logo logo_amd = { ASCII_AMD, 62, 19, {COLOR_WHITE, COLOR_GREEN}, {COLOR_WHITE, COLOR_GREEN} };
|
static struct ascii_logo logo_amd = { ASCII_AMD, 62, 6, {COLOR_WHITE, COLOR_GREEN}, {COLOR_WHITE, COLOR_GREEN} };
|
||||||
static struct ascii_logo logo_intel = { ASCII_INTEL, 62, 19, {COLOR_CYAN}, {COLOR_CYAN, COLOR_WHITE} };
|
static struct ascii_logo logo_intel = { ASCII_INTEL, 62, 19, {COLOR_CYAN}, {COLOR_CYAN, COLOR_WHITE} };
|
||||||
static struct ascii_logo logo_snapd = { ASCII_SNAPD, 62, 19, {COLOR_RED, COLOR_WHITE}, {COLOR_RED, COLOR_WHITE} };
|
static struct ascii_logo logo_snapd = { ASCII_SNAPD, 62, 19, {COLOR_RED, COLOR_WHITE}, {COLOR_RED, COLOR_WHITE} };
|
||||||
static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19, {COLOR_BLUE, COLOR_YELLOW}, {COLOR_BLUE, COLOR_YELLOW} };
|
static struct ascii_logo logo_mtk = { ASCII_MTK, 62, 19, {COLOR_BLUE, COLOR_YELLOW}, {COLOR_BLUE, COLOR_YELLOW} };
|
||||||
|
|||||||
@@ -322,22 +322,31 @@ void print_ascii_x86(struct ascii* art, uint32_t la) {
|
|||||||
int attr_type;
|
int attr_type;
|
||||||
char* attr_value;
|
char* attr_value;
|
||||||
uint32_t space_right;
|
uint32_t space_right;
|
||||||
uint32_t space_up = (logo->height - art->n_attributes_set)/2;
|
int32_t space_up = ((int)logo->height - (int)art->n_attributes_set)/2;
|
||||||
uint32_t space_down = logo->height - art->n_attributes_set - space_up;
|
int32_t space_down = (int)logo->height - (int)art->n_attributes_set - (int)space_up;
|
||||||
uint32_t logo_pos = 0;
|
uint32_t logo_pos = 0;
|
||||||
|
int32_t iters = max(logo->height, art->n_attributes_set);
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
for(uint32_t n=0; n < logo->height; n++) {
|
for(int32_t n=0; n < iters; n++) {
|
||||||
for(uint32_t i=0; i < logo->width; i++) {
|
// 1. Print logo
|
||||||
if(logo->art[logo_pos] == '$' && logo->art[logo_pos+1] == 'C') {
|
if(space_up > 0 || (space_up + n >= 0 && n + space_down < (int)logo->height)) {
|
||||||
parse_print_color(logo, &logo_pos);
|
for(uint32_t i=0; i < logo->width; i++) {
|
||||||
|
if(logo->art[logo_pos] == '$' && logo->art[logo_pos+1] == 'C') {
|
||||||
|
parse_print_color(logo, &logo_pos);
|
||||||
|
}
|
||||||
|
printf("%c", logo->art[logo_pos]);
|
||||||
|
logo_pos++;
|
||||||
}
|
}
|
||||||
printf("%c", logo->art[logo_pos]);
|
printf("%s", art->reset);
|
||||||
logo_pos++;
|
}
|
||||||
|
else {
|
||||||
|
// If logo should not be printed, fill with spaces
|
||||||
|
printf("%*c", logo->width, ' ');
|
||||||
}
|
}
|
||||||
printf("%s", art->reset);
|
|
||||||
|
|
||||||
if(n > space_up-1 && n < logo->height - space_down) {
|
// 2. Print text
|
||||||
|
if(space_up < 0 || (n > space_up-1 && n < (int)logo->height - space_down)) {
|
||||||
attr_type = art->attributes[attr_to_print]->type;
|
attr_type = art->attributes[attr_to_print]->type;
|
||||||
attr_value = art->attributes[attr_to_print]->value;
|
attr_value = art->attributes[attr_to_print]->value;
|
||||||
attr_to_print++;
|
attr_to_print++;
|
||||||
@@ -355,7 +364,6 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs) {
|
|||||||
if(art == NULL)
|
if(art == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
struct ascii_logo* logo = art->art;
|
|
||||||
char* uarch = get_str_uarch(cpu);
|
char* uarch = get_str_uarch(cpu);
|
||||||
char* manufacturing_process = get_str_process(cpu);
|
char* manufacturing_process = get_str_process(cpu);
|
||||||
char* sockets = get_str_sockets(cpu->topo);
|
char* sockets = get_str_sockets(cpu->topo);
|
||||||
@@ -398,11 +406,6 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs) {
|
|||||||
}
|
}
|
||||||
setAttribute(art,ATTRIBUTE_PEAK,pp);
|
setAttribute(art,ATTRIBUTE_PEAK,pp);
|
||||||
|
|
||||||
if(art->n_attributes_set > logo->height) {
|
|
||||||
printBug("The number of attributes set is bigger than the max that can be displayed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t longest_attribute = longest_attribute_length(art);
|
uint32_t longest_attribute = longest_attribute_length(art);
|
||||||
print_ascii_x86(art, longest_attribute);
|
print_ascii_x86(art, longest_attribute);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user