mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Logo (Builtin): improve performance on Windows
This commit is contained in:
+23
-19
@@ -59,33 +59,35 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
|
||||
|
||||
uint32_t currentlineLength = 0;
|
||||
|
||||
if (instance.config.brightColor)
|
||||
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreateA(2048);
|
||||
|
||||
ffPrintCharTimes('\n', options->paddingTop);
|
||||
ffPrintCharTimes(' ', options->paddingLeft);
|
||||
if (instance.config.brightColor)
|
||||
ffStrbufAppendS(&result, FASTFETCH_TEXT_MODIFIER_BOLT);
|
||||
|
||||
ffStrbufAppendNC(&result, options->paddingTop, '\n');
|
||||
ffStrbufAppendNC(&result, options->paddingLeft, ' ');
|
||||
|
||||
instance.state.logoHeight = options->paddingTop;
|
||||
|
||||
//Use logoColor[0] as the default color
|
||||
if(doColorReplacement)
|
||||
ffPrintColor(&options->colors[0]);
|
||||
ffStrbufAppendF(&result, "\e[%sm", options->colors[0].chars);
|
||||
|
||||
while(*data != '\0')
|
||||
{
|
||||
//We are at the end of a line. Print paddings and update max line length
|
||||
if(*data == '\n' || (*data == '\r' && *(data + 1) == '\n'))
|
||||
{
|
||||
ffPrintCharTimes(' ', options->paddingRight);
|
||||
ffStrbufAppendNC(&result, options->paddingRight, ' ');
|
||||
|
||||
//We have \r\n, skip the \r
|
||||
if(*data == '\r')
|
||||
++data;
|
||||
|
||||
putchar('\n');
|
||||
ffStrbufAppendC(&result, '\n');
|
||||
++data;
|
||||
|
||||
ffPrintCharTimes(' ', options->paddingLeft);
|
||||
ffStrbufAppendNC(&result, options->paddingLeft, ' ');
|
||||
|
||||
if(currentlineLength > instance.state.logoWidth)
|
||||
instance.state.logoWidth = currentlineLength;
|
||||
@@ -98,7 +100,7 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
|
||||
//Always print tabs as 4 spaces, to have consistent spacing
|
||||
if(*data == '\t')
|
||||
{
|
||||
ffPrintCharTimes(' ', 4);
|
||||
ffStrbufAppendNC(&result, 4, ' ');
|
||||
++data;
|
||||
continue;
|
||||
}
|
||||
@@ -108,16 +110,16 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
|
||||
{
|
||||
const char* start = data;
|
||||
|
||||
fputs("\e[", stdout);
|
||||
ffStrbufAppendS(&result, "\e[");
|
||||
data += 2;
|
||||
|
||||
while(isdigit(*data) || *data == ';')
|
||||
putchar(*data++); // number
|
||||
ffStrbufAppendC(&result, *data++); // number
|
||||
|
||||
//We have a valid control sequence, print it and continue with next char
|
||||
if(isascii(*data))
|
||||
{
|
||||
putchar(*data++); // single letter, end of control sequence
|
||||
ffStrbufAppendC(&result, *data++); // single letter, end of control sequence
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -135,7 +137,7 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
|
||||
//If we have $$, or $\0, print it as single $
|
||||
if(*data == '$' || *data == '\0')
|
||||
{
|
||||
putchar('$');
|
||||
ffStrbufAppendC(&result, '$');
|
||||
++currentlineLength;
|
||||
++data;
|
||||
continue;
|
||||
@@ -147,13 +149,13 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
|
||||
//If the index is valid, print the color. Otherwise continue as normal
|
||||
if(index < 0 || index >= FASTFETCH_LOGO_MAX_COLORS)
|
||||
{
|
||||
putchar('$');
|
||||
ffStrbufAppendC(&result, '$');
|
||||
++currentlineLength;
|
||||
//Don't continue here, we want to print the current char as unicode
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintColor(&options->colors[index]);
|
||||
ffStrbufAppendF(&result, "\e[%sm", options->colors[index].chars);
|
||||
++data;
|
||||
continue;
|
||||
}
|
||||
@@ -182,11 +184,11 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
|
||||
if(*data == '\0')
|
||||
break;
|
||||
|
||||
putchar(*data++);
|
||||
ffStrbufAppendC(&result, *data++);
|
||||
}
|
||||
}
|
||||
|
||||
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
|
||||
ffStrbufAppendS(&result, FASTFETCH_TEXT_MODIFIER_RESET);
|
||||
|
||||
if(!options->separate)
|
||||
{
|
||||
@@ -197,13 +199,15 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
|
||||
instance.state.logoWidth += options->paddingLeft + options->paddingRight;
|
||||
|
||||
//Go to the leftmost position and go up the height
|
||||
printf("\e[1G\e[%uA", instance.state.logoHeight);
|
||||
ffStrbufAppendF(&result, "\e[1G\e[%uA", instance.state.logoHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.state.logoWidth = instance.state.logoHeight = 0;
|
||||
ffPrintCharTimes('\n', options->paddingRight);
|
||||
ffStrbufAppendNC(&result, options->paddingRight, '\n');
|
||||
}
|
||||
|
||||
ffWriteFDBuffer(FFUnixFD2NativeFD(STDOUT_FILENO), &result);
|
||||
}
|
||||
|
||||
static void logoApplyColors(const FFlogo* logo)
|
||||
|
||||
Reference in New Issue
Block a user