From b87997caa2ad9d035f4e0d89613503b03447d296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 14 Jun 2023 16:17:38 +0800 Subject: [PATCH] Logo: parse chafa options as enum --- src/logo/option.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/logo/option.c b/src/logo/option.c index 0239bf5ab..86574b680 100644 --- a/src/logo/option.c +++ b/src/logo/option.c @@ -314,15 +314,52 @@ const char* ffParseLogoJsonConfig(FFinstance* instance) yyjson_val* canvasMode = yyjson_obj_get(val, "canvasMode"); if (canvasMode) - options->chafaCanvasMode = (uint32_t) yyjson_get_uint(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 }, + {}, + }); + + if (error) return error; + options->chafaCanvasMode = (uint32_t) value; + } yyjson_val* colorSpace = yyjson_obj_get(val, "colorSpace"); if (colorSpace) - options->chafaColorSpace = (uint32_t) yyjson_get_uint(colorSpace); + { + int value; + const char* error = ffJsonConfigParseEnum(colorSpace, &value, (FFKeyValuePair[]) { + { "RGB", 0 }, + { "DIN99D", 1 }, + {}, + }); + + if (error) return error; + options->chafaColorSpace = (uint32_t) value; + } yyjson_val* ditherMode = yyjson_obj_get(val, "ditherMode"); if (ditherMode) - options->chafaDitherMode = (uint32_t) yyjson_get_uint(ditherMode); + { + int value; + const char* error = ffJsonConfigParseEnum(ditherMode, &value, (FFKeyValuePair[]) { + { "NONE", 0 }, + { "ORDERED", 1 }, + { "DIFFUSION", 2 }, + {}, + }); + + if (error) return error; + options->chafaDitherMode = (uint32_t) value; + } continue; } else