mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
@@ -1,4 +1,6 @@
|
||||
#include "fastfetch.h"
|
||||
#include "util/FFlist.h"
|
||||
#include "util/FFstrbuf.h"
|
||||
#include "common/font.h"
|
||||
|
||||
#include <string.h>
|
||||
@@ -192,6 +194,21 @@ void ffFontInitValues(FFfont* font, const char* name, const char* size)
|
||||
fontInitPretty(font);
|
||||
}
|
||||
|
||||
void ffFontInitMoveValues(FFfont* font, FFstrbuf* name, FFstrbuf* size, FFstrbuf* style)
|
||||
{
|
||||
ffFontInit(font);
|
||||
|
||||
if (name) ffStrbufInitMove(&font->name, name);
|
||||
if (size) ffStrbufInitMove(&font->size, size);
|
||||
if (style)
|
||||
{
|
||||
FFstrbuf* styleBuf = FF_LIST_ADD(FFstrbuf, font->styles);
|
||||
ffStrbufInitMove(styleBuf, style);
|
||||
}
|
||||
|
||||
fontInitPretty(font);
|
||||
}
|
||||
|
||||
void ffFontInitWithSpace(FFfont* font, const char* rawName)
|
||||
{
|
||||
const char* pspace = strrchr(rawName, ' ');
|
||||
|
||||
@@ -15,6 +15,7 @@ void ffFontInit(FFfont* font);
|
||||
void ffFontInitQt(FFfont* font, const char* data);
|
||||
void ffFontInitPango(FFfont* font, const char* data);
|
||||
void ffFontInitValues(FFfont* font, const char* name, const char* size);
|
||||
void ffFontInitMoveValues(FFfont* font, FFstrbuf* name, FFstrbuf* size, FFstrbuf* style);
|
||||
void ffFontInitWithSpace(FFfont* font, const char* rawName);
|
||||
void ffFontDestroy(FFfont* font);
|
||||
|
||||
|
||||
@@ -8,13 +8,18 @@
|
||||
|
||||
static void detectAlacritty(FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
// Maybe using a toml parser to read the config file is better?
|
||||
// https://github.com/cktan/tomlc17
|
||||
|
||||
// Doc: https://alacritty.org/config-alacritty.html#s26
|
||||
FF_STRBUF_AUTO_DESTROY fontNormal = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontFamily = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontStyle = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate();
|
||||
|
||||
do {
|
||||
// Latest alacritty uses toml instead of yaml
|
||||
FFpropquery fontQueryToml[] = {
|
||||
{"family =", &fontName},
|
||||
{"normal =", &fontNormal},
|
||||
{"size =", &fontSize},
|
||||
};
|
||||
|
||||
@@ -25,29 +30,39 @@ static void detectAlacritty(FFTerminalFontResult* terminalFont)
|
||||
break;
|
||||
if(ffParsePropFileConfigValues(".alacritty.toml", 2, fontQueryToml))
|
||||
break;
|
||||
|
||||
FFpropquery fontQueryYaml[] = {
|
||||
{"family:", &fontName},
|
||||
{"size:", &fontSize},
|
||||
};
|
||||
|
||||
if(ffParsePropFileConfigValues("alacritty/alacritty.yml", 2, fontQueryYaml))
|
||||
break;
|
||||
if(ffParsePropFileConfigValues("alacritty.yml", 2, fontQueryYaml))
|
||||
break;
|
||||
if(ffParsePropFileConfigValues(".alacritty.yml", 2, fontQueryYaml))
|
||||
break;
|
||||
} while (false);
|
||||
|
||||
//by default alacritty uses its own font called alacritty
|
||||
if(fontName.length == 0)
|
||||
ffStrbufAppendS(&fontName, "alacritty");
|
||||
if(fontNormal.length > 0)
|
||||
{
|
||||
// { family = "Fira Code", style = "Medium" }
|
||||
ffStrbufTrimSpace(&fontNormal);
|
||||
ffStrbufTrimRight(&fontNormal, '}');
|
||||
ffStrbufTrimLeft(&fontNormal, '{');
|
||||
ffStrbufTrimSpace(&fontNormal);
|
||||
|
||||
// family = "Fira Code", style = "Medium"
|
||||
ffStrbufReplaceAllC(&fontNormal, ',', '\n'); // Assume no commas in font names
|
||||
ffParsePropLines(fontNormal.chars, "family =", &fontFamily);
|
||||
ffParsePropLines(fontNormal.chars, "style =", &fontStyle);
|
||||
}
|
||||
|
||||
if (fontFamily.length == 0)
|
||||
{
|
||||
#if __APPLE__
|
||||
ffStrbufSetStatic(&fontFamily, "Menlo");
|
||||
#elif _WIN32
|
||||
ffStrbufSetStatic(&fontFamily, "Consolas");
|
||||
#else
|
||||
ffStrbufSetStatic(&fontFamily, "monospace");
|
||||
#endif
|
||||
}
|
||||
if (fontStyle.length == 0)
|
||||
ffStrbufSetStatic(&fontStyle, "Regular");
|
||||
|
||||
// the default font size is 11
|
||||
if(fontSize.length == 0)
|
||||
ffStrbufAppendS(&fontSize, "11");
|
||||
ffStrbufSetStatic(&fontSize, "11.25");
|
||||
|
||||
ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars);
|
||||
ffFontInitMoveValues(&terminalFont->font, &fontFamily, &fontSize, &fontStyle);
|
||||
}
|
||||
|
||||
static void detectGhostty(const FFstrbuf* exe, FFTerminalFontResult* terminalFont)
|
||||
|
||||
Reference in New Issue
Block a user