mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-05 04:34:19 +01:00
Chore: run clang-format
```bash find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) ! -path "src/3rdparty/*" -print0 | xargs -0 clang-format -i ```
This commit is contained in:
+462
-541
File diff suppressed because it is too large
Load Diff
+11
-16
@@ -5,38 +5,33 @@
|
||||
#include "common/FFstrbuf.h"
|
||||
#include "common/FFlist.h"
|
||||
|
||||
typedef enum __attribute__((__packed__)) FFSizeBinaryPrefixType
|
||||
{
|
||||
typedef enum __attribute__((__packed__)) FFSizeBinaryPrefixType {
|
||||
FF_SIZE_BINARY_PREFIX_TYPE_IEC, // 1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard)
|
||||
FF_SIZE_BINARY_PREFIX_TYPE_SI, // 1000 Bytes = 1 kB, 1000 kB = 1 MB, ...
|
||||
FF_SIZE_BINARY_PREFIX_TYPE_JEDEC, // 1024 Bytes = 1 KB, 1024 KB = 1 MB, ...
|
||||
} FFSizeBinaryPrefixType;
|
||||
|
||||
typedef enum __attribute__((__packed__)) FFTemperatureUnit
|
||||
{
|
||||
typedef enum __attribute__((__packed__)) FFTemperatureUnit {
|
||||
FF_TEMPERATURE_UNIT_DEFAULT,
|
||||
FF_TEMPERATURE_UNIT_CELSIUS,
|
||||
FF_TEMPERATURE_UNIT_FAHRENHEIT,
|
||||
FF_TEMPERATURE_UNIT_KELVIN,
|
||||
} FFTemperatureUnit;
|
||||
|
||||
typedef enum __attribute__((__packed__)) FFSpaceBeforeUnitType
|
||||
{
|
||||
typedef enum __attribute__((__packed__)) FFSpaceBeforeUnitType {
|
||||
FF_SPACE_BEFORE_UNIT_DEFAULT,
|
||||
FF_SPACE_BEFORE_UNIT_ALWAYS,
|
||||
FF_SPACE_BEFORE_UNIT_NEVER,
|
||||
} FFSpaceBeforeUnitType;
|
||||
|
||||
typedef enum __attribute__((__packed__)) FFFractionTrailingZerosType
|
||||
{
|
||||
typedef enum __attribute__((__packed__)) FFFractionTrailingZerosType {
|
||||
FF_FRACTION_TRAILING_ZEROS_TYPE_DEFAULT,
|
||||
FF_FRACTION_TRAILING_ZEROS_TYPE_ALWAYS,
|
||||
FF_FRACTION_TRAILING_ZEROS_TYPE_NEVER,
|
||||
} FFFractionTrailingZerosType;
|
||||
|
||||
typedef struct FFOptionsDisplay
|
||||
{
|
||||
//If one of those is empty, ffLogoPrint will set them
|
||||
typedef struct FFOptionsDisplay {
|
||||
// If one of those is empty, ffLogoPrint will set them
|
||||
FFstrbuf colorKeys;
|
||||
FFstrbuf colorTitle;
|
||||
FFstrbuf colorOutput;
|
||||
@@ -47,11 +42,11 @@ typedef struct FFOptionsDisplay
|
||||
FFstrbuf keyValueSeparator;
|
||||
|
||||
int32_t stat; // <0: disable stat; 0: no threshold; >0: threshold in ms
|
||||
bool pipe; //disables all escape sequences
|
||||
bool pipe; // disables all escape sequences
|
||||
bool showErrors;
|
||||
#ifndef NDEBUG
|
||||
#ifndef NDEBUG
|
||||
bool debugMode;
|
||||
#endif
|
||||
#endif
|
||||
bool disableLinewrap;
|
||||
bool durationAbbreviation;
|
||||
FFSpaceBeforeUnitType durationSpaceBeforeUnit;
|
||||
@@ -73,8 +68,8 @@ typedef struct FFOptionsDisplay
|
||||
FFstrbuf barBorderLeftElapsed;
|
||||
FFstrbuf barBorderRightElapsed;
|
||||
FFstrbuf barColorElapsed; // "auto" for auto selection from percent config; empty for no custom color (inherits)
|
||||
FFstrbuf barColorTotal; // empty for no custom color (inherits)
|
||||
FFstrbuf barColorBorder; // empty for no custom color (inherits)
|
||||
FFstrbuf barColorTotal; // empty for no custom color (inherits)
|
||||
FFstrbuf barColorBorder; // empty for no custom color (inherits)
|
||||
uint8_t barWidth;
|
||||
FFPercentageTypeFlags percentType;
|
||||
uint8_t percentNdigits;
|
||||
|
||||
+71
-71
@@ -6,119 +6,120 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_val* root)
|
||||
{
|
||||
const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_val* root) {
|
||||
yyjson_val* object = yyjson_obj_get(root, "general");
|
||||
if (!object) return NULL;
|
||||
if (!yyjson_is_obj(object)) return "Property 'general' must be an object";
|
||||
if (!object) {
|
||||
return NULL;
|
||||
}
|
||||
if (!yyjson_is_obj(object)) {
|
||||
return "Property 'general' must be an object";
|
||||
}
|
||||
|
||||
yyjson_val *key, *val;
|
||||
size_t idx, max;
|
||||
yyjson_obj_foreach(object, idx, max, key, val)
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "thread"))
|
||||
yyjson_obj_foreach (object, idx, max, key, val) {
|
||||
if (unsafe_yyjson_equals_str(key, "thread")) {
|
||||
options->multithreading = yyjson_get_bool(val);
|
||||
else if (unsafe_yyjson_equals_str(key, "processingTimeout"))
|
||||
} else if (unsafe_yyjson_equals_str(key, "processingTimeout")) {
|
||||
options->processingTimeout = (int32_t) yyjson_get_int(val);
|
||||
else if (unsafe_yyjson_equals_str(key, "preRun"))
|
||||
{
|
||||
if (!yyjson_is_str(val))
|
||||
} else if (unsafe_yyjson_equals_str(key, "preRun")) {
|
||||
if (!yyjson_is_str(val)) {
|
||||
return "general.preRun must be a string";
|
||||
if (system(unsafe_yyjson_get_str(val)) < 0)
|
||||
}
|
||||
if (system(unsafe_yyjson_get_str(val)) < 0) {
|
||||
return "Failed to execute preRun command";
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "detectVersion"))
|
||||
}
|
||||
} else if (unsafe_yyjson_equals_str(key, "detectVersion")) {
|
||||
options->detectVersion = yyjson_get_bool(val);
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
else if (unsafe_yyjson_equals_str(key, "playerName"))
|
||||
}
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
else if (unsafe_yyjson_equals_str(key, "playerName")) {
|
||||
ffStrbufSetJsonVal(&options->playerName, val);
|
||||
else if (unsafe_yyjson_equals_str(key, "dsForceDrm"))
|
||||
{
|
||||
if (yyjson_is_str(val))
|
||||
{
|
||||
} else if (unsafe_yyjson_equals_str(key, "dsForceDrm")) {
|
||||
if (yyjson_is_str(val)) {
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
|
||||
{ "sysfs-only", FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY },
|
||||
{ "false", FF_DS_FORCE_DRM_TYPE_FALSE },
|
||||
{ "true", FF_DS_FORCE_DRM_TYPE_TRUE },
|
||||
{},
|
||||
});
|
||||
if (error)
|
||||
{"sysfs-only", FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY},
|
||||
{"false", FF_DS_FORCE_DRM_TYPE_FALSE},
|
||||
{"true", FF_DS_FORCE_DRM_TYPE_TRUE},
|
||||
{},
|
||||
});
|
||||
if (error) {
|
||||
return "Invalid enum value of `dsForceDrm`";
|
||||
else
|
||||
} else {
|
||||
options->dsForceDrm = (FFDsForceDrmType) value;
|
||||
}
|
||||
else
|
||||
}
|
||||
} else {
|
||||
options->dsForceDrm = yyjson_get_bool(val) ? FF_DS_FORCE_DRM_TYPE_TRUE : FF_DS_FORCE_DRM_TYPE_FALSE;
|
||||
}
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
else if (unsafe_yyjson_equals_str(key, "wmiTimeout"))
|
||||
#elif defined(_WIN32)
|
||||
else if (unsafe_yyjson_equals_str(key, "wmiTimeout")) {
|
||||
options->wmiTimeout = (int32_t) yyjson_get_int(val);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
else
|
||||
else {
|
||||
return "Unknown general property";
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key, const char* value)
|
||||
{
|
||||
if(ffStrEqualsIgnCase(key, "--thread") || ffStrEqualsIgnCase(key, "--multithreading"))
|
||||
bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key, const char* value) {
|
||||
if (ffStrEqualsIgnCase(key, "--thread") || ffStrEqualsIgnCase(key, "--multithreading")) {
|
||||
options->multithreading = ffOptionParseBoolean(value);
|
||||
else if(ffStrEqualsIgnCase(key, "--processing-timeout"))
|
||||
} else if (ffStrEqualsIgnCase(key, "--processing-timeout")) {
|
||||
options->processingTimeout = ffOptionParseInt32(key, value);
|
||||
else if(ffStrEqualsIgnCase(key, "--detect-version"))
|
||||
} else if (ffStrEqualsIgnCase(key, "--detect-version")) {
|
||||
options->detectVersion = ffOptionParseBoolean(value);
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
else if(ffStrEqualsIgnCase(key, "--player-name"))
|
||||
ffOptionParseString(key, value, &options->playerName);
|
||||
else if(ffStrEqualsIgnCase(key, "--ds-force-drm"))
|
||||
{
|
||||
if (ffOptionParseBoolean(value))
|
||||
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_TRUE;
|
||||
else if (ffStrEqualsIgnCase(value, "sysfs-only"))
|
||||
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY;
|
||||
else
|
||||
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_FALSE;
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
else if (ffStrEqualsIgnCase(key, "--wmi-timeout"))
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
else if (ffStrEqualsIgnCase(key, "--player-name")) {
|
||||
ffOptionParseString(key, value, &options->playerName);
|
||||
} else if (ffStrEqualsIgnCase(key, "--ds-force-drm")) {
|
||||
if (ffOptionParseBoolean(value)) {
|
||||
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_TRUE;
|
||||
} else if (ffStrEqualsIgnCase(value, "sysfs-only")) {
|
||||
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY;
|
||||
} else {
|
||||
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_FALSE;
|
||||
}
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
else if (ffStrEqualsIgnCase(key, "--wmi-timeout")) {
|
||||
options->wmiTimeout = ffOptionParseInt32(key, value);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
else
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffOptionsInitGeneral(FFOptionsGeneral* options)
|
||||
{
|
||||
void ffOptionsInitGeneral(FFOptionsGeneral* options) {
|
||||
options->processingTimeout = 5000;
|
||||
options->multithreading = true;
|
||||
options->detectVersion = true;
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
ffStrbufInit(&options->playerName);
|
||||
options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_FALSE;
|
||||
#elif defined(_WIN32)
|
||||
#elif defined(_WIN32)
|
||||
options->wmiTimeout = 5000;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void ffOptionsDestroyGeneral(FF_MAYBE_UNUSED FFOptionsGeneral* options)
|
||||
{
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
void ffOptionsDestroyGeneral(FF_MAYBE_UNUSED FFOptionsGeneral* options) {
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
ffStrbufDestroy(&options->playerName);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void ffOptionsGenerateGeneralJsonConfig(FFdata* data, FFOptionsGeneral* options)
|
||||
{
|
||||
void ffOptionsGenerateGeneralJsonConfig(FFdata* data, FFOptionsGeneral* options) {
|
||||
yyjson_mut_doc* doc = data->resultDoc;
|
||||
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, doc->root, "general");
|
||||
|
||||
@@ -128,12 +129,11 @@ void ffOptionsGenerateGeneralJsonConfig(FFdata* data, FFOptionsGeneral* options)
|
||||
|
||||
yyjson_mut_obj_add_bool(doc, obj, "detectVersion", options->detectVersion);
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "playerName", &options->playerName);
|
||||
|
||||
switch (options->dsForceDrm)
|
||||
{
|
||||
switch (options->dsForceDrm) {
|
||||
case FF_DS_FORCE_DRM_TYPE_FALSE:
|
||||
yyjson_mut_obj_add_bool(doc, obj, "dsForceDrm", false);
|
||||
break;
|
||||
@@ -145,9 +145,9 @@ void ffOptionsGenerateGeneralJsonConfig(FFdata* data, FFOptionsGeneral* options)
|
||||
break;
|
||||
}
|
||||
|
||||
#elif defined(_WIN32)
|
||||
#elif defined(_WIN32)
|
||||
|
||||
yyjson_mut_obj_add_int(doc, obj, "wmiTimeout", options->wmiTimeout);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
+8
-10
@@ -2,26 +2,24 @@
|
||||
|
||||
#include "common/ffdata.h"
|
||||
|
||||
typedef enum __attribute__((__packed__)) FFDsForceDrmType
|
||||
{
|
||||
FF_DS_FORCE_DRM_TYPE_FALSE = 0, // Disable
|
||||
FF_DS_FORCE_DRM_TYPE_TRUE = 1, // Try `libdrm`, then `sysfs` if libdrm failed
|
||||
typedef enum __attribute__((__packed__)) FFDsForceDrmType {
|
||||
FF_DS_FORCE_DRM_TYPE_FALSE = 0, // Disable
|
||||
FF_DS_FORCE_DRM_TYPE_TRUE = 1, // Try `libdrm`, then `sysfs` if libdrm failed
|
||||
FF_DS_FORCE_DRM_TYPE_SYSFS_ONLY, // Use `/sys/class/drm` only
|
||||
} FFDsForceDrmType;
|
||||
|
||||
typedef struct FFOptionsGeneral
|
||||
{
|
||||
typedef struct FFOptionsGeneral {
|
||||
bool multithreading;
|
||||
int32_t processingTimeout;
|
||||
bool detectVersion;
|
||||
|
||||
// Module options that cannot be put in module option structure
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
// Module options that cannot be put in module option structure
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
|
||||
FFstrbuf playerName;
|
||||
FFDsForceDrmType dsForceDrm;
|
||||
#elif defined(_WIN32)
|
||||
#elif defined(_WIN32)
|
||||
int32_t wmiTimeout;
|
||||
#endif
|
||||
#endif
|
||||
} FFOptionsGeneral;
|
||||
|
||||
const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_val* root);
|
||||
|
||||
+257
-315
@@ -3,14 +3,14 @@
|
||||
#include "common/jsonconfig.h"
|
||||
#include "common/stringUtils.h"
|
||||
|
||||
void ffOptionsInitLogo(FFOptionsLogo* options)
|
||||
{
|
||||
void ffOptionsInitLogo(FFOptionsLogo* options) {
|
||||
ffStrbufInit(&options->source);
|
||||
options->type = FF_LOGO_TYPE_AUTO;
|
||||
for(uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i)
|
||||
for (uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i) {
|
||||
ffStrbufInit(&options->colors[i]);
|
||||
}
|
||||
options->width = 0;
|
||||
options->height = 0; //preserve aspect ratio
|
||||
options->height = 0; // preserve aspect ratio
|
||||
options->paddingTop = 0;
|
||||
options->paddingLeft = 0;
|
||||
options->paddingRight = 4;
|
||||
@@ -26,234 +26,190 @@ void ffOptionsInitLogo(FFOptionsLogo* options)
|
||||
options->chafaDitherMode = UINT32_MAX;
|
||||
}
|
||||
|
||||
bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, const char* value)
|
||||
{
|
||||
if (ffStrEqualsIgnCase(key, "-l"))
|
||||
bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, const char* value) {
|
||||
if (ffStrEqualsIgnCase(key, "-l")) {
|
||||
goto logoType;
|
||||
}
|
||||
|
||||
const char* subKey = ffOptionTestPrefix(key, "logo");
|
||||
if(subKey)
|
||||
{
|
||||
if (subKey[0] == '\0')
|
||||
{
|
||||
logoType:
|
||||
if(value == NULL)
|
||||
{
|
||||
if (subKey) {
|
||||
if (subKey[0] == '\0') {
|
||||
logoType:
|
||||
if (value == NULL) {
|
||||
fprintf(stderr, "Error: usage: %s <none|small|logo-source>\n", key);
|
||||
exit(477);
|
||||
}
|
||||
//this is usually wanted when disabling logo
|
||||
if(ffStrEqualsIgnCase(value, "none"))
|
||||
// this is usually wanted when disabling logo
|
||||
if (ffStrEqualsIgnCase(value, "none")) {
|
||||
options->type = FF_LOGO_TYPE_NONE;
|
||||
else if(ffStrEqualsIgnCase(value, "small"))
|
||||
} else if (ffStrEqualsIgnCase(value, "small")) {
|
||||
options->type = FF_LOGO_TYPE_SMALL;
|
||||
else
|
||||
} else {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(subKey, "type"))
|
||||
{
|
||||
}
|
||||
} else if (ffStrEqualsIgnCase(subKey, "type")) {
|
||||
options->type = (FFLogoType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
|
||||
{ "auto", FF_LOGO_TYPE_AUTO },
|
||||
{ "builtin", FF_LOGO_TYPE_BUILTIN },
|
||||
{ "small", FF_LOGO_TYPE_SMALL },
|
||||
{ "file", FF_LOGO_TYPE_FILE },
|
||||
{ "file-raw", FF_LOGO_TYPE_FILE_RAW },
|
||||
{ "data", FF_LOGO_TYPE_DATA },
|
||||
{ "data-raw", FF_LOGO_TYPE_DATA_RAW },
|
||||
{ "command-raw", FF_LOGO_TYPE_COMMAND_RAW },
|
||||
{ "sixel", FF_LOGO_TYPE_IMAGE_SIXEL },
|
||||
{ "kitty", FF_LOGO_TYPE_IMAGE_KITTY },
|
||||
{ "kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT },
|
||||
{ "kitty-icat", FF_LOGO_TYPE_IMAGE_KITTY_ICAT },
|
||||
{ "iterm", FF_LOGO_TYPE_IMAGE_ITERM },
|
||||
{ "chafa", FF_LOGO_TYPE_IMAGE_CHAFA },
|
||||
{ "raw", FF_LOGO_TYPE_IMAGE_RAW },
|
||||
{ "none", FF_LOGO_TYPE_NONE },
|
||||
{},
|
||||
});
|
||||
}
|
||||
else if(ffStrStartsWithIgnCase(subKey, "color-") && subKey[6] != '\0' && subKey[7] == '\0') // matches "--logo-color-*"
|
||||
{"auto", FF_LOGO_TYPE_AUTO},
|
||||
{"builtin", FF_LOGO_TYPE_BUILTIN},
|
||||
{"small", FF_LOGO_TYPE_SMALL},
|
||||
{"file", FF_LOGO_TYPE_FILE},
|
||||
{"file-raw", FF_LOGO_TYPE_FILE_RAW},
|
||||
{"data", FF_LOGO_TYPE_DATA},
|
||||
{"data-raw", FF_LOGO_TYPE_DATA_RAW},
|
||||
{"command-raw", FF_LOGO_TYPE_COMMAND_RAW},
|
||||
{"sixel", FF_LOGO_TYPE_IMAGE_SIXEL},
|
||||
{"kitty", FF_LOGO_TYPE_IMAGE_KITTY},
|
||||
{"kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT},
|
||||
{"kitty-icat", FF_LOGO_TYPE_IMAGE_KITTY_ICAT},
|
||||
{"iterm", FF_LOGO_TYPE_IMAGE_ITERM},
|
||||
{"chafa", FF_LOGO_TYPE_IMAGE_CHAFA},
|
||||
{"raw", FF_LOGO_TYPE_IMAGE_RAW},
|
||||
{"none", FF_LOGO_TYPE_NONE},
|
||||
{},
|
||||
});
|
||||
} else if (ffStrStartsWithIgnCase(subKey, "color-") && subKey[6] != '\0' && subKey[7] == '\0') // matches "--logo-color-*"
|
||||
{
|
||||
//Map the number to an array index, so that '1' -> 0, '2' -> 1, etc.
|
||||
int index = (int)subKey[6] - '0' - 1;
|
||||
// Map the number to an array index, so that '1' -> 0, '2' -> 1, etc.
|
||||
int index = (int) subKey[6] - '0' - 1;
|
||||
|
||||
//Match only --logo-color-[1-9]
|
||||
if(index < 0 || index >= FASTFETCH_LOGO_MAX_COLORS)
|
||||
{
|
||||
// Match only --logo-color-[1-9]
|
||||
if (index < 0 || index >= FASTFETCH_LOGO_MAX_COLORS) {
|
||||
fprintf(stderr, "Error: invalid --color-[1-9] index: %c\n", key[13]);
|
||||
exit(472);
|
||||
}
|
||||
if(value == NULL)
|
||||
{
|
||||
if (value == NULL) {
|
||||
fprintf(stderr, "Error: usage: %s <str>\n", key);
|
||||
exit(477);
|
||||
}
|
||||
ffOptionParseColor(value, &options->colors[index]);
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(subKey, "width"))
|
||||
} else if (ffStrEqualsIgnCase(subKey, "width")) {
|
||||
options->width = ffOptionParseUInt32(key, value);
|
||||
else if(ffStrEqualsIgnCase(subKey, "height"))
|
||||
} else if (ffStrEqualsIgnCase(subKey, "height")) {
|
||||
options->height = ffOptionParseUInt32(key, value);
|
||||
else if(ffStrEqualsIgnCase(subKey, "padding"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(subKey, "padding")) {
|
||||
uint32_t padding = ffOptionParseUInt32(key, value);
|
||||
options->paddingLeft = padding;
|
||||
options->paddingRight = padding;
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(subKey, "padding-top"))
|
||||
} else if (ffStrEqualsIgnCase(subKey, "padding-top")) {
|
||||
options->paddingTop = ffOptionParseUInt32(key, value);
|
||||
else if(ffStrEqualsIgnCase(subKey, "padding-left"))
|
||||
} else if (ffStrEqualsIgnCase(subKey, "padding-left")) {
|
||||
options->paddingLeft = ffOptionParseUInt32(key, value);
|
||||
else if(ffStrEqualsIgnCase(subKey, "padding-right"))
|
||||
} else if (ffStrEqualsIgnCase(subKey, "padding-right")) {
|
||||
options->paddingRight = ffOptionParseUInt32(key, value);
|
||||
else if(ffStrEqualsIgnCase(subKey, "print-remaining"))
|
||||
} else if (ffStrEqualsIgnCase(subKey, "print-remaining")) {
|
||||
options->printRemaining = ffOptionParseBoolean(value);
|
||||
else if(ffStrEqualsIgnCase(subKey, "preserve-aspect-ratio"))
|
||||
} else if (ffStrEqualsIgnCase(subKey, "preserve-aspect-ratio")) {
|
||||
options->preserveAspectRatio = ffOptionParseBoolean(value);
|
||||
else if(ffStrEqualsIgnCase(subKey, "recache"))
|
||||
} else if (ffStrEqualsIgnCase(subKey, "recache")) {
|
||||
options->recache = ffOptionParseBoolean(value);
|
||||
else if(ffStrEqualsIgnCase(subKey, "separate"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(subKey, "separate")) {
|
||||
fputs("--logo-separate has been renamed to --logo-position\n", stderr);
|
||||
exit(477);
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(subKey, "position"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(subKey, "position")) {
|
||||
options->position = (FFLogoPosition) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
|
||||
{ "left", FF_LOGO_POSITION_LEFT },
|
||||
{ "right", FF_LOGO_POSITION_RIGHT },
|
||||
{ "top", FF_LOGO_POSITION_TOP },
|
||||
{},
|
||||
});
|
||||
}
|
||||
else
|
||||
{"left", FF_LOGO_POSITION_LEFT},
|
||||
{"right", FF_LOGO_POSITION_RIGHT},
|
||||
{"top", FF_LOGO_POSITION_TOP},
|
||||
{},
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
else if((subKey = ffOptionTestPrefix(key, "file")))
|
||||
{
|
||||
if(subKey[0] == '\0')
|
||||
{
|
||||
}
|
||||
} else if ((subKey = ffOptionTestPrefix(key, "file"))) {
|
||||
if (subKey[0] == '\0') {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_FILE;
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(subKey, "raw"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(subKey, "raw")) {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_FILE_RAW;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
else if((subKey = ffOptionTestPrefix(key, "data")))
|
||||
{
|
||||
if(subKey[0] == '\0')
|
||||
{
|
||||
}
|
||||
} else if ((subKey = ffOptionTestPrefix(key, "data"))) {
|
||||
if (subKey[0] == '\0') {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_DATA;
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(subKey, "raw"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(subKey, "raw")) {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_DATA_RAW;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(key, "--sixel"))
|
||||
{
|
||||
}
|
||||
} else if (ffStrEqualsIgnCase(key, "--sixel")) {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_IMAGE_SIXEL;
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(key, "--kitty"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(key, "--kitty")) {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_IMAGE_KITTY;
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(key, "--kitty-direct"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(key, "--kitty-direct")) {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_IMAGE_KITTY_DIRECT;
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(key, "--kitty-icat"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(key, "--kitty-icat")) {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_IMAGE_KITTY_ICAT;
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(key, "--iterm"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(key, "--iterm")) {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_IMAGE_ITERM;
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(key, "--raw"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(key, "--raw")) {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_IMAGE_RAW;
|
||||
}
|
||||
else if((subKey = ffOptionTestPrefix(key, "chafa")))
|
||||
{
|
||||
if(subKey[0] == '\0')
|
||||
{
|
||||
} else if ((subKey = ffOptionTestPrefix(key, "chafa"))) {
|
||||
if (subKey[0] == '\0') {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_IMAGE_CHAFA;
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(subKey, "fg-only"))
|
||||
} else if (ffStrEqualsIgnCase(subKey, "fg-only")) {
|
||||
options->chafaFgOnly = ffOptionParseBoolean(value);
|
||||
else if(ffStrEqualsIgnCase(subKey, "symbols"))
|
||||
} else if (ffStrEqualsIgnCase(subKey, "symbols")) {
|
||||
ffOptionParseString(key, value, &options->chafaSymbols);
|
||||
else if(ffStrEqualsIgnCase(subKey, "canvas-mode"))
|
||||
{
|
||||
} else if (ffStrEqualsIgnCase(subKey, "canvas-mode")) {
|
||||
options->chafaCanvasMode = (uint32_t) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
|
||||
{ "TRUECOLOR", 0 },
|
||||
{ "INDEXED_256", 1 },
|
||||
{ "INDEXED_240", 2 },
|
||||
{ "INDEXED_16", 3 },
|
||||
{ "FGBG_BGFG", 4 },
|
||||
{ "FGBG", 5 },
|
||||
{ "INDEXED_8", 6 },
|
||||
{ "INDEXED_16_8", 7 },
|
||||
{},
|
||||
});
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(subKey, "color-space"))
|
||||
{
|
||||
{"TRUECOLOR", 0},
|
||||
{"INDEXED_256", 1},
|
||||
{"INDEXED_240", 2},
|
||||
{"INDEXED_16", 3},
|
||||
{"FGBG_BGFG", 4},
|
||||
{"FGBG", 5},
|
||||
{"INDEXED_8", 6},
|
||||
{"INDEXED_16_8", 7},
|
||||
{},
|
||||
});
|
||||
} else if (ffStrEqualsIgnCase(subKey, "color-space")) {
|
||||
options->chafaColorSpace = (uint32_t) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
|
||||
{ "RGB", 0 },
|
||||
{ "DIN99D", 1 },
|
||||
{},
|
||||
});
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(subKey, "dither-mode"))
|
||||
{
|
||||
{"RGB", 0},
|
||||
{"DIN99D", 1},
|
||||
{},
|
||||
});
|
||||
} else if (ffStrEqualsIgnCase(subKey, "dither-mode")) {
|
||||
options->chafaDitherMode = (uint32_t) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
|
||||
{ "NONE", 0 },
|
||||
{ "ORDERED", 1 },
|
||||
{ "DIFFUSION", 2 },
|
||||
{},
|
||||
});
|
||||
}
|
||||
else
|
||||
{"NONE", 0},
|
||||
{"ORDERED", 1},
|
||||
{"DIFFUSION", 2},
|
||||
{},
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
else
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffOptionsDestroyLogo(FFOptionsLogo* options)
|
||||
{
|
||||
void ffOptionsDestroyLogo(FFOptionsLogo* options) {
|
||||
ffStrbufDestroy(&options->source);
|
||||
ffStrbufDestroy(&options->chafaSymbols);
|
||||
for(uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i)
|
||||
for (uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i) {
|
||||
ffStrbufDestroy(&options->colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* root)
|
||||
{
|
||||
const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* root) {
|
||||
yyjson_val* object = yyjson_obj_get(root, "logo");
|
||||
if (!object) return NULL;
|
||||
if (yyjson_is_null(object))
|
||||
{
|
||||
if (!object) {
|
||||
return NULL;
|
||||
}
|
||||
if (yyjson_is_null(object)) {
|
||||
options->type = FF_LOGO_TYPE_NONE;
|
||||
options->paddingTop = 0;
|
||||
options->paddingRight = 0;
|
||||
@@ -261,218 +217,206 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (yyjson_is_str(object))
|
||||
{
|
||||
if (yyjson_is_str(object)) {
|
||||
ffStrbufSetJsonVal(&options->source, object);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!yyjson_is_obj(object)) return "Property 'logo' must be an object";
|
||||
if (!yyjson_is_obj(object)) {
|
||||
return "Property 'logo' must be an object";
|
||||
}
|
||||
|
||||
yyjson_val *key, *val;
|
||||
size_t idx, max;
|
||||
yyjson_obj_foreach(object, idx, max, key, val)
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "type"))
|
||||
{
|
||||
yyjson_obj_foreach (object, idx, max, key, val) {
|
||||
if (unsafe_yyjson_equals_str(key, "type")) {
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
|
||||
{ "auto", FF_LOGO_TYPE_AUTO },
|
||||
{ "builtin", FF_LOGO_TYPE_BUILTIN },
|
||||
{ "small", FF_LOGO_TYPE_SMALL },
|
||||
{ "file", FF_LOGO_TYPE_FILE },
|
||||
{ "file-raw", FF_LOGO_TYPE_FILE_RAW },
|
||||
{ "data", FF_LOGO_TYPE_DATA },
|
||||
{ "data-raw", FF_LOGO_TYPE_DATA_RAW },
|
||||
{ "command-raw", FF_LOGO_TYPE_COMMAND_RAW },
|
||||
{ "sixel", FF_LOGO_TYPE_IMAGE_SIXEL },
|
||||
{ "kitty", FF_LOGO_TYPE_IMAGE_KITTY },
|
||||
{ "kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT },
|
||||
{ "kitty-icat", FF_LOGO_TYPE_IMAGE_KITTY_ICAT },
|
||||
{ "iterm", FF_LOGO_TYPE_IMAGE_ITERM },
|
||||
{ "chafa", FF_LOGO_TYPE_IMAGE_CHAFA },
|
||||
{ "raw", FF_LOGO_TYPE_IMAGE_RAW },
|
||||
{ "none", FF_LOGO_TYPE_NONE },
|
||||
{},
|
||||
});
|
||||
{"auto", FF_LOGO_TYPE_AUTO},
|
||||
{"builtin", FF_LOGO_TYPE_BUILTIN},
|
||||
{"small", FF_LOGO_TYPE_SMALL},
|
||||
{"file", FF_LOGO_TYPE_FILE},
|
||||
{"file-raw", FF_LOGO_TYPE_FILE_RAW},
|
||||
{"data", FF_LOGO_TYPE_DATA},
|
||||
{"data-raw", FF_LOGO_TYPE_DATA_RAW},
|
||||
{"command-raw", FF_LOGO_TYPE_COMMAND_RAW},
|
||||
{"sixel", FF_LOGO_TYPE_IMAGE_SIXEL},
|
||||
{"kitty", FF_LOGO_TYPE_IMAGE_KITTY},
|
||||
{"kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT},
|
||||
{"kitty-icat", FF_LOGO_TYPE_IMAGE_KITTY_ICAT},
|
||||
{"iterm", FF_LOGO_TYPE_IMAGE_ITERM},
|
||||
{"chafa", FF_LOGO_TYPE_IMAGE_CHAFA},
|
||||
{"raw", FF_LOGO_TYPE_IMAGE_RAW},
|
||||
{"none", FF_LOGO_TYPE_NONE},
|
||||
{},
|
||||
});
|
||||
|
||||
if (error) return error;
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
options->type = (FFLogoType) value;
|
||||
continue;
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "source"))
|
||||
{
|
||||
} else if (unsafe_yyjson_equals_str(key, "source")) {
|
||||
ffStrbufSetJsonVal(&options->source, val);
|
||||
continue;
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "color"))
|
||||
{
|
||||
if (!yyjson_is_obj(val))
|
||||
} else if (unsafe_yyjson_equals_str(key, "color")) {
|
||||
if (!yyjson_is_obj(val)) {
|
||||
return "Property 'color' must be an object";
|
||||
}
|
||||
|
||||
yyjson_val *keyc, *valc;
|
||||
size_t idxc, maxc;
|
||||
yyjson_obj_foreach(val, idxc, maxc, keyc, valc)
|
||||
{
|
||||
yyjson_obj_foreach (val, idxc, maxc, keyc, valc) {
|
||||
uint32_t index = (uint32_t) strtoul(unsafe_yyjson_get_str(keyc), NULL, 10);
|
||||
if (index < 1 || index > FASTFETCH_LOGO_MAX_COLORS)
|
||||
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]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "width"))
|
||||
{
|
||||
if (yyjson_is_null(val))
|
||||
} else if (unsafe_yyjson_equals_str(key, "width")) {
|
||||
if (yyjson_is_null(val)) {
|
||||
options->width = 0;
|
||||
else
|
||||
{
|
||||
} else {
|
||||
uint32_t value = (uint32_t) yyjson_get_uint(val);
|
||||
if (value == 0)
|
||||
if (value == 0) {
|
||||
return "Logo width must be a positive integer";
|
||||
}
|
||||
options->width = value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "height"))
|
||||
{
|
||||
if (yyjson_is_null(val))
|
||||
} else if (unsafe_yyjson_equals_str(key, "height")) {
|
||||
if (yyjson_is_null(val)) {
|
||||
options->height = 0;
|
||||
else
|
||||
{
|
||||
} else {
|
||||
uint32_t value = (uint32_t) yyjson_get_uint(val);
|
||||
if (value == 0)
|
||||
if (value == 0) {
|
||||
return "Logo height must be a positive integer";
|
||||
}
|
||||
options->height = value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "padding"))
|
||||
{
|
||||
if (!yyjson_is_obj(val))
|
||||
} else if (unsafe_yyjson_equals_str(key, "padding")) {
|
||||
if (!yyjson_is_obj(val)) {
|
||||
return "Logo padding must be an object";
|
||||
}
|
||||
|
||||
#define FF_PARSE_PADDING_POSITON(pos, paddingPos) \
|
||||
yyjson_val* pos = yyjson_obj_get(val, #pos); \
|
||||
if (pos) \
|
||||
{ \
|
||||
if (!yyjson_is_uint(pos)) \
|
||||
return "Logo padding values must be positive integers"; \
|
||||
options->paddingPos = (uint32_t) yyjson_get_uint(pos); \
|
||||
}
|
||||
#define FF_PARSE_PADDING_POSITON(pos, paddingPos) \
|
||||
yyjson_val* pos = yyjson_obj_get(val, #pos); \
|
||||
if (pos) { \
|
||||
if (!yyjson_is_uint(pos)) \
|
||||
return "Logo padding values must be positive integers"; \
|
||||
options->paddingPos = (uint32_t) yyjson_get_uint(pos); \
|
||||
}
|
||||
FF_PARSE_PADDING_POSITON(left, paddingLeft);
|
||||
FF_PARSE_PADDING_POSITON(top, paddingTop);
|
||||
FF_PARSE_PADDING_POSITON(right, paddingRight);
|
||||
#undef FF_PARSE_PADDING_POSITON
|
||||
#undef FF_PARSE_PADDING_POSITON
|
||||
continue;
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "printRemaining"))
|
||||
{
|
||||
} else if (unsafe_yyjson_equals_str(key, "printRemaining")) {
|
||||
options->printRemaining = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "preserveAspectRatio"))
|
||||
{
|
||||
} else if (unsafe_yyjson_equals_str(key, "preserveAspectRatio")) {
|
||||
options->preserveAspectRatio = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "recache"))
|
||||
{
|
||||
} else if (unsafe_yyjson_equals_str(key, "recache")) {
|
||||
options->recache = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "position"))
|
||||
{
|
||||
} else if (unsafe_yyjson_equals_str(key, "position")) {
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
|
||||
{ "left", FF_LOGO_POSITION_LEFT },
|
||||
{ "top", FF_LOGO_POSITION_TOP },
|
||||
{ "right", FF_LOGO_POSITION_RIGHT },
|
||||
{},
|
||||
});
|
||||
{"left", FF_LOGO_POSITION_LEFT},
|
||||
{"top", FF_LOGO_POSITION_TOP},
|
||||
{"right", FF_LOGO_POSITION_RIGHT},
|
||||
{},
|
||||
});
|
||||
|
||||
if (error) return error;
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
options->position = (FFLogoPosition) value;
|
||||
continue;
|
||||
}
|
||||
else if (unsafe_yyjson_equals_str(key, "chafa"))
|
||||
{
|
||||
if (!yyjson_is_obj(val))
|
||||
} else if (unsafe_yyjson_equals_str(key, "chafa")) {
|
||||
if (!yyjson_is_obj(val)) {
|
||||
return "Chafa config must be an object";
|
||||
}
|
||||
|
||||
yyjson_val* fgOnly = yyjson_obj_get(val, "fgOnly");
|
||||
if (fgOnly)
|
||||
if (fgOnly) {
|
||||
options->chafaFgOnly = yyjson_get_bool(fgOnly);
|
||||
}
|
||||
|
||||
yyjson_val* symbols = yyjson_obj_get(val, "symbols");
|
||||
if (symbols)
|
||||
if (symbols) {
|
||||
ffStrbufSetJsonVal(&options->chafaSymbols, symbols);
|
||||
}
|
||||
|
||||
yyjson_val* canvasMode = yyjson_obj_get(val, "canvasMode");
|
||||
if (canvasMode)
|
||||
{
|
||||
if (canvasMode) {
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(canvasMode, &value, (FFKeyValuePair[]) {
|
||||
{ "TRUECOLOR", 0 },
|
||||
{ "INDEXED_256", 1 },
|
||||
{ "INDEXED_240", 2 },
|
||||
{ "INDEXED_16", 3 },
|
||||
{ "FGBG_BGFG", 4 },
|
||||
{ "FGBG", 5 },
|
||||
{ "INDEXED_8", 6 },
|
||||
{ "INDEXED_16_8", 7 },
|
||||
{},
|
||||
});
|
||||
{"TRUECOLOR", 0},
|
||||
{"INDEXED_256", 1},
|
||||
{"INDEXED_240", 2},
|
||||
{"INDEXED_16", 3},
|
||||
{"FGBG_BGFG", 4},
|
||||
{"FGBG", 5},
|
||||
{"INDEXED_8", 6},
|
||||
{"INDEXED_16_8", 7},
|
||||
{},
|
||||
});
|
||||
|
||||
if (error) return error;
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
options->chafaCanvasMode = (uint32_t) value;
|
||||
}
|
||||
|
||||
yyjson_val* colorSpace = yyjson_obj_get(val, "colorSpace");
|
||||
if (colorSpace)
|
||||
{
|
||||
if (colorSpace) {
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(colorSpace, &value, (FFKeyValuePair[]) {
|
||||
{ "RGB", 0 },
|
||||
{ "DIN99D", 1 },
|
||||
{},
|
||||
});
|
||||
{"RGB", 0},
|
||||
{"DIN99D", 1},
|
||||
{},
|
||||
});
|
||||
|
||||
if (error) return error;
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
options->chafaColorSpace = (uint32_t) value;
|
||||
}
|
||||
|
||||
yyjson_val* ditherMode = yyjson_obj_get(val, "ditherMode");
|
||||
if (ditherMode)
|
||||
{
|
||||
if (ditherMode) {
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(ditherMode, &value, (FFKeyValuePair[]) {
|
||||
{ "NONE", 0 },
|
||||
{ "ORDERED", 1 },
|
||||
{ "DIFFUSION", 2 },
|
||||
{},
|
||||
});
|
||||
{"NONE", 0},
|
||||
{"ORDERED", 1},
|
||||
{"DIFFUSION", 2},
|
||||
{},
|
||||
});
|
||||
|
||||
if (error) return error;
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
options->chafaDitherMode = (uint32_t) value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return "Unknown logo key";
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options)
|
||||
{
|
||||
void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options) {
|
||||
yyjson_mut_doc* doc = data->resultDoc;
|
||||
yyjson_mut_val* obj = yyjson_mut_obj(doc);
|
||||
|
||||
switch (options->type)
|
||||
{
|
||||
switch (options->type) {
|
||||
case FF_LOGO_TYPE_NONE:
|
||||
yyjson_mut_obj_add_null(doc, doc->root, "logo");
|
||||
return;
|
||||
@@ -527,23 +471,24 @@ void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options)
|
||||
|
||||
{
|
||||
yyjson_mut_val* color = yyjson_mut_obj(doc);
|
||||
for (int i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++)
|
||||
{
|
||||
char c = (char)('1' + i);
|
||||
for (int i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++) {
|
||||
char c = (char) ('1' + i);
|
||||
yyjson_mut_obj_add(color, yyjson_mut_strncpy(doc, &c, 1), yyjson_mut_strbuf(doc, &options->colors[i]));
|
||||
}
|
||||
yyjson_mut_obj_add_val(doc, obj, "color", color);
|
||||
}
|
||||
|
||||
if (options->width == 0)
|
||||
if (options->width == 0) {
|
||||
yyjson_mut_obj_add_null(doc, obj, "width");
|
||||
else
|
||||
} else {
|
||||
yyjson_mut_obj_add_uint(doc, obj, "width", options->width);
|
||||
}
|
||||
|
||||
if (options->height == 0)
|
||||
if (options->height == 0) {
|
||||
yyjson_mut_obj_add_null(doc, obj, "height");
|
||||
else
|
||||
} else {
|
||||
yyjson_mut_obj_add_uint(doc, obj, "height", options->height);
|
||||
}
|
||||
|
||||
{
|
||||
yyjson_mut_val* padding = yyjson_mut_obj_add_obj(doc, obj, "padding");
|
||||
@@ -558,43 +503,40 @@ void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options)
|
||||
|
||||
yyjson_mut_obj_add_bool(doc, obj, "recache", options->recache);
|
||||
|
||||
yyjson_mut_obj_add_str(doc, obj, "position", ((const char* []) {
|
||||
"left",
|
||||
"top",
|
||||
"right",
|
||||
})[options->position]);
|
||||
yyjson_mut_obj_add_str(doc, obj, "position", ((const char*[]) {
|
||||
"left",
|
||||
"top",
|
||||
"right",
|
||||
})[options->position]);
|
||||
|
||||
{
|
||||
yyjson_mut_val* chafa = yyjson_mut_obj(doc);
|
||||
yyjson_mut_obj_add_bool(doc, chafa, "fgOnly", options->chafaFgOnly);
|
||||
yyjson_mut_obj_add_strbuf(doc, chafa, "symbols", &options->chafaSymbols);
|
||||
if (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->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 <= 1)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, chafa, "colorSpace", ((const char* []) {
|
||||
"RGB",
|
||||
"DIN99D",
|
||||
})[options->chafaColorSpace]);
|
||||
if (options->chafaColorSpace <= 1) {
|
||||
yyjson_mut_obj_add_str(doc, chafa, "colorSpace", ((const char*[]) {
|
||||
"RGB",
|
||||
"DIN99D",
|
||||
})[options->chafaColorSpace]);
|
||||
}
|
||||
if (options->chafaDitherMode <= 2)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, chafa, "ditherMode", ((const char* []) {
|
||||
"NONE",
|
||||
"ORDERED",
|
||||
"DIFFUSION",
|
||||
})[options->chafaDitherMode]);
|
||||
if (options->chafaDitherMode <= 2) {
|
||||
yyjson_mut_obj_add_str(doc, chafa, "ditherMode", ((const char*[]) {
|
||||
"NONE",
|
||||
"ORDERED",
|
||||
"DIFFUSION",
|
||||
})[options->chafaDitherMode]);
|
||||
}
|
||||
|
||||
yyjson_mut_obj_add_val(doc, obj, "chafa", chafa);
|
||||
|
||||
+3
-6
@@ -5,8 +5,7 @@
|
||||
#define FASTFETCH_LOGO_MAX_NAMES 9
|
||||
#define FASTFETCH_LOGO_MAX_COLORS 9 // two digits would make parsing much more complicated (index 1 - 9)
|
||||
|
||||
typedef enum __attribute__((__packed__)) FFLogoType
|
||||
{
|
||||
typedef enum __attribute__((__packed__)) FFLogoType {
|
||||
FF_LOGO_TYPE_AUTO, // if something is given, first try builtin, then file. Otherwise detect logo
|
||||
FF_LOGO_TYPE_BUILTIN, // builtin ascii art
|
||||
FF_LOGO_TYPE_SMALL, // builtin ascii art, small version
|
||||
@@ -25,15 +24,13 @@ typedef enum __attribute__((__packed__)) FFLogoType
|
||||
FF_LOGO_TYPE_NONE, // `--logo none`, but still applies colors to the system information output (unless `--pipe` is set)
|
||||
} FFLogoType;
|
||||
|
||||
typedef enum __attribute__((__packed__)) FFLogoPosition
|
||||
{
|
||||
typedef enum __attribute__((__packed__)) FFLogoPosition {
|
||||
FF_LOGO_POSITION_LEFT,
|
||||
FF_LOGO_POSITION_TOP,
|
||||
FF_LOGO_POSITION_RIGHT,
|
||||
} FFLogoPosition;
|
||||
|
||||
typedef struct FFOptionsLogo
|
||||
{
|
||||
typedef struct FFOptionsLogo {
|
||||
FFstrbuf source;
|
||||
FFLogoType type;
|
||||
FFLogoPosition position;
|
||||
|
||||
Reference in New Issue
Block a user