mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Migration: support logo
This commit is contained in:
+9
-3
@@ -795,7 +795,7 @@ static void parseArguments(FFdata* data, int argc, const char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
static void ffRun(FFdata* data)
|
||||
static void run(FFdata* data)
|
||||
{
|
||||
if (instance.state.configDoc)
|
||||
{
|
||||
@@ -837,6 +837,12 @@ static void ffRun(FFdata* data)
|
||||
ffFinish();
|
||||
}
|
||||
|
||||
static void migrateConfig(FFdata* data)
|
||||
{
|
||||
ffGenerateLogoJsonConfig(&instance.config.logo, instance.state.migrateConfigDoc);
|
||||
ffMigrateCommandOptionToJsonc(data);
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
ffInitInstance();
|
||||
@@ -853,9 +859,9 @@ int main(int argc, const char** argv)
|
||||
parseArguments(&data, argc, argv);
|
||||
|
||||
if (__builtin_expect(!instance.state.migrateConfigDoc, true))
|
||||
ffRun(&data);
|
||||
run(&data);
|
||||
else
|
||||
ffMigrateCommandOptionToJsonc(&data); // Migrate
|
||||
migrateConfig(&data);
|
||||
|
||||
ffStrbufDestroy(&data.structure);
|
||||
FF_LIST_FOR_EACH(FFCustomValue, customValue, data.customValues)
|
||||
|
||||
@@ -37,5 +37,6 @@ void ffInitLogoOptions(FFLogoOptions* options);
|
||||
bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value);
|
||||
void ffDestroyLogoOptions(FFLogoOptions* options);
|
||||
const char* ffParseLogoJsonConfig(FFLogoOptions* options);
|
||||
void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc);
|
||||
|
||||
#endif
|
||||
|
||||
+142
-1
@@ -286,7 +286,7 @@ const char* ffParseLogoJsonConfig(FFLogoOptions* options)
|
||||
{
|
||||
const char* keyc = yyjson_get_str(key_c);
|
||||
uint32_t index = (uint32_t) strtoul(keyc, NULL, 10);
|
||||
if (index < 1 || index > 9)
|
||||
if (index < 1 || index > FASTFETCH_LOGO_MAX_COLORS)
|
||||
return "Keys of property 'color' must be a number between 1 to 9";
|
||||
|
||||
ffOptionParseColor(yyjson_get_str(valc), &options->colors[index - 1]);
|
||||
@@ -417,3 +417,144 @@ const char* ffParseLogoJsonConfig(FFLogoOptions* options)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc)
|
||||
{
|
||||
__attribute__((__cleanup__(ffDestroyLogoOptions))) FFLogoOptions defaultOptions;
|
||||
ffInitLogoOptions(&defaultOptions);
|
||||
|
||||
yyjson_mut_val* obj = yyjson_mut_obj(doc);
|
||||
|
||||
if (options->type != defaultOptions.type)
|
||||
{
|
||||
switch (options->type)
|
||||
{
|
||||
case FF_LOGO_TYPE_NONE:
|
||||
yyjson_mut_obj_add_null(doc, doc->root, "logo");
|
||||
return;
|
||||
case FF_LOGO_TYPE_BUILTIN:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "builtin");
|
||||
break;
|
||||
case FF_LOGO_TYPE_SMALL:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "small");
|
||||
break;
|
||||
case FF_LOGO_TYPE_FILE:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "file");
|
||||
break;
|
||||
case FF_LOGO_TYPE_FILE_RAW:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "file-raw");
|
||||
break;
|
||||
case FF_LOGO_TYPE_DATA:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "data");
|
||||
break;
|
||||
case FF_LOGO_TYPE_DATA_RAW:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "data-raw");
|
||||
break;
|
||||
case FF_LOGO_TYPE_IMAGE_SIXEL:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "sixel");
|
||||
break;
|
||||
case FF_LOGO_TYPE_IMAGE_KITTY:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "kitty");
|
||||
break;
|
||||
case FF_LOGO_TYPE_IMAGE_ITERM:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "iterm");
|
||||
break;
|
||||
case FF_LOGO_TYPE_IMAGE_CHAFA:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "chafa");
|
||||
break;
|
||||
case FF_LOGO_TYPE_IMAGE_RAW:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "raw");
|
||||
break;
|
||||
default:
|
||||
yyjson_mut_obj_add_str(doc, obj, "type", "auto");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ffStrbufEqual(&options->source, &defaultOptions.source))
|
||||
yyjson_mut_obj_add_str(doc, obj, "source", options->source.chars);
|
||||
|
||||
{
|
||||
yyjson_mut_val* color = yyjson_mut_arr(doc);
|
||||
for (int i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++)
|
||||
{
|
||||
if (!ffStrbufEqual(&options->colors[i], &defaultOptions.colors[i]))
|
||||
yyjson_mut_arr_add_strbuf(doc, color, &options->colors[i]);
|
||||
}
|
||||
if (yyjson_mut_arr_size(color) > 0)
|
||||
yyjson_mut_obj_add_val(doc, obj, "color", color);
|
||||
}
|
||||
|
||||
if (options->width != defaultOptions.width)
|
||||
yyjson_mut_obj_add_uint(doc, obj, "width", options->width);
|
||||
|
||||
if (options->height != defaultOptions.height)
|
||||
yyjson_mut_obj_add_uint(doc, obj, "height", options->height);
|
||||
|
||||
{
|
||||
yyjson_mut_val* padding = yyjson_mut_obj(doc);
|
||||
if (options->paddingTop != defaultOptions.paddingTop)
|
||||
yyjson_mut_obj_add_uint(doc, padding, "top", options->paddingTop);
|
||||
if (options->paddingLeft != defaultOptions.paddingLeft)
|
||||
yyjson_mut_obj_add_uint(doc, padding, "left", options->paddingLeft);
|
||||
if (options->paddingRight != defaultOptions.paddingRight)
|
||||
yyjson_mut_obj_add_uint(doc, padding, "right", options->paddingRight);
|
||||
|
||||
if (yyjson_mut_obj_size(padding) > 0)
|
||||
yyjson_mut_obj_add_val(doc, obj, "padding", padding);
|
||||
}
|
||||
|
||||
if (options->printRemaining != defaultOptions.printRemaining)
|
||||
yyjson_mut_obj_add_bool(doc, obj, "printRemaining", options->printRemaining);
|
||||
|
||||
if (options->preserveAspectRadio != defaultOptions.preserveAspectRadio)
|
||||
yyjson_mut_obj_add_bool(doc, obj, "preserveAspectRadio", options->preserveAspectRadio);
|
||||
|
||||
if (options->recache != defaultOptions.recache)
|
||||
yyjson_mut_obj_add_bool(doc, obj, "recache", options->recache);
|
||||
|
||||
if (options->separate != defaultOptions.separate)
|
||||
yyjson_mut_obj_add_bool(doc, obj, "separate", options->separate);
|
||||
|
||||
{
|
||||
yyjson_mut_val* chafa = yyjson_mut_obj(doc);
|
||||
if (options->chafaFgOnly != defaultOptions.chafaFgOnly)
|
||||
yyjson_mut_obj_add_bool(doc, chafa, "fgOnly", options->chafaFgOnly);
|
||||
if (!ffStrbufEqual(&options->chafaSymbols, &defaultOptions.chafaSymbols))
|
||||
yyjson_mut_obj_add_strbuf(doc, chafa, "symbols", &options->chafaSymbols);
|
||||
if (options->chafaCanvasMode != defaultOptions.chafaCanvasMode && options->chafaCanvasMode <= 7)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, chafa, "canvasMode", ((const char* []) {
|
||||
"TRUECOLOR",
|
||||
"INDEXED_256",
|
||||
"INDEXED_240",
|
||||
"INDEXED_16",
|
||||
"FGBG_BGFG",
|
||||
"FGBG",
|
||||
"INDEXED_8",
|
||||
"INDEXED_16_8",
|
||||
})[options->chafaCanvasMode]);
|
||||
}
|
||||
if (options->chafaColorSpace != defaultOptions.chafaColorSpace && options->chafaColorSpace <= 1)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, chafa, "colorSpace", ((const char* []) {
|
||||
"RGB",
|
||||
"DIN99D",
|
||||
})[options->chafaColorSpace]);
|
||||
}
|
||||
if (options->chafaDitherMode != defaultOptions.chafaDitherMode && options->chafaDitherMode <= 2)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, chafa, "ditherMode", ((const char* []) {
|
||||
"NONE",
|
||||
"ORDERED",
|
||||
"DIFFUSION",
|
||||
})[options->chafaDitherMode]);
|
||||
}
|
||||
|
||||
if (yyjson_mut_obj_size(chafa) > 0)
|
||||
yyjson_mut_obj_add_val(doc, obj, "chafa", chafa);
|
||||
}
|
||||
|
||||
if (yyjson_mut_obj_size(obj) > 0)
|
||||
yyjson_mut_obj_add_val(doc, doc->root, "logo", obj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user