Display: add option --display-order

This commit is contained in:
李通洲
2024-02-22 10:47:13 +08:00
parent 77db2d84a3
commit 5e7cfe2976
4 changed files with 72 additions and 0 deletions
+42
View File
@@ -6,6 +6,16 @@
#define FF_DISPLAY_NUM_FORMAT_ARGS 8
static int sortByNameAsc(FFDisplayResult* a, FFDisplayResult* b)
{
return ffStrbufComp(&a->name, &b->name);
}
static int sortByNameDesc(FFDisplayResult* a, FFDisplayResult* b)
{
return -ffStrbufComp(&a->name, &b->name);
}
void ffPrintDisplay(FFDisplayOptions* options)
{
const FFDisplayServerResult* dsResult = ffConnectDisplayServer();
@@ -16,6 +26,11 @@ void ffPrintDisplay(FFDisplayOptions* options)
return;
}
if (options->order != FF_DISPLAY_ORDER_NONE)
{
ffListSort((FFlist*) &dsResult->displays, (void*) (options->order == FF_DISPLAY_ORDER_ASC ? sortByNameAsc : sortByNameDesc));
}
if (options->compactType != FF_DISPLAY_COMPACT_TYPE_NONE)
{
ffPrintLogoAndKey(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
@@ -133,6 +148,17 @@ bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, co
return true;
}
if (ffStrEqualsIgnCase(subKey, "order"))
{
options->order = (FFDisplayOrder) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
{ "asc", FF_DISPLAY_ORDER_ASC },
{ "desc", FF_DISPLAY_ORDER_DESC },
{ "none", FF_DISPLAY_ORDER_NONE },
{},
});
return true;
}
return false;
}
@@ -171,6 +197,22 @@ void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "order"))
{
int value;
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
{ "asc", FF_DISPLAY_ORDER_ASC },
{ "desc", FF_DISPLAY_ORDER_DESC },
{ "none", FF_DISPLAY_ORDER_NONE },
{},
});
if (error)
ffPrintError(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, "Invalid %s value: %s", key, error);
else
options->order = (FFDisplayOrder) value;
continue;
}
ffPrintError(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
+8
View File
@@ -11,6 +11,13 @@ typedef enum FFDisplayCompactType
FF_DISPLAY_COMPACT_TYPE_SCALED_BIT = 1 << 1,
} FFDisplayCompactType;
typedef enum FFDisplayOrder
{
FF_DISPLAY_ORDER_NONE,
FF_DISPLAY_ORDER_ASC,
FF_DISPLAY_ORDER_DESC,
} FFDisplayOrder;
typedef struct FFDisplayOptions
{
FFModuleBaseInfo moduleInfo;
@@ -18,4 +25,5 @@ typedef struct FFDisplayOptions
FFDisplayCompactType compactType;
bool preciseRefreshRate;
FFDisplayOrder order;
} FFDisplayOptions;