mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
prettier cursor output
This commit is contained in:
+18
-5
@@ -3,9 +3,16 @@
|
||||
#define FF_CURSOR_MODULE_NAME "Cursor"
|
||||
#define FF_CURSOR_NUM_FORMAT_ARGS 2
|
||||
|
||||
static void printCursor(FFinstance* instance, const FFstrbuf* cursorTheme, const FFstrbuf* cursorSize)
|
||||
static void printCursor(FFinstance* instance, FFstrbuf* cursorTheme, const FFstrbuf* cursorSize)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey);
|
||||
|
||||
ffStrbufRemoveIgnCaseEndS(cursorTheme, "cursors");
|
||||
ffStrbufRemoveIgnCaseEndS(cursorTheme, "cursor");
|
||||
ffStrbufTrimRight(cursorTheme, '_');
|
||||
if(cursorTheme->length == 0)
|
||||
ffStrbufAppendS(cursorTheme, "default");
|
||||
|
||||
ffStrbufWriteTo(cursorTheme, stdout);
|
||||
|
||||
if(cursorSize != NULL && cursorSize->length > 0)
|
||||
@@ -34,7 +41,13 @@ static void printCursorGTK(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
printCursor(instance, >k->cursor, >k->cursorSize);
|
||||
//gtk->cursor is const, so we don't want to modify it
|
||||
FFstrbuf theme;
|
||||
ffStrbufInitCopy(&theme, >k->cursor);
|
||||
|
||||
printCursor(instance, &theme, >k->cursorSize);
|
||||
|
||||
ffStrbufDestroy(&theme);
|
||||
}
|
||||
|
||||
static void printCursorPlasma(FFinstance* instance)
|
||||
@@ -162,9 +175,6 @@ static bool printCursorFromEnv(FFinstance* instance)
|
||||
|
||||
void ffPrintCursor(FFinstance* instance)
|
||||
{
|
||||
if(printCursorFromEnv(instance))
|
||||
return;
|
||||
|
||||
const FFWMDEResult* wmde = ffDetectWMDE(instance);
|
||||
|
||||
if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "KDE Plasma") == 0)
|
||||
@@ -185,6 +195,9 @@ void ffPrintCursor(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
if(printCursorFromEnv(instance))
|
||||
return;
|
||||
|
||||
//User config
|
||||
if(printCursorFromXDG(instance, true))
|
||||
return;
|
||||
|
||||
@@ -569,6 +569,40 @@ bool ffStrbufEndsWithS(const FFstrbuf* strbuf, const char* end)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool testEndsWithIgnCaseS(const FFstrbuf* strbuf, const char* end, uint32_t* endLength)
|
||||
{
|
||||
*endLength = strlen(end);
|
||||
|
||||
if(*endLength > strbuf->length)
|
||||
return false;
|
||||
|
||||
for(uint32_t i = 0; i < *endLength; ++i)
|
||||
{
|
||||
if(tolower(strbuf->chars[strbuf->length - *endLength + i]) != tolower(end[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ffStrbufEndsWithIgnCaseS(const FFstrbuf* strbuf, const char* end)
|
||||
{
|
||||
uint32_t dummy;
|
||||
return testEndsWithIgnCaseS(strbuf, end, &dummy);
|
||||
}
|
||||
|
||||
bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end)
|
||||
{
|
||||
uint32_t endLength;
|
||||
if(testEndsWithIgnCaseS(strbuf, end, &endLength))
|
||||
{
|
||||
ffStrbufSubstrBefore(strbuf, strbuf->length - endLength);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffStrbufRecalculateLength(FFstrbuf* strbuf)
|
||||
{
|
||||
for(strbuf->length = 0; strbuf->chars[strbuf->length] != '\0'; ++strbuf->length);
|
||||
|
||||
@@ -96,6 +96,10 @@ bool ffStrbufStartsWithIgnCaseNS(const FFstrbuf* strbuf, uint32_t length, const
|
||||
|
||||
bool ffStrbufEndsWithS(const FFstrbuf* strbuf, const char* end);
|
||||
|
||||
bool ffStrbufEndsWithIgnCaseS(const FFstrbuf* strbuf, const char* end);
|
||||
|
||||
bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end);
|
||||
|
||||
void ffStrbufRecalculateLength(FFstrbuf* strbuf);
|
||||
|
||||
void ffStrbufDestroy(FFstrbuf* strbuf);
|
||||
|
||||
Reference in New Issue
Block a user