mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Display: add option --display-order
This commit is contained in:
parent
77db2d84a3
commit
5e7cfe2976
@ -1111,6 +1111,15 @@
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"order": {
|
||||
"description": "Set the order should be used when printing",
|
||||
"enum": [
|
||||
"none",
|
||||
"asc",
|
||||
"desc"
|
||||
],
|
||||
"default": "none"
|
||||
},
|
||||
"key": {
|
||||
"$ref": "#/$defs/key"
|
||||
},
|
||||
|
@ -1047,6 +1047,19 @@
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "display-order",
|
||||
"desc": "Set the order should be used when printing displays",
|
||||
"arg": {
|
||||
"type": "enum",
|
||||
"enum": {
|
||||
"none": "Use the detected order",
|
||||
"asc": "Sort by display name ascendingly",
|
||||
"desc": "Sort by display name descendingly"
|
||||
},
|
||||
"default": "none"
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "brightness-ddcci-sleep",
|
||||
"desc": "Set the sleep times (in ms) when sending DDC/CI requests",
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user