mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
@@ -18,6 +18,8 @@ Features:
|
||||
* In `display.color`: "@<color-index>" (e.g., "@34" for color index 34)
|
||||
* In `format` strings: "#@<color-index>" (e.g., "#@34" for color index 34)
|
||||
* Improves uptime accuracy on Windows 10+ (Uptime, Windows)
|
||||
* Adds a new module `Logo` to query built-in logo raw data in JSON output (Logo)
|
||||
* Usage: `fastfetch -s logo -l <logo-name> -j # Supported in JSON format only`
|
||||
|
||||
Bugfixes:
|
||||
* Skips local / loopback routes when detecting network interfaces (LocalIP, Linux) (#2127)
|
||||
|
||||
@@ -468,6 +468,7 @@ set(LIBFASTFETCH_SRC
|
||||
src/modules/loadavg/loadavg.c
|
||||
src/modules/locale/locale.c
|
||||
src/modules/localip/localip.c
|
||||
src/modules/logo/logo.c
|
||||
src/modules/memory/memory.c
|
||||
src/modules/monitor/monitor.c
|
||||
src/modules/netio/netio.c
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
#include "3rdparty/yyjson/yyjson.h"
|
||||
#include "common/printing.h"
|
||||
#include "logo/logo.h"
|
||||
#include "fastfetch.h"
|
||||
#include "modules/logo/logo.h"
|
||||
#include "options/logo.h"
|
||||
|
||||
bool ffPrintLogo(FF_MAYBE_UNUSED FFLogoOptions* options)
|
||||
{
|
||||
ffPrintError(FF_LOGO_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_DEFAULT, "Supported in JSON format only");
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffParseLogoJsonObject(FF_MAYBE_UNUSED FFLogoOptions* options, FF_MAYBE_UNUSED yyjson_val* module)
|
||||
{
|
||||
yyjson_val *key, *val;
|
||||
size_t idx, max;
|
||||
yyjson_obj_foreach(module, idx, max, key, val)
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "type") || unsafe_yyjson_equals_str(key, "condition"))
|
||||
continue;
|
||||
|
||||
ffPrintError(FF_LOGO_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
|
||||
}
|
||||
}
|
||||
|
||||
bool ffGenerateLogoJsonResult(FF_MAYBE_UNUSED FFLogoOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
FFLogoSize size = FF_LOGO_SIZE_UNKNOWN;
|
||||
FFOptionsLogo* logoOptions = &instance.config.logo;
|
||||
if (logoOptions->type == FF_LOGO_TYPE_SMALL)
|
||||
size = FF_LOGO_SIZE_SMALL;
|
||||
else if (logoOptions->type != FF_LOGO_TYPE_BUILTIN && logoOptions->type != FF_LOGO_TYPE_AUTO)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "Only 'builtin' and 'small' logo types are supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
const FFlogo* logo = logoOptions->source.length > 0
|
||||
? ffLogoGetBuiltinForName(&logoOptions->source, size)
|
||||
: ffLogoGetBuiltinDetected(size);
|
||||
|
||||
if (!logo)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "No built-in logo found for the specified name/size");
|
||||
return false;
|
||||
}
|
||||
|
||||
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
|
||||
|
||||
yyjson_mut_obj_add_str(doc, obj, "lines", logo->lines);
|
||||
|
||||
yyjson_mut_val* namesArr = yyjson_mut_obj_add_arr(doc, obj, "names");
|
||||
for (size_t i = 0; i < FASTFETCH_LOGO_MAX_NAMES && logo->names[i]; i++)
|
||||
yyjson_mut_arr_add_str(doc, namesArr, logo->names[i]);
|
||||
|
||||
yyjson_mut_val* colorsArr = yyjson_mut_obj_add_arr(doc, obj, "colors");
|
||||
for (size_t i = 0; i < FASTFETCH_LOGO_MAX_COLORS && logo->colors[i]; i++)
|
||||
yyjson_mut_arr_add_str(doc, colorsArr, logo->colors[i]);
|
||||
|
||||
yyjson_mut_obj_add_str(doc, obj, "colorKeys", logo->colorKeys);
|
||||
yyjson_mut_obj_add_str(doc, obj, "colorTitle", logo->colorTitle);
|
||||
|
||||
yyjson_mut_val* typeArr = yyjson_mut_obj_add_arr(doc, obj, "type");
|
||||
if (logo->type & FF_LOGO_LINE_TYPE_NORMAL)
|
||||
yyjson_mut_arr_add_str(doc, typeArr, "normal");
|
||||
if (logo->type & FF_LOGO_LINE_TYPE_SMALL_BIT)
|
||||
yyjson_mut_arr_add_str(doc, typeArr, "small");
|
||||
if (logo->type & FF_LOGO_LINE_TYPE_ALTER_BIT)
|
||||
yyjson_mut_arr_add_str(doc, typeArr, "alter");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffInitLogoOptions(FF_MAYBE_UNUSED FFLogoOptions* options)
|
||||
{
|
||||
}
|
||||
|
||||
void ffDestroyLogoOptions(FF_MAYBE_UNUSED FFLogoOptions* options)
|
||||
{
|
||||
}
|
||||
|
||||
FFModuleBaseInfo ffLogoModuleInfo = {
|
||||
.name = FF_LOGO_MODULE_NAME,
|
||||
.description = "Query built-in logo for JSON output",
|
||||
.initOptions = (void*) ffInitLogoOptions,
|
||||
.destroyOptions = (void*) ffDestroyLogoOptions,
|
||||
.parseJsonObject = (void*) ffParseLogoJsonObject,
|
||||
.printModule = (void*) ffPrintLogo,
|
||||
.generateJsonResult = (void*) ffGenerateLogoJsonResult,
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "option.h"
|
||||
|
||||
#define FF_LOGO_MODULE_NAME "Logo"
|
||||
|
||||
bool ffPrintLogo(FFLogoOptions* options);
|
||||
void ffInitLogoOptions(FFLogoOptions* options);
|
||||
void ffDestroyLogoOptions(FFLogoOptions* options);
|
||||
|
||||
extern FFModuleBaseInfo ffLogoModuleInfo;
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/option.h"
|
||||
|
||||
typedef struct FFLogoOptions
|
||||
{
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFLogoOptions;
|
||||
|
||||
static_assert(sizeof(FFLogoOptions) <= FF_OPTION_MAX_SIZE, "FFLogoOptions size exceeds maximum allowed size");
|
||||
@@ -82,6 +82,7 @@ static FFModuleBaseInfo* L[] = {
|
||||
&ffLoadavgModuleInfo,
|
||||
&ffLocaleModuleInfo,
|
||||
&ffLocalIPModuleInfo,
|
||||
&ffLogoModuleInfo,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "modules/loadavg/loadavg.h"
|
||||
#include "modules/locale/locale.h"
|
||||
#include "modules/localip/localip.h"
|
||||
#include "modules/logo/logo.h"
|
||||
#include "modules/media/media.h"
|
||||
#include "modules/memory/memory.h"
|
||||
#include "modules/monitor/monitor.h"
|
||||
|
||||
Reference in New Issue
Block a user