mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Locale: add JSON config support
This commit is contained in:
+1
-1
@@ -284,7 +284,7 @@ set(LIBFASTFETCH_SRC
|
||||
src/modules/icons.c
|
||||
src/modules/gamepad/gamepad.c
|
||||
src/modules/kernel/kernel.c
|
||||
src/modules/locale.c
|
||||
src/modules/locale/locale.c
|
||||
src/modules/localip.c
|
||||
src/modules/memory.c
|
||||
src/modules/opencl.c
|
||||
|
||||
+2
-2
@@ -89,7 +89,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
ffInitDiskOptions(&instance->config.disk);
|
||||
ffInitBatteryOptions(&instance->config.battery);
|
||||
initModuleArg(&instance->config.powerAdapter);
|
||||
initModuleArg(&instance->config.locale);
|
||||
ffInitLocaleOptions(&instance->config.locale);
|
||||
initModuleArg(&instance->config.localIP);
|
||||
initModuleArg(&instance->config.publicIP);
|
||||
initModuleArg(&instance->config.weather);
|
||||
@@ -316,7 +316,7 @@ static void destroyConfig(FFinstance* instance)
|
||||
ffDestroyDiskOptions(&instance->config.disk);
|
||||
ffDestroyBatteryOptions(&instance->config.battery);
|
||||
destroyModuleArg(&instance->config.powerAdapter);
|
||||
destroyModuleArg(&instance->config.locale);
|
||||
ffDestroyLocaleOptions(&instance->config.locale);
|
||||
destroyModuleArg(&instance->config.localIP);
|
||||
destroyModuleArg(&instance->config.publicIP);
|
||||
destroyModuleArg(&instance->config.wallpaper);
|
||||
|
||||
+3
-3
@@ -1010,7 +1010,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else if(ffParseDiskCommandOptions(&instance->config.disk, key, value)) {}
|
||||
else if(ffParseBatteryCommandOptions(&instance->config.battery, key, value)) {}
|
||||
else if(optionParseModuleArgs(key, value, "poweradapter", &instance->config.powerAdapter)) {}
|
||||
else if(optionParseModuleArgs(key, value, "locale", &instance->config.locale)) {}
|
||||
else if(ffParseLocaleCommandOptions(&instance->config.locale, key, value)) {}
|
||||
else if(optionParseModuleArgs(key, value, "localip", &instance->config.localIP)) {}
|
||||
else if(optionParseModuleArgs(key, value, "publicip", &instance->config.publicIP)) {}
|
||||
else if(optionParseModuleArgs(key, value, "weather", &instance->config.weather)) {}
|
||||
@@ -1258,8 +1258,8 @@ static void parseStructureCommand(FFinstance* instance, const char* line)
|
||||
ffPrintBattery(instance, &instance->config.battery);
|
||||
else if(strcasecmp(line, "poweradapter") == 0)
|
||||
ffPrintPowerAdapter(instance);
|
||||
else if(strcasecmp(line, "locale") == 0)
|
||||
ffPrintLocale(instance);
|
||||
else if(strcasecmp(line, FF_LOCALE_MODULE_NAME) == 0)
|
||||
ffPrintLocale(instance, &instance->config.locale);
|
||||
else if(strcasecmp(line, "localip") == 0)
|
||||
ffPrintLocalIp(instance);
|
||||
else if(strcasecmp(line, "publicip") == 0)
|
||||
|
||||
+1
-2
@@ -115,7 +115,7 @@ typedef struct FFconfig
|
||||
FFDiskOptions disk;
|
||||
FFBatteryOptions battery;
|
||||
FFModuleArgs powerAdapter;
|
||||
FFModuleArgs locale;
|
||||
FFLocaleOptions locale;
|
||||
FFModuleArgs localIP;
|
||||
FFModuleArgs publicIP;
|
||||
FFModuleArgs weather;
|
||||
@@ -245,7 +245,6 @@ void ffPrintTerminalFont(FFinstance* instance);
|
||||
void ffPrintMemory(FFinstance* instance);
|
||||
void ffPrintSwap(FFinstance* instance);
|
||||
void ffPrintPowerAdapter(FFinstance* instance);
|
||||
void ffPrintLocale(FFinstance* instance);
|
||||
void ffPrintPlayer(FFinstance* instance);
|
||||
void ffPrintMedia(FFinstance* instance);
|
||||
void ffPrintDateTime(FFinstance* instance, FFDateTimeOptions* options);
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ int main(int argc, char** argv)
|
||||
//ffPrintPublicIp(&instance);
|
||||
//ffPrintWifi(&instance);
|
||||
//ffPrintCPUUsage(&instance, &instance.config.cpuUsage);
|
||||
ffPrintLocale(&instance);
|
||||
ffPrintLocale(&instance, &instance.config.locale);
|
||||
//ffPrintDateTime(&instance);
|
||||
//ffPrintDate(&instance);
|
||||
//ffPrintTime(&instance);
|
||||
|
||||
@@ -81,6 +81,12 @@ static bool parseModuleJsonObject(FFinstance* instance, const char* type, json_o
|
||||
false;
|
||||
}
|
||||
|
||||
case 'L': {
|
||||
return
|
||||
tryModule(instance, type, module, FF_LOCALE_MODULE_NAME, ffParseLocaleJsonObject) ||
|
||||
false;
|
||||
}
|
||||
|
||||
case 'O': {
|
||||
return
|
||||
tryModule(instance, type, module, FF_OS_MODULE_NAME, ffParseOSJsonObject) ||
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/locale/locale.h"
|
||||
|
||||
#define FF_LOCALE_MODULE_NAME "Locale"
|
||||
#define FF_LOCALE_NUM_FORMAT_ARGS 1
|
||||
|
||||
void ffPrintLocale(FFinstance* instance)
|
||||
{
|
||||
FFstrbuf locale;
|
||||
ffStrbufInit(&locale);
|
||||
|
||||
ffDetectLocale(&locale);
|
||||
if(locale.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.locale, "No locale found");
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->config.locale.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.locale.key);
|
||||
ffStrbufPutTo(&locale, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.locale, FF_LOCALE_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &locale}
|
||||
});
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&locale);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/locale/locale.h"
|
||||
#include "modules/locale/locale.h"
|
||||
|
||||
#define FF_LOCALE_NUM_FORMAT_ARGS 1
|
||||
|
||||
void ffPrintLocale(FFinstance* instance, FFLocaleOptions* options)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY locale;
|
||||
ffStrbufInit(&locale);
|
||||
|
||||
ffDetectLocale(&locale);
|
||||
if(locale.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_LOCALE_MODULE_NAME, 0, &options->moduleArgs, "No locale found");
|
||||
return;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_LOCALE_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
ffStrbufPutTo(&locale, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_LOCALE_MODULE_NAME, 0, &options->moduleArgs, FF_LOCALE_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &locale}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ffInitLocaleOptions(FFLocaleOptions* options)
|
||||
{
|
||||
options->moduleName = FF_LOCALE_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
bool ffParseLocaleCommandOptions(FFLocaleOptions* options, const char* key, const char* value)
|
||||
{
|
||||
const char* subKey = ffOptionTestPrefix(key, FF_LOCALE_MODULE_NAME);
|
||||
if (!subKey) return false;
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffDestroyLocaleOptions(FFLocaleOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseLocaleJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFLocaleOptions __attribute__((__cleanup__(ffDestroyLocaleOptions))) options;
|
||||
ffInitLocaleOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_LOCALE_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintLocale(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_LOCALE_MODULE_NAME "Locale"
|
||||
|
||||
void ffPrintLocale(FFinstance* instance, FFLocaleOptions* options);
|
||||
void ffInitLocaleOptions(FFLocaleOptions* options);
|
||||
bool ffParseLocaleCommandOptions(FFLocaleOptions* options, const char* key, const char* value);
|
||||
void ffDestroyLocaleOptions(FFLocaleOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseLocaleJsonObject(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 FFLocaleOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFLocaleOptions;
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "modules/gpu/gpu.h"
|
||||
#include "modules/host/host.h"
|
||||
#include "modules/kernel/kernel.h"
|
||||
#include "modules/locale/locale.h"
|
||||
#include "modules/separator/separator.h"
|
||||
#include "modules/title/title.h"
|
||||
#include "modules/jsonconfig/jsonconfig.h"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "modules/gamepad/option.h"
|
||||
#include "modules/gpu/option.h"
|
||||
#include "modules/kernel/option.h"
|
||||
#include "modules/locale/option.h"
|
||||
#include "modules/os/option.h"
|
||||
#include "modules/separator/option.h"
|
||||
#include "modules/title/option.h"
|
||||
|
||||
Reference in New Issue
Block a user