mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
TerminalFont: support JSON config
This commit is contained in:
@@ -118,6 +118,7 @@ static bool parseModuleJsonObject(FFinstance* instance, const char* type, json_o
|
||||
case 'T': {
|
||||
return
|
||||
tryModule(instance, type, module, FF_TERMINAL_MODULE_NAME, ffParseTerminalJsonObject) ||
|
||||
tryModule(instance, type, module, FF_TERMINALFONT_MODULE_NAME, ffParseTerminalFontJsonObject) ||
|
||||
tryModule(instance, type, module, FF_TITLE_MODULE_NAME, ffParseTitleJsonObject) ||
|
||||
false;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "modules/sound/sound.h"
|
||||
#include "modules/swap/swap.h"
|
||||
#include "modules/terminal/terminal.h"
|
||||
#include "modules/terminalfont/terminalfont.h"
|
||||
#include "modules/title/title.h"
|
||||
#include "modules/jsonconfig/jsonconfig.h"
|
||||
#include "modules/uptime/uptime.h"
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "modules/sound/option.h"
|
||||
#include "modules/swap/option.h"
|
||||
#include "modules/terminal/option.h"
|
||||
#include "modules/terminalfont/option.h"
|
||||
#include "modules/title/option.h"
|
||||
#include "modules/uptime/option.h"
|
||||
#include "modules/wifi/option.h"
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/terminalfont/terminalfont.h"
|
||||
|
||||
#define FF_TERMFONT_MODULE_NAME "Terminal Font"
|
||||
#define FF_TERMFONT_NUM_FORMAT_ARGS 4
|
||||
|
||||
void ffPrintTerminalFont(FFinstance* instance)
|
||||
{
|
||||
const FFTerminalFontResult* terminalFont = ffDetectTerminalFont(instance);
|
||||
|
||||
if(terminalFont->error.length > 0)
|
||||
{
|
||||
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "%s", terminalFont->error.chars);
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->config.terminalFont.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont.key);
|
||||
ffStrbufPutTo(&terminalFont->font.pretty, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, FF_TERMFONT_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont->font.pretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont->font.name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont->font.size},
|
||||
{FF_FORMAT_ARG_TYPE_LIST, &terminalFont->font.styles}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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 FFTerminalFontOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFTerminalFontOptions;
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/terminalfont/terminalfont.h"
|
||||
#include "modules/terminalfont/terminalfont.h"
|
||||
|
||||
#define FF_TERMINALFONT_DISPLAY_NAME "Terminal Font"
|
||||
#define FF_TERMINALFONT_NUM_FORMAT_ARGS 4
|
||||
|
||||
void ffPrintTerminalFont(FFinstance* instance, FFTerminalFontOptions* options)
|
||||
{
|
||||
const FFTerminalFontResult* terminalFont = ffDetectTerminalFont(instance);
|
||||
|
||||
if(terminalFont->error.length > 0)
|
||||
{
|
||||
ffPrintError(instance, FF_TERMINALFONT_DISPLAY_NAME, 0, &options->moduleArgs, "%s", terminalFont->error.chars);
|
||||
return;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_TERMINALFONT_DISPLAY_NAME, 0, &options->moduleArgs.key);
|
||||
ffStrbufPutTo(&terminalFont->font.pretty, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_TERMINALFONT_DISPLAY_NAME, 0, &options->moduleArgs, FF_TERMINALFONT_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont->font.pretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont->font.name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont->font.size},
|
||||
{FF_FORMAT_ARG_TYPE_LIST, &terminalFont->font.styles}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ffInitTerminalFontOptions(FFTerminalFontOptions* options)
|
||||
{
|
||||
options->moduleName = FF_TERMINALFONT_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
bool ffParseTerminalFontCommandOptions(FFTerminalFontOptions* options, const char* key, const char* value)
|
||||
{
|
||||
const char* subKey = ffOptionTestPrefix(key, FF_TERMINALFONT_MODULE_NAME);
|
||||
if (!subKey) return false;
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffDestroyTerminalFontOptions(FFTerminalFontOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseTerminalFontJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFTerminalFontOptions __attribute__((__cleanup__(ffDestroyTerminalFontOptions))) options;
|
||||
ffInitTerminalFontOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_TERMINALFONT_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintTerminalFont(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_TERMINALFONT_MODULE_NAME "TerminalFont"
|
||||
|
||||
void ffPrintTerminalFont(FFinstance* instance, FFTerminalFontOptions* options);
|
||||
void ffInitTerminalFontOptions(FFTerminalFontOptions* options);
|
||||
bool ffParseTerminalFontCommandOptions(FFTerminalFontOptions* options, const char* key, const char* value);
|
||||
void ffDestroyTerminalFontOptions(FFTerminalFontOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseTerminalFontJsonObject(FFinstance* instance, json_object* module);
|
||||
#endif
|
||||
Reference in New Issue
Block a user