mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Font: support JSON config
This commit is contained in:
+1
-1
@@ -278,7 +278,7 @@ set(LIBFASTFETCH_SRC
|
||||
src/modules/datetime/datetime.c
|
||||
src/modules/de.c
|
||||
src/modules/disk/disk.c
|
||||
src/modules/font.c
|
||||
src/modules/font/font.c
|
||||
src/modules/gpu/gpu.c
|
||||
src/modules/host/host.c
|
||||
src/modules/icons.c
|
||||
|
||||
+2
-2
@@ -77,7 +77,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
initModuleArg(&instance->config.wmTheme);
|
||||
initModuleArg(&instance->config.theme);
|
||||
initModuleArg(&instance->config.icons);
|
||||
initModuleArg(&instance->config.font);
|
||||
ffInitFontOptions(&instance->config.font);
|
||||
ffInitCursorOptions(&instance->config.cursor);
|
||||
initModuleArg(&instance->config.terminal);
|
||||
initModuleArg(&instance->config.terminalFont);
|
||||
@@ -304,7 +304,7 @@ static void destroyConfig(FFinstance* instance)
|
||||
destroyModuleArg(&instance->config.wmTheme);
|
||||
destroyModuleArg(&instance->config.theme);
|
||||
destroyModuleArg(&instance->config.icons);
|
||||
destroyModuleArg(&instance->config.font);
|
||||
ffDestroyFontOptions(&instance->config.font);
|
||||
ffDestroyCursorOptions(&instance->config.cursor);
|
||||
destroyModuleArg(&instance->config.terminal);
|
||||
destroyModuleArg(&instance->config.terminalFont);
|
||||
|
||||
+3
-3
@@ -998,7 +998,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else if(optionParseModuleArgs(key, value, "theme", &instance->config.theme)) {}
|
||||
else if(optionParseModuleArgs(key, value, "icons", &instance->config.icons)) {}
|
||||
else if(optionParseModuleArgs(key, value, "wallpaper", &instance->config.wallpaper)) {}
|
||||
else if(optionParseModuleArgs(key, value, "font", &instance->config.font)) {}
|
||||
else if(ffParseFontCommandOptions(&instance->config.font, key, value)) {}
|
||||
else if(ffParseCursorCommandOptions(&instance->config.cursor, key, value)) {}
|
||||
else if(optionParseModuleArgs(key, value, "terminal", &instance->config.terminal)) {}
|
||||
else if(optionParseModuleArgs(key, value, "terminal-font", &instance->config.terminalFont)) {}
|
||||
@@ -1232,8 +1232,8 @@ static void parseStructureCommand(FFinstance* instance, const char* line)
|
||||
ffPrintIcons(instance);
|
||||
else if(strcasecmp(line, "wallpaper") == 0)
|
||||
ffPrintWallpaper(instance);
|
||||
else if(strcasecmp(line, "font") == 0)
|
||||
ffPrintFont(instance);
|
||||
else if(strcasecmp(line, FF_FONT_MODULE_NAME) == 0)
|
||||
ffPrintFont(instance, &instance->config.font);
|
||||
else if(strcasecmp(line, FF_CURSOR_MODULE_NAME) == 0)
|
||||
ffPrintCursor(instance, &instance->config.cursor);
|
||||
else if(strcasecmp(line, "terminal") == 0)
|
||||
|
||||
+1
-2
@@ -102,7 +102,7 @@ typedef struct FFconfig
|
||||
FFModuleArgs wmTheme;
|
||||
FFModuleArgs theme;
|
||||
FFModuleArgs icons;
|
||||
FFModuleArgs font;
|
||||
FFFontOptions font;
|
||||
FFCursorOptions cursor;
|
||||
FFModuleArgs terminal;
|
||||
FFModuleArgs terminalFont;
|
||||
@@ -240,7 +240,6 @@ void ffPrintWMTheme(FFinstance* instance);
|
||||
void ffPrintTheme(FFinstance* instance);
|
||||
void ffPrintIcons(FFinstance* instance);
|
||||
void ffPrintWallpaper(FFinstance* instance);
|
||||
void ffPrintFont(FFinstance* instance);
|
||||
void ffPrintTerminal(FFinstance* instance);
|
||||
void ffPrintTerminalFont(FFinstance* instance);
|
||||
void ffPrintMemory(FFinstance* instance);
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ int main(int argc, char** argv)
|
||||
ffPrintWMTheme(&instance);
|
||||
ffPrintTheme(&instance);
|
||||
ffPrintIcons(&instance);
|
||||
ffPrintFont(&instance);
|
||||
ffPrintFont(&instance, &instance.config.font);
|
||||
ffPrintCursor(&instance, &instance.config.cursor);
|
||||
ffPrintTerminal(&instance);
|
||||
ffPrintTerminalFont(&instance);
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/font/font.h"
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
|
||||
#define FF_FONT_MODULE_NAME "Font"
|
||||
#define FF_FONT_NUM_FORMAT_ARGS (FF_DETECT_FONT_NUM_FONTS + 1)
|
||||
|
||||
void ffPrintFont(FFinstance* instance)
|
||||
{
|
||||
const FFFontResult* font = ffDetectFont(instance);
|
||||
|
||||
if(font->error.length > 0)
|
||||
{
|
||||
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "%s", font->error.chars);
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->config.font.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font.key);
|
||||
ffStrbufPutTo(&font->display, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[0]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[1]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[2]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[3]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->display},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/font/font.h"
|
||||
#include "modules/font/font.h"
|
||||
|
||||
#define FF_FONT_NUM_FORMAT_ARGS (FF_DETECT_FONT_NUM_FONTS + 1)
|
||||
|
||||
void ffPrintFont(FFinstance* instance, FFFontOptions* options)
|
||||
{
|
||||
const FFFontResult* font = ffDetectFont(instance);
|
||||
|
||||
if(font->error.length > 0)
|
||||
{
|
||||
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &options->moduleArgs, "%s", font->error.chars);
|
||||
return;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
ffStrbufPutTo(&font->display, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &options->moduleArgs, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[0]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[1]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[2]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[3]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->display},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ffInitFontOptions(FFFontOptions* options)
|
||||
{
|
||||
options->moduleName = FF_FONT_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
bool ffParseFontCommandOptions(FFFontOptions* options, const char* key, const char* value)
|
||||
{
|
||||
const char* subKey = ffOptionTestPrefix(key, FF_FONT_MODULE_NAME);
|
||||
if (!subKey) return false;
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffDestroyFontOptions(FFFontOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseFontJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFFontOptions __attribute__((__cleanup__(ffDestroyFontOptions))) options;
|
||||
ffInitFontOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintFont(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_FONT_MODULE_NAME "Font"
|
||||
|
||||
void ffPrintFont(FFinstance* instance, FFFontOptions* options);
|
||||
void ffInitFontOptions(FFFontOptions* options);
|
||||
bool ffParseFontCommandOptions(FFFontOptions* options, const char* key, const char* value);
|
||||
void ffDestroyFontOptions(FFFontOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseFontJsonObject(FFinstance* instance, json_object* module);
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
// This file will be included in "fastfetch.h", do NOT put unnecessary things here
|
||||
|
||||
#include "common/option.h"
|
||||
|
||||
typedef struct FFFontOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFFontOptions;
|
||||
@@ -56,6 +56,12 @@ static bool parseModuleJsonObject(FFinstance* instance, const char* type, json_o
|
||||
false;
|
||||
}
|
||||
|
||||
case 'F': {
|
||||
return
|
||||
tryModule(instance, type, module, FF_FONT_MODULE_NAME, ffParseFontJsonObject) ||
|
||||
false;
|
||||
}
|
||||
|
||||
case 'G': {
|
||||
return
|
||||
tryModule(instance, type, module, FF_GAMEPAD_MODULE_NAME, ffParseGamepadJsonObject) ||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "modules/datetime/datetime.h"
|
||||
#include "modules/disk/disk.h"
|
||||
#include "modules/display/display.h"
|
||||
#include "modules/font/font.h"
|
||||
#include "modules/gamepad/gamepad.h"
|
||||
#include "modules/gpu/gpu.h"
|
||||
#include "modules/host/host.h"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "modules/datetime/option.h"
|
||||
#include "modules/disk/option.h"
|
||||
#include "modules/display/option.h"
|
||||
#include "modules/font/option.h"
|
||||
#include "modules/host/option.h"
|
||||
#include "modules/gamepad/option.h"
|
||||
#include "modules/gpu/option.h"
|
||||
|
||||
Reference in New Issue
Block a user