From 54f6b6a9c9f98dcc0d0fd6836bf081363e90efd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 20 Jun 2023 15:54:57 +0800 Subject: [PATCH] Display: remove `--detect-name` --- CHANGELOG.md | 1 + src/data/json_schema.jsonc | 6 ------ src/modules/brightness/brightness.c | 26 ++++++++++++++++++++++++-- src/modules/display/display.c | 15 +-------------- src/modules/display/option.h | 1 - 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 711ce403a..8429c1ac1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Changes: * Drop the dependency of cJSON. We now use [yyjson](https://ibireme.github.io/yyjson/doc/doxygen/html/index.html) to parse JSON documents. * Remove `--shell-version` and `--terminal-version`. They are always enabled * Remove `--*-error-format` +* Remove `--display-detect-name`. Display name is always detected, and will be printed if multiple displays are detected Features: * FreeBSD support is improved greatly, and actually tested in a phycial machine diff --git a/src/data/json_schema.jsonc b/src/data/json_schema.jsonc index b5edf812f..e3c335810 100644 --- a/src/data/json_schema.jsonc +++ b/src/data/json_schema.jsonc @@ -747,12 +747,6 @@ "description": "Set if all displays should be printed in one line", "default": "none" }, - "detectName": { - "title": "modules.display.detectName", - "description": "Set if display name should be detected and printed (if supported)", - "type": "boolean", - "default": false - }, "preciseRefreshRate": { "title": "modules.display.preciseRefreshRate", "description": "Set if decimal refresh rates should not be rounded into integers when printing", diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index 0a5be81b3..8f53caf77 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -1,6 +1,8 @@ +#include "common/bar.h" #include "common/printing.h" #include "common/jsonconfig.h" #include "detection/brightness/brightness.h" +#include "detection/displayserver/displayserver.h" #include "modules/brightness/brightness.h" #include "util/stringUtils.h" @@ -10,6 +12,8 @@ void ffPrintBrightness(FFinstance* instance, FFBrightnessOptions* options) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFBrightnessResult)); + const FFDisplayServerResult* ds = ffConnectDisplayServer(instance); + const char* error = ffDetectBrightness(&result); if(error) @@ -30,7 +34,9 @@ void ffPrintBrightness(FFinstance* instance, FFBrightnessOptions* options) { if(options->moduleArgs.key.length == 0) { - ffStrbufAppendF(&key, "%s (%s)", FF_BRIGHTNESS_MODULE_NAME, item->name.chars); + ffStrbufAppendS(&key, FF_BRIGHTNESS_MODULE_NAME); + if (ds->displays.length > 1) + ffStrbufAppendF(&key, " (%s)", item->name.chars); } else { @@ -39,10 +45,26 @@ void ffPrintBrightness(FFinstance* instance, FFBrightnessOptions* options) }); } + FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); + if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(instance, key.chars, 0, NULL, &options->moduleArgs.keyColor); - printf("%.0f%%\n", item->value); + + if (instance->config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) + { + ffAppendPercentBar(instance, &str, (uint8_t) (item->value + 0.5), 0, 10, 10); + } + + if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) + { + if(str.length > 0) + ffStrbufAppendC(&str, ' '); + + ffAppendPercentNum(instance, &str, (uint8_t) (item->value + 0.5), 10, 10, str.length > 0); + } + + ffStrbufPutTo(&str, stdout); } else { diff --git a/src/modules/display/display.c b/src/modules/display/display.c index 0034805a8..ddbe7536c 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -53,7 +53,7 @@ void ffPrintDisplay(FFinstance* instance, FFDisplayOptions* options) if(options->moduleArgs.outputFormat.length == 0) { - if((options->detectName && result->name.length) || (moduleIndex > 0 && displayType)) + if(moduleIndex > 0) { ffStrbufClear(&key); if(options->moduleArgs.key.length == 0) @@ -117,7 +117,6 @@ void ffInitDisplayOptions(FFDisplayOptions* options) options->moduleName = FF_DISPLAY_MODULE_NAME; ffOptionInitModuleArg(&options->moduleArgs); options->compactType = FF_DISPLAY_COMPACT_TYPE_NONE; - options->detectName = false; options->preciseRefreshRate = false; } @@ -139,12 +138,6 @@ bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, co return true; } - if (ffStrEqualsIgnCase(subKey, "detect-name")) - { - options->detectName = ffOptionParseBoolean(value); - return true; - } - if (ffStrEqualsIgnCase(subKey, "precise-refresh-rate")) { options->preciseRefreshRate = ffOptionParseBoolean(value); @@ -193,12 +186,6 @@ void ffParseDisplayJsonObject(FFinstance* instance, yyjson_val* module) continue; } - if (ffStrEqualsIgnCase(key, "detectName")) - { - options.detectName = yyjson_get_bool(val); - continue; - } - if (ffStrEqualsIgnCase(key, "preciseRefreshRate")) { options.preciseRefreshRate = yyjson_get_bool(val); diff --git a/src/modules/display/option.h b/src/modules/display/option.h index 4e47b1bee..20def688c 100644 --- a/src/modules/display/option.h +++ b/src/modules/display/option.h @@ -17,6 +17,5 @@ typedef struct FFDisplayOptions FFModuleArgs moduleArgs; FFDisplayCompactType compactType; - bool detectName; bool preciseRefreshRate; } FFDisplayOptions;