diff --git a/doc/json_schema.json b/doc/json_schema.json index 04266e383..231b9db3f 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1041,6 +1041,11 @@ "maximum": 400, "default": 10 }, + "compact": { + "description": "Set if multiple results should be printed in one line", + "type": "boolean", + "default": false + }, "key": { "$ref": "#/$defs/key" }, diff --git a/src/data/help.json b/src/data/help.json index 0d3424adb..2d99a0b3a 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -1000,6 +1000,14 @@ "default": 10 } }, + { + "long": "brightness-compact", + "desc": "Set if multiple results should be printed in one line", + "arg": { + "type": "bool", + "default": false + } + }, { "long": "sound-type", "desc": "Set what type of sound devices should be printed", diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index ca989d35b..c5740bc57 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -25,6 +25,24 @@ void ffPrintBrightness(FFBrightnessOptions* options) return; } + if (options->compact) + { + FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); + + FF_LIST_FOR_EACH(FFBrightnessResult, item, result) + { + if(str.length > 0) + ffStrbufAppendC(&str, ' '); + + const double percent = (item->current - item->min) / (item->max - item->min) * 100; + ffPercentAppendNum(&str, percent, options->percent, false, &options->moduleArgs); + } + + ffPrintLogoAndKey(FF_BRIGHTNESS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + ffStrbufPutTo(&str, stdout); + return; + } + FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); uint32_t index = 0; @@ -101,6 +119,12 @@ bool ffParseBrightnessCommandOptions(FFBrightnessOptions* options, const char* k return true; } + if (ffStrEqualsIgnCase(subKey, "compact")) + { + options->compact = ffOptionParseBoolean(value); + return true; + } + if (ffPercentParseCommandOptions(key, subKey, value, &options->percent)) return true; @@ -126,6 +150,12 @@ void ffParseBrightnessJsonObject(FFBrightnessOptions* options, yyjson_val* modul continue; } + if (ffStrEqualsIgnCase(key, "compact")) + { + options->compact = (uint32_t) yyjson_get_bool(val); + continue; + } + if (ffPercentParseJsonObject(key, val, &options->percent)) continue; @@ -144,6 +174,9 @@ void ffGenerateBrightnessJsonConfig(FFBrightnessOptions* options, yyjson_mut_doc yyjson_mut_obj_add_uint(doc, module, "ddcciSleep", options->ddcciSleep); ffPercentGenerateJsonConfig(doc, module, defaultOptions.percent, options->percent); + + if (defaultOptions.compact != options->compact) + yyjson_mut_obj_add_bool(doc, module, "compact", options->compact); } void ffGenerateBrightnessJsonResult(FF_MAYBE_UNUSED FFBrightnessOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) @@ -205,6 +238,7 @@ void ffInitBrightnessOptions(FFBrightnessOptions* options) options->ddcciSleep = 10; options->percent = (FFColorRangeConfig) { 100, 100 }; + options->compact = false; } void ffDestroyBrightnessOptions(FFBrightnessOptions* options) diff --git a/src/modules/brightness/option.h b/src/modules/brightness/option.h index 2623d0aea..e359cdc3e 100644 --- a/src/modules/brightness/option.h +++ b/src/modules/brightness/option.h @@ -12,4 +12,5 @@ typedef struct FFBrightnessOptions uint32_t ddcciSleep; // ms FFColorRangeConfig percent; + bool compact; } FFBrightnessOptions;