mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-08 06:00:08 +01:00
WMTheme: add JSON config support
This commit is contained in:
@@ -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 FFWMThemeOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFWMThemeOptions;
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/wmtheme/wmtheme.h"
|
||||
#include "modules/wmtheme/wmtheme.h"
|
||||
|
||||
#define FF_WMTHEME_DISPLAY_NAME "WM Theme"
|
||||
#define FF_WMTHEME_NUM_FORMAT_ARGS 1
|
||||
|
||||
void ffPrintWMTheme(FFinstance* instance, FFWMThemeOptions* options)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate();
|
||||
if(ffDetectWmTheme(instance, &themeOrError))
|
||||
{
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs.key);
|
||||
puts(themeOrError.chars);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_WMTHEME_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &themeOrError}
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintError(instance, FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, "%*s", themeOrError.length, themeOrError.chars);
|
||||
}
|
||||
}
|
||||
|
||||
void ffInitWMThemeOptions(FFWMThemeOptions* options)
|
||||
{
|
||||
options->moduleName = FF_WMTHEME_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
bool ffParseWMThemeCommandOptions(FFWMThemeOptions* options, const char* key, const char* value)
|
||||
{
|
||||
const char* subKey = ffOptionTestPrefix(key, FF_WMTHEME_MODULE_NAME);
|
||||
if (!subKey) return false;
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffDestroyWMThemeOptions(FFWMThemeOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseWMThemeJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFWMThemeOptions __attribute__((__cleanup__(ffDestroyWMThemeOptions))) options;
|
||||
ffInitWMThemeOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_WMTHEME_DISPLAY_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintWMTheme(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include "modules/wmtheme/option.h"
|
||||
|
||||
#define FF_WMTHEME_MODULE_NAME "WMTheme"
|
||||
|
||||
void ffPrintWMTheme(FFinstance* instance, FFWMThemeOptions* options);
|
||||
void ffInitWMThemeOptions(FFWMThemeOptions* options);
|
||||
bool ffParseWMThemeCommandOptions(FFWMThemeOptions* options, const char* key, const char* value);
|
||||
void ffDestroyWMThemeOptions(FFWMThemeOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseWMThemeJsonObject(FFinstance* instance, json_object* module);
|
||||
#endif
|
||||
Reference in New Issue
Block a user