mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 09:33:39 +01:00
TerminalFont: support st
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "common/settings.h"
|
||||
#include "common/properties.h"
|
||||
#include "common/parsing.h"
|
||||
#include "common/io/io.h"
|
||||
#include "detection/terminalshell/terminalshell.h"
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
#include "util/mallocHelper.h"
|
||||
@@ -250,6 +251,38 @@ static void detectXterm(FFTerminalFontResult* terminalFont)
|
||||
ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars);
|
||||
}
|
||||
|
||||
static void detectSt(FFTerminalFontResult* terminalFont, uint32_t pid)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY size = ffStrbufCreateF("/proc/%u/cmdline", pid);
|
||||
FF_STRBUF_AUTO_DESTROY font = ffStrbufCreate();
|
||||
if (!ffAppendFileBuffer(size.chars, &font))
|
||||
{
|
||||
ffStrbufAppendF(&terminalFont->error, "Failed to open %s", size.chars);
|
||||
return;
|
||||
}
|
||||
|
||||
const char* p = memmem(font.chars, font.length, "\0-f", sizeof("\0-f")); // find parameter of `-f`
|
||||
if (!p)
|
||||
{
|
||||
ffStrbufAppendF(&terminalFont->error, "st was not executed with `-f` parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
ffStrbufSubstrAfter(&font, (uint32_t) (p + (sizeof("\0-f") - 1) - font.chars));
|
||||
ffStrbufRecalculateLength(&font);
|
||||
|
||||
// `monospace:size=15` || `monospace` || `:size=15`
|
||||
uint32_t index = ffStrbufFirstIndexS(&font, ":size=");
|
||||
if (index != font.length)
|
||||
{
|
||||
ffStrbufSetS(&size, font.chars + index + strlen(":size="));
|
||||
ffStrbufSubstrBefore(&font, index);
|
||||
}
|
||||
else
|
||||
ffStrbufClear(&size);
|
||||
ffFontInitValues(&terminalFont->font, font.chars, size.chars);
|
||||
}
|
||||
|
||||
void ffDetectTerminalFontPlatform(const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "konsole"))
|
||||
@@ -276,4 +309,6 @@ void ffDetectTerminalFontPlatform(const FFTerminalShellResult* terminalShell, FF
|
||||
detectQTerminal(terminalFont);
|
||||
else if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "xterm"))
|
||||
detectXterm(terminalFont);
|
||||
else if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "st"))
|
||||
detectSt(terminalFont, terminalShell->terminalPid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user