From f0844d763675edefc252b5c8e064e8f133ddd515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 25 Jun 2023 21:22:44 +0800 Subject: [PATCH] JsonConfig: support `"logo": null` and `"logo": "/path/to/logo"` --- doc/json_schema.json | 290 ++++++++++++++++++++------------------- presets/examples/3.jsonc | 4 +- presets/examples/5.jsonc | 4 +- src/logo/logo.c | 6 + src/logo/option.c | 16 +++ 5 files changed, 175 insertions(+), 145 deletions(-) diff --git a/doc/json_schema.json b/doc/json_schema.json index 158a1e5f..e169b30c 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -27,162 +27,174 @@ "format": "uri" }, "logo": { - "title": "Fastfetch logo configurations", - "type": "object", - "properties": { - "type": { - "title": "Set the type of the logo given", - "enum": [ - "auto", - "builtin", - "file", - "file-raw", - "data", - "data-raw", - "sixel", - "kitty", - "iterm", - "chafa", - "raw", - "none" - ], - "default": "auto" + "oneOf": [ + { + "title": "Disable logo", + "type": "null" }, - "source": { - "type": "string", - "title": "Set the source file of the logo" + { + "title": "Set the source file of the logo", + "type": "string" }, - "color": { + { + "title": "Fastfetch logo configurations", "type": "object", - "title": "Overwrite a color in the logo", "properties": { - "1": { - "title": "Color 1", - "$ref": "#/$defs/colors" + "type": { + "title": "Set the type of the logo given", + "enum": [ + "auto", + "builtin", + "file", + "file-raw", + "data", + "data-raw", + "sixel", + "kitty", + "iterm", + "chafa", + "raw", + "none" + ], + "default": "auto" }, - "2": { - "title": "Color 2", - "$ref": "#/$defs/colors" + "source": { + "type": "string", + "title": "Set the source file of the logo" }, - "3": { - "title": "Color 3", - "$ref": "#/$defs/colors" + "color": { + "type": "object", + "title": "Overwrite a color in the logo", + "properties": { + "1": { + "title": "Color 1", + "$ref": "#/$defs/colors" + }, + "2": { + "title": "Color 2", + "$ref": "#/$defs/colors" + }, + "3": { + "title": "Color 3", + "$ref": "#/$defs/colors" + }, + "4": { + "title": "Color 4", + "$ref": "#/$defs/colors" + }, + "5": { + "title": "Color 5", + "$ref": "#/$defs/colors" + }, + "6": { + "title": "Color 6", + "$ref": "#/$defs/colors" + }, + "7": { + "title": "Color 7", + "$ref": "#/$defs/colors" + }, + "8": { + "title": "Color 8", + "$ref": "#/$defs/colors" + }, + "9": { + "title": "Color 9", + "$ref": "#/$defs/colors" + } + } }, - "4": { - "title": "Color 4", - "$ref": "#/$defs/colors" - }, - "5": { - "title": "Color 5", - "$ref": "#/$defs/colors" - }, - "6": { - "title": "Color 6", - "$ref": "#/$defs/colors" - }, - "7": { - "title": "Color 7", - "$ref": "#/$defs/colors" - }, - "8": { - "title": "Color 8", - "$ref": "#/$defs/colors" - }, - "9": { - "title": "Color 9", - "$ref": "#/$defs/colors" - } - } - }, - "width": { - "type": "integer", - "title": "Set the width of the logo (in characters). Required for iTerm image protocol", - "minimum": 1 - }, - "height": { - "type": "integer", - "title": "Set the height of the logo (in characters). Required for iTerm image protocol", - "minimum": 1 - }, - "padding": { - "type": "object", - "title": "Set the padding of the logo", - "properties": { - "top": { + "width": { "type": "integer", - "title": "Set the top padding of the logo", - "minimum": 0 + "title": "Set the width of the logo (in characters). Required for iTerm image protocol", + "minimum": 1 }, - "left": { + "height": { "type": "integer", - "title": "Set the left padding of the logo", - "minimum": 0 + "title": "Set the height of the logo (in characters). Required for iTerm image protocol", + "minimum": 1 }, - "right": { - "type": "integer", - "title": "Set the right padding of the logo", - "minimum": 0 - } - } - }, - "printRemaining": { - "type": "boolean", - "title": "Whether to print the remaining logo, if it has more lines than modules to display", - "default": false - }, - "preserveAspectRadio": { - "type": "boolean", - "title": "Whether to preserve the aspect ratio of the logo. Supported by iTerm image protocol", - "default": false - }, - "chafa": { - "type": "object", - "title": "Chafa configuration. See chafa document for details", - "properties": { - "fgOnly": { + "padding": { + "type": "object", + "title": "Set the padding of the logo", + "properties": { + "top": { + "type": "integer", + "title": "Set the top padding of the logo", + "minimum": 0 + }, + "left": { + "type": "integer", + "title": "Set the left padding of the logo", + "minimum": 0 + }, + "right": { + "type": "integer", + "title": "Set the right padding of the logo", + "minimum": 0 + } + } + }, + "printRemaining": { "type": "boolean", - "title": "Produce character-cell output using foreground colors only", + "title": "Whether to print the remaining logo, if it has more lines than modules to display", "default": false }, - "symbols": { - "type": "string", - "title": "Specify character symbols to employ in final output" + "preserveAspectRadio": { + "type": "boolean", + "title": "Whether to preserve the aspect ratio of the logo. Supported by iTerm image protocol", + "default": false }, - "canvasMode": { - "type": "string", - "title": "Determine how colors are used in the output. This value maps the value of enum ChafaCanvasMode.", - "enum": [ - "TRUECOLOR", - "INDEXED_256", - "INDEXED_240", - "INDEXED_16", - "FGBG_BGFG", - "FGBG", - "INDEXED_8", - "INDEXED_16_8" - ] - }, - "colorSpace": { - "type": "string", - "title": "Set color space used for quantization. This value maps the value of enum ChafaColorSpace.", - "enum": [ - "RGB", - "DIN99D" - ] - }, - "ditherMode": { - "type": "string", - "title": "Set output dither mode (No effect with 24-bit color). This value maps the value of enum ChafaDitherMode.", - "enum": [ - "NONE", - "ORDERED", - "DIFFUSION" - ] + "chafa": { + "type": "object", + "title": "Chafa configuration. See chafa document for details", + "properties": { + "fgOnly": { + "type": "boolean", + "title": "Produce character-cell output using foreground colors only", + "default": false + }, + "symbols": { + "type": "string", + "title": "Specify character symbols to employ in final output" + }, + "canvasMode": { + "type": "string", + "title": "Determine how colors are used in the output. This value maps the value of enum ChafaCanvasMode.", + "enum": [ + "TRUECOLOR", + "INDEXED_256", + "INDEXED_240", + "INDEXED_16", + "FGBG_BGFG", + "FGBG", + "INDEXED_8", + "INDEXED_16_8" + ] + }, + "colorSpace": { + "type": "string", + "title": "Set color space used for quantization. This value maps the value of enum ChafaColorSpace.", + "enum": [ + "RGB", + "DIN99D" + ] + }, + "ditherMode": { + "type": "string", + "title": "Set output dither mode (No effect with 24-bit color). This value maps the value of enum ChafaDitherMode.", + "enum": [ + "NONE", + "ORDERED", + "DIFFUSION" + ] + } + } } - } + }, + "additionalProperties": false } - }, - "additionalProperties": false + ] }, "general": { "title": "Fastfetch general configurations", diff --git a/presets/examples/3.jsonc b/presets/examples/3.jsonc index 6ff5dabb..89fc9319 100644 --- a/presets/examples/3.jsonc +++ b/presets/examples/3.jsonc @@ -2,9 +2,7 @@ { "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json", - "logo": { - "source": "debian_small" - }, + "logo": "debian_small", "display": { "binaryPrefix": "si" }, diff --git a/presets/examples/5.jsonc b/presets/examples/5.jsonc index fefe2441..888c763d 100644 --- a/presets/examples/5.jsonc +++ b/presets/examples/5.jsonc @@ -2,9 +2,7 @@ { "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json", - "logo": { - "type": "none" - }, + "logo": null, "display": { "color": "reset_magenta" }, diff --git a/src/logo/logo.c b/src/logo/logo.c index 17e91b24..f0715593 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -410,6 +410,12 @@ void ffLogoPrint(void) const FFLogoOptions* options = &instance.config.logo; + if (options->type == FF_LOGO_TYPE_NONE) + { + logoPrintNone(); + return; + } + //If the source is not set, we can directly print the detected logo. if(options->source.length == 0) { diff --git a/src/logo/option.c b/src/logo/option.c index 5fe22176..a277616a 100644 --- a/src/logo/option.c +++ b/src/logo/option.c @@ -201,6 +201,22 @@ const char* ffParseLogoJsonConfig(void) yyjson_val* object = yyjson_obj_get(root, "logo"); if (!object) return NULL; + if (yyjson_is_null(object)) + { + options->type = FF_LOGO_TYPE_NONE; + options->paddingTop = 0; + options->paddingRight = 0; + options->paddingLeft = 0; + return NULL; + } + + if (yyjson_is_str(object)) + { + const char* value = yyjson_get_str(object); + ffStrbufSetS(&options->source, value); + return NULL; + } + if (!yyjson_is_obj(object)) return "Property 'logo' must be an object"; yyjson_val *key_, *val;