mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 20:24:19 +01:00
DE: support JSON config
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
|
||||
#define FF_DE_MODULE_NAME "DE"
|
||||
#define FF_DE_NUM_FORMAT_ARGS 3
|
||||
|
||||
void ffPrintDesktopEnvironment(FFinstance* instance)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, "DE detection is not supported on Android");
|
||||
return;
|
||||
#endif
|
||||
|
||||
const FFDisplayServerResult* result = ffConnectDisplayServer(instance);
|
||||
|
||||
if(result->dePrettyName.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, "No DE found");
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->config.de.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_DE_MODULE_NAME, 0, &instance->config.de.key);
|
||||
|
||||
ffStrbufWriteTo(&result->dePrettyName, stdout);
|
||||
|
||||
if(result->deVersion.length > 0)
|
||||
{
|
||||
putchar(' ');
|
||||
ffStrbufWriteTo(&result->deVersion, stdout);
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, FF_DE_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->deProcessName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->dePrettyName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->deVersion}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
#include "modules/de/de.h"
|
||||
|
||||
#define FF_DE_NUM_FORMAT_ARGS 3
|
||||
|
||||
void ffPrintDE(FFinstance* instance, FFDEOptions* options)
|
||||
{
|
||||
const FFDisplayServerResult* result = ffConnectDisplayServer(instance);
|
||||
|
||||
if(result->dePrettyName.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &options->moduleArgs, "No DE found");
|
||||
return;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_DE_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
|
||||
ffStrbufWriteTo(&result->dePrettyName, stdout);
|
||||
|
||||
if(result->deVersion.length > 0)
|
||||
{
|
||||
putchar(' ');
|
||||
ffStrbufWriteTo(&result->deVersion, stdout);
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_DE_MODULE_NAME, 0, &options->moduleArgs, FF_DE_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->deProcessName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->dePrettyName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->deVersion}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ffInitDEOptions(FFDEOptions* options)
|
||||
{
|
||||
options->moduleName = FF_DE_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* value)
|
||||
{
|
||||
const char* subKey = ffOptionTestPrefix(key, FF_DE_MODULE_NAME);
|
||||
if (!subKey) return false;
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffDestroyDEOptions(FFDEOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseDEJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFDEOptions __attribute__((__cleanup__(ffDestroyDEOptions))) options;
|
||||
ffInitDEOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintDE(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_DE_MODULE_NAME "DE"
|
||||
|
||||
void ffPrintDE(FFinstance* instance, FFDEOptions* options);
|
||||
void ffInitDEOptions(FFDEOptions* options);
|
||||
bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* value);
|
||||
void ffDestroyDEOptions(FFDEOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseDEJsonObject(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 FFDEOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFDEOptions;
|
||||
@@ -53,6 +53,7 @@ static bool parseModuleJsonObject(FFinstance* instance, const char* type, json_o
|
||||
tryModule(instance, type, module, FF_DATETIME_MODULE_NAME, ffParseDateTimeJsonObject) ||
|
||||
tryModule(instance, type, module, FF_DISPLAY_MODULE_NAME, ffParseDisplayJsonObject) ||
|
||||
tryModule(instance, type, module, FF_DISK_MODULE_NAME, ffParseDiskJsonObject) ||
|
||||
tryModule(instance, type, module, FF_DE_MODULE_NAME, ffParseDEJsonObject) ||
|
||||
false;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "modules/datetime/datetime.h"
|
||||
#include "modules/disk/disk.h"
|
||||
#include "modules/display/display.h"
|
||||
#include "modules/de/de.h"
|
||||
#include "modules/font/font.h"
|
||||
#include "modules/gamepad/gamepad.h"
|
||||
#include "modules/gpu/gpu.h"
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "modules/custom/option.h"
|
||||
#include "modules/command/option.h"
|
||||
#include "modules/datetime/option.h"
|
||||
#include "modules/de/option.h"
|
||||
#include "modules/disk/option.h"
|
||||
#include "modules/display/option.h"
|
||||
#include "modules/font/option.h"
|
||||
|
||||
Reference in New Issue
Block a user