mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 09:33:39 +01:00
Font: support JSON config
This commit is contained in:
@@ -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