From 42b756e703ab14477e043a2f2031c1d23fa5d09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 24 Feb 2024 12:50:21 +0800 Subject: [PATCH 01/14] GPU (Linux): revert `show sub-device if available` --- src/detection/gpu/gpu.h | 2 +- src/detection/gpu/gpu_bsd.c | 2 +- src/detection/gpu/gpu_linux.c | 2 +- src/detection/gpu/gpu_pci.c | 9 +-------- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index 8f404f243..9558af0b5 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -44,5 +44,5 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus); const char* ffGetGPUVendorString(unsigned vendorId); #if defined(__linux__) || defined(__FreeBSD__) -void ffGPUParsePciIds(FFstrbuf* content, uint8_t subclass, uint16_t vendor, uint16_t device, uint16_t subVendor, uint16_t subDevice, FFGPUResult* gpu); +void ffGPUParsePciIds(FFstrbuf* content, uint8_t subclass, uint16_t vendor, uint16_t device, FFGPUResult* gpu); #endif diff --git a/src/detection/gpu/gpu_bsd.c b/src/detection/gpu/gpu_bsd.c index ed0f7337d..e0ac12f11 100644 --- a/src/detection/gpu/gpu_bsd.c +++ b/src/detection/gpu/gpu_bsd.c @@ -74,7 +74,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) { if (pciids.length == 0) loadPciIds(&pciids); - ffGPUParsePciIds(&pciids, pc->pc_subclass, pc->pc_vendor, pc->pc_device, pc->pc_subvendor, pc->pc_subdevice, gpu); + ffGPUParsePciIds(&pciids, pc->pc_subclass, pc->pc_vendor, pc->pc_device, gpu); } #ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index c97660b9d..1a8dead18 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -143,7 +143,7 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus) { if (!pciids.length) loadPciIds(&pciids); - ffGPUParsePciIds(&pciids, subclassId, (uint16_t) vendorId, (uint16_t) deviceId, (uint16_t) subVendorId, (uint16_t) subDeviceId, gpu); + ffGPUParsePciIds(&pciids, subclassId, (uint16_t) vendorId, (uint16_t) deviceId, gpu); } pciDetectDriver(gpu, &pciDir, &buffer); diff --git a/src/detection/gpu/gpu_pci.c b/src/detection/gpu/gpu_pci.c index e8d454aec..c4b1e56ff 100644 --- a/src/detection/gpu/gpu_pci.c +++ b/src/detection/gpu/gpu_pci.c @@ -1,6 +1,6 @@ #include "gpu.h" -void ffGPUParsePciIds(FFstrbuf* content, uint8_t subclass, uint16_t vendor, uint16_t device, uint16_t subVendor, uint16_t subDevice, FFGPUResult* gpu) +void ffGPUParsePciIds(FFstrbuf* content, uint8_t subclass, uint16_t vendor, uint16_t device, FFGPUResult* gpu) { if (content->length) { @@ -40,13 +40,6 @@ void ffGPUParsePciIds(FFstrbuf* content, uint8_t subclass, uint16_t vendor, uint if (start) { start += len; - - // Search for subvendor and subdevice - len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n\t\t%04x %04x ", subVendor, subDevice); - char* subStart = memmem(start, (size_t) (end - start), buffer, len); - if (subStart) - start = subStart + len; - end = memchr(start, '\n', (uint32_t) (end - start)); if (!end) end = content->chars + content->length; From 1c8769386762456b995e923a12e017c23eefd581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 26 Feb 2024 10:23:00 +0800 Subject: [PATCH 02/14] Percent: tidy --- src/common/percent.c | 6 +++--- src/options/display.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/common/percent.c b/src/common/percent.c index 306838d06..9c52970ed 100644 --- a/src/common/percent.c +++ b/src/common/percent.c @@ -89,9 +89,9 @@ void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentConfig config if (colored && !options->pipe) { - const char* colorGreen = instance.config.display.percentColorGreen.chars; - const char* colorYellow = instance.config.display.percentColorYellow.chars; - const char* colorRed = instance.config.display.percentColorRed.chars; + const char* colorGreen = options->percentColorGreen.chars; + const char* colorYellow = options->percentColorYellow.chars; + const char* colorRed = options->percentColorRed.chars; if(percent != percent) ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_BLACK "m"); diff --git a/src/options/display.c b/src/options/display.c index 5ba60b58e..c1b254b5d 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -452,6 +452,17 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do yyjson_mut_obj_add_uint(doc, percent, "type", options->percentType); if (options->percentNdigits != defaultOptions.percentNdigits) yyjson_mut_obj_add_uint(doc, percent, "ndigits", options->percentNdigits); + { + yyjson_mut_val* color = yyjson_mut_obj(doc); + if (!ffStrbufEqual(&options->percentColorGreen, &defaultOptions.percentColorGreen)) + yyjson_mut_obj_add_strbuf(doc, color, "green", &options->percentColorGreen); + if (!ffStrbufEqual(&options->percentColorYellow, &defaultOptions.percentColorYellow)) + yyjson_mut_obj_add_strbuf(doc, color, "yellow", &options->percentColorYellow); + if (!ffStrbufEqual(&options->percentColorRed, &defaultOptions.percentColorRed)) + yyjson_mut_obj_add_strbuf(doc, color, "red", &options->percentColorRed); + if (yyjson_mut_obj_size(color) > 0) + yyjson_mut_obj_add_val(doc, percent, "color", color); + } if (yyjson_mut_obj_size(percent) > 0) yyjson_mut_obj_add_val(doc, obj, "percent", percent); } From a0c47204bb438a71cae8a7b89ef8daf1bbb48c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 26 Feb 2024 10:46:13 +0800 Subject: [PATCH 03/14] Temp: Display: support better temperature value formatting Fix #737 --- CHANGELOG.md | 13 +++ doc/json_schema.json | 41 +++++++- src/common/parsing.c | 30 +++++- src/data/help.json | 35 +++++++ src/modules/battery/battery.c | 6 +- src/modules/cpu/cpu.c | 6 +- src/modules/gpu/gpu.c | 4 +- src/modules/physicaldisk/physicaldisk.c | 6 +- src/options/display.c | 133 +++++++++++++++++------- src/options/display.h | 4 + 10 files changed, 227 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cf70d53b..80dc9de96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +# 2.8.6 + +Changes: +* Due to newly introduced configs, JSONC option `{ "temperatureUnit": "C" }` has been changed to `{ "temperature": { "unit": "C" } }` + +Bugfixes: +* Fix incorrect GPU name detection for Intel iGPU on Linux (#736, GPU, Linux) + +Features: +* Support additional temperature formatting options (#737) + * `{ "temperature": { "ndigits": 1 } }` + * `{ "temperature": { "color": { "green": "green", "yellow": "yellow", "red": "red" } } }` + # 2.8.5 Bugfixes: diff --git a/doc/json_schema.json b/doc/json_schema.json index 198ec8e2c..5b7b89b7e 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -407,11 +407,42 @@ } } }, - "temperatureUnit": { - "type": "string", - "description": "Set the unit of the temperature", - "enum": ["CELSIUS", "C", "FAHRENHEIT", "F", "KELVIN", "K"], - "default": "C" + "temperature": { + "type": "object", + "description": "Set how a temperature value should be displayed", + "properties": { + "unit": { + "type": "string", + "description": "Set the unit of the temperature", + "enum": ["CELSIUS", "C", "FAHRENHEIT", "F", "KELVIN", "K"], + "default": "C" + }, + "ndigits": { + "type": "integer", + "description": "Set the number of digits to keep after the decimal point when formatting temperature values", + "minimum": 0, + "maximum": 9, + "default": 1 + }, + "color": { + "type": "object", + "description": "Set color used in different states of temperature values", + "properties": { + "green": { + "description": "Color used in green state", + "$ref": "#/$defs/colors" + }, + "yellow": { + "description": "Color used in yellow state", + "$ref": "#/$defs/colors" + }, + "red": { + "description": "Color used in red state", + "$ref": "#/$defs/colors" + } + } + } + } }, "bar": { "type": "object", diff --git a/src/common/parsing.c b/src/common/parsing.c index 5f5b18d04..f4833fd35 100644 --- a/src/common/parsing.c +++ b/src/common/parsing.c @@ -1,5 +1,6 @@ #include "fastfetch.h" #include "common/parsing.h" +#include "util/textModifier.h" #include #include @@ -98,18 +99,39 @@ void ffParseSize(uint64_t bytes, FFstrbuf* result) void ffParseTemperature(double celsius, FFstrbuf* buffer) { - switch (instance.config.display.temperatureUnit) + if (celsius != celsius) // ignores NaN + return; + + const FFOptionsDisplay* options = &instance.config.display; + const char* colorGreen = options->temperatureColorGreen.chars; + const char* colorYellow = options->temperatureColorYellow.chars; + const char* colorRed = options->temperatureColorRed.chars; + + if (!options->pipe) + { + if (celsius < 50) + ffStrbufAppendF(buffer, "\e[%sm", colorGreen); + else if (celsius < 80) + ffStrbufAppendF(buffer, "\e[%sm", colorYellow); + else + ffStrbufAppendF(buffer, "\e[%sm", colorRed); + } + + switch (options->temperatureUnit) { case FF_TEMPERATURE_UNIT_CELSIUS: - ffStrbufAppendF(buffer, "%.1f°C", celsius); + ffStrbufAppendF(buffer, "%.*f°C", options->temperatureNdigits, celsius); break; case FF_TEMPERATURE_UNIT_FAHRENHEIT: - ffStrbufAppendF(buffer, "%.1f°F", celsius * 1.8 + 32); + ffStrbufAppendF(buffer, "%.*f°F", options->temperatureNdigits, celsius * 1.8 + 32); break; case FF_TEMPERATURE_UNIT_KELVIN: - ffStrbufAppendF(buffer, "%.1f K", celsius + 273.15); + ffStrbufAppendF(buffer, "%.*f K", options->temperatureNdigits, celsius + 273.15); break; } + + if (!options->pipe) + ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); } void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4) diff --git a/src/data/help.json b/src/data/help.json index 752295eec..5199b1b42 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -667,6 +667,41 @@ }, "default": "C" } + }, + { + "long": "temperature-ndigits", + "desc": "Set the number of digits to keep after the decimal point when printing temperature", + "arg": { + "type": "num", + "default": 2 + } + }, + { + "long": "temperature-color-green", + "desc": "Set color used in green state of temperature values", + "remark": "See `-h color` for the list of available colors", + "arg": { + "type": "color", + "default": "green" + } + }, + { + "long": "temperature-color-yellow", + "desc": "Set color used in yellow state of temperature values", + "remark": "See `-h color` for the list of available colors", + "arg": { + "type": "color", + "default": "light_yellow" + } + }, + { + "long": "temperature-color-red", + "desc": "Set color used in red state of temperature values", + "remark": "See `-h color` for the list of available colors", + "arg": { + "type": "color", + "default": "light_red" + } } ], "Library path": [ diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index a97dd263b..bab7d5db0 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -58,13 +58,15 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin { FF_STRBUF_AUTO_DESTROY capacityStr = ffStrbufCreate(); ffPercentAppendNum(&capacityStr, result->capacity, options->percent, false); + FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); + ffParseTemperature(result->temperature, &tempStr); ffPrintFormat(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->technology}, {FF_FORMAT_ARG_TYPE_STRBUF, &capacityStr}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->status}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature}, + {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr}, {FF_FORMAT_ARG_TYPE_UINT, &result->cycleCount}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->serial}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufactureDate}, @@ -226,7 +228,7 @@ void ffPrintBatteryHelpFormat(void) "Battery technology", "Battery capacity (percentage)", "Battery status", - "Battery temperature", + "Battery temperature (formatted)", "Battery cycle count", "Battery serial number", "Battery manufactor date", diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index f1ee0e84f..c2716b528 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -60,6 +60,8 @@ void ffPrintCPU(FFCPUOptions* options) } else { + FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); + ffParseTemperature(cpu.temperature, &tempStr); ffPrintFormat(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &cpu.name}, {FF_FORMAT_ARG_TYPE_STRBUF, &cpu.vendor}, @@ -68,7 +70,7 @@ void ffPrintCPU(FFCPUOptions* options) {FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresOnline}, {FF_FORMAT_ARG_TYPE_DOUBLE, &cpu.frequencyMin}, {FF_FORMAT_ARG_TYPE_DOUBLE, &cpu.frequencyMax}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &cpu.temperature} + {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr} }); } } @@ -193,7 +195,7 @@ void ffPrintCPUHelpFormat(void) "Online core count", "Min frequency", "Max frequency", - "Temperature" + "Temperature (formatted)" }); } diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index b8c3118a4..270872127 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -72,11 +72,13 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu } else { + FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); + ffParseTemperature(gpu->temperature, &tempStr); ffPrintFormat(FF_GPU_MODULE_NAME, index, &options->moduleArgs, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor}, {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name}, {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature}, + {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr}, {FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount}, {FF_FORMAT_ARG_TYPE_STRING, type}, {FF_FORMAT_ARG_TYPE_UINT64, &gpu->dedicated.total}, diff --git a/src/modules/physicaldisk/physicaldisk.c b/src/modules/physicaldisk/physicaldisk.c index 864f5a673..01f5033c5 100644 --- a/src/modules/physicaldisk/physicaldisk.c +++ b/src/modules/physicaldisk/physicaldisk.c @@ -102,6 +102,8 @@ void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options) } else { + FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); + ffParseTemperature(dev->temperature, &tempStr); if (dev->type & FF_PHYSICALDISK_TYPE_READWRITE) readOnlyType = "Read-write"; ffParseSize(dev->size, &buffer); @@ -115,7 +117,7 @@ void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options) {FF_FORMAT_ARG_TYPE_STRING, removableType}, {FF_FORMAT_ARG_TYPE_STRING, readOnlyType}, {FF_FORMAT_ARG_TYPE_STRBUF, &dev->revision}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &dev->temperature}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &tempStr}, }); } ++index; @@ -263,7 +265,7 @@ void ffPrintPhysicalDiskHelpFormat(void) "Device kind (Removable or Fixed)", "Device kind (Read-only or Read-write)", "Product revision", - "Device temperature", + "Device temperature (formatted)", }); } diff --git a/src/options/display.c b/src/options/display.c index c1b254b5d..7adccaa8c 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -94,20 +94,46 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va yyjson_val* ndigits = yyjson_obj_get(val, "ndigits"); if (ndigits) options->percentNdigits = (uint8_t) yyjson_get_uint(ndigits); } - else if (ffStrEqualsIgnCase(key, "temperatureUnit")) + else if (ffStrEqualsIgnCase(key, "temperature")) { - int value; - const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { - { "CELSIUS", FF_TEMPERATURE_UNIT_CELSIUS }, - { "C", FF_TEMPERATURE_UNIT_CELSIUS }, - { "FAHRENHEIT", FF_TEMPERATURE_UNIT_FAHRENHEIT }, - { "F", FF_TEMPERATURE_UNIT_FAHRENHEIT }, - { "KELVIN", FF_TEMPERATURE_UNIT_KELVIN }, - { "K", FF_TEMPERATURE_UNIT_KELVIN }, - {}, - }); - if (error) return error; - options->temperatureUnit = (FFTemperatureUnit) value; + if (!yyjson_is_obj(val)) + return "display.temperature must be an object"; + + yyjson_val* unit = yyjson_obj_get(val, "unit"); + if (unit) + { + int value; + const char* error = ffJsonConfigParseEnum(unit, &value, (FFKeyValuePair[]) { + { "CELSIUS", FF_TEMPERATURE_UNIT_CELSIUS }, + { "C", FF_TEMPERATURE_UNIT_CELSIUS }, + { "FAHRENHEIT", FF_TEMPERATURE_UNIT_FAHRENHEIT }, + { "F", FF_TEMPERATURE_UNIT_FAHRENHEIT }, + { "KELVIN", FF_TEMPERATURE_UNIT_KELVIN }, + { "K", FF_TEMPERATURE_UNIT_KELVIN }, + {}, + }); + if (error) return error; + options->temperatureUnit = (FFTemperatureUnit) value; + } + + yyjson_val* ndigits = yyjson_obj_get(val, "ndigits"); + if (ndigits) options->temperatureNdigits = (uint8_t) yyjson_get_uint(ndigits); + + yyjson_val* color = yyjson_obj_get(val, "color"); + if (color) + { + if (!yyjson_is_obj(color)) + return "display.temperature.color must be an object"; + + yyjson_val* green = yyjson_obj_get(color, "green"); + if (green) ffOptionParseColor(yyjson_get_str(green), &options->temperatureColorGreen); + + yyjson_val* yellow = yyjson_obj_get(color, "yellow"); + if (yellow) ffOptionParseColor(yyjson_get_str(yellow), &options->temperatureColorYellow); + + yyjson_val* red = yyjson_obj_get(color, "red"); + if (red) ffOptionParseColor(yyjson_get_str(red), &options->temperatureColorRed); + } } else if (ffStrEqualsIgnCase(key, "percent")) { @@ -253,17 +279,31 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key {} }); } - else if(ffStrEqualsIgnCase(key, "--temperature-unit")) + else if(ffStrStartsWithIgnCase(key, "--temperature-")) { - options->temperatureUnit = (FFTemperatureUnit) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { - { "CELSIUS", FF_TEMPERATURE_UNIT_CELSIUS }, - { "C", FF_TEMPERATURE_UNIT_CELSIUS }, - { "FAHRENHEIT", FF_TEMPERATURE_UNIT_FAHRENHEIT }, - { "F", FF_TEMPERATURE_UNIT_FAHRENHEIT }, - { "KELVIN", FF_TEMPERATURE_UNIT_KELVIN }, - { "K", FF_TEMPERATURE_UNIT_KELVIN }, - {}, - }); + const char* subkey = key + strlen("--temperature-"); + if(ffStrEqualsIgnCase(subkey, "unit")) + { + options->temperatureUnit = (FFTemperatureUnit) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { + { "CELSIUS", FF_TEMPERATURE_UNIT_CELSIUS }, + { "C", FF_TEMPERATURE_UNIT_CELSIUS }, + { "FAHRENHEIT", FF_TEMPERATURE_UNIT_FAHRENHEIT }, + { "F", FF_TEMPERATURE_UNIT_FAHRENHEIT }, + { "KELVIN", FF_TEMPERATURE_UNIT_KELVIN }, + { "K", FF_TEMPERATURE_UNIT_KELVIN }, + {}, + }); + } + else if (ffStrEqualsIgnCase(subkey, "ndigits")) + options->temperatureNdigits = (uint8_t) ffOptionParseUInt32(key, value); + else if(ffStrEqualsIgnCase(subkey, "color-green")) + ffOptionParseColor(value, &options->temperatureColorGreen); + else if(ffStrEqualsIgnCase(subkey, "color-yellow")) + ffOptionParseColor(value, &options->temperatureColorYellow); + else if(ffStrEqualsIgnCase(subkey, "color-red")) + ffOptionParseColor(value, &options->temperatureColorRed); + else + return false; } else if(ffStrStartsWithIgnCase(key, "--percent-")) { @@ -323,11 +363,16 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options) options->binaryPrefixType = FF_BINARY_PREFIX_TYPE_IEC; options->sizeNdigits = 2; options->sizeMaxPrefix = UINT8_MAX; - options->temperatureUnit = FF_TEMPERATURE_UNIT_CELSIUS; options->stat = false; options->noBuffer = false; options->keyWidth = 0; + options->temperatureUnit = FF_TEMPERATURE_UNIT_CELSIUS; + options->temperatureNdigits = 1; + ffStrbufInitStatic(&options->temperatureColorGreen, FF_COLOR_FG_GREEN); + ffStrbufInitStatic(&options->temperatureColorYellow, FF_COLOR_FG_LIGHT_YELLOW); + ffStrbufInitStatic(&options->temperatureColorRed, FF_COLOR_FG_LIGHT_RED); + ffStrbufInitStatic(&options->barCharElapsed, "■"); ffStrbufInitStatic(&options->barCharTotal, "-"); options->barWidth = 10; @@ -430,20 +475,38 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do yyjson_mut_obj_add_val(doc, obj, "size", size); } - if (options->temperatureUnit != defaultOptions.temperatureUnit) { - switch (options->temperatureUnit) + yyjson_mut_val* temperature = yyjson_mut_obj(doc); + if (options->temperatureUnit != defaultOptions.temperatureUnit) { - case FF_TEMPERATURE_UNIT_CELSIUS: - yyjson_mut_obj_add_str(doc, obj, "temperatureUnit", "C"); - break; - case FF_TEMPERATURE_UNIT_FAHRENHEIT: - yyjson_mut_obj_add_str(doc, obj, "temperatureUnit", "F"); - break; - case FF_TEMPERATURE_UNIT_KELVIN: - yyjson_mut_obj_add_str(doc, obj, "temperatureUnit", "K"); - break; + switch (options->temperatureUnit) + { + case FF_TEMPERATURE_UNIT_CELSIUS: + yyjson_mut_obj_add_str(doc, obj, "unit", "C"); + break; + case FF_TEMPERATURE_UNIT_FAHRENHEIT: + yyjson_mut_obj_add_str(doc, obj, "unit", "F"); + break; + case FF_TEMPERATURE_UNIT_KELVIN: + yyjson_mut_obj_add_str(doc, obj, "unit", "K"); + break; + } + } + if (options->temperatureNdigits != defaultOptions.temperatureNdigits) + yyjson_mut_obj_add_uint(doc, temperature, "ndigits", options->temperatureNdigits); + { + yyjson_mut_val* color = yyjson_mut_obj(doc); + if (!ffStrbufEqual(&options->temperatureColorGreen, &defaultOptions.temperatureColorGreen)) + yyjson_mut_obj_add_strbuf(doc, color, "green", &options->temperatureColorGreen); + if (!ffStrbufEqual(&options->temperatureColorYellow, &defaultOptions.temperatureColorYellow)) + yyjson_mut_obj_add_strbuf(doc, color, "yellow", &options->temperatureColorYellow); + if (!ffStrbufEqual(&options->temperatureColorRed, &defaultOptions.temperatureColorRed)) + yyjson_mut_obj_add_strbuf(doc, color, "red", &options->temperatureColorRed); + if (yyjson_mut_obj_size(color) > 0) + yyjson_mut_obj_add_val(doc, temperature, "color", color); } + if (yyjson_mut_obj_size(temperature) > 0) + yyjson_mut_obj_add_val(doc, obj, "temperature", temperature); } { diff --git a/src/options/display.h b/src/options/display.h index 296e95a24..2d800150e 100644 --- a/src/options/display.h +++ b/src/options/display.h @@ -35,6 +35,10 @@ typedef struct FFOptionsDisplay uint8_t sizeNdigits; uint8_t sizeMaxPrefix; FFTemperatureUnit temperatureUnit; + uint8_t temperatureNdigits; + FFstrbuf temperatureColorGreen; + FFstrbuf temperatureColorYellow; + FFstrbuf temperatureColorRed; FFstrbuf barCharElapsed; FFstrbuf barCharTotal; uint8_t barWidth; From 609caad02fc3219c52303369e5a7d8d6af5a548c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 26 Feb 2024 13:30:09 +0800 Subject: [PATCH 04/14] Global: use FASTFETCH_TARGET_DIR_USR where applicable --- src/detection/de/de_linux.c | 4 ++-- src/detection/gpu/gpu_bsd.c | 2 +- src/detection/gpu/gpu_linux.c | 6 +++--- src/detection/lm/lm_linux.c | 2 +- src/detection/packages/packages_apple.c | 10 +++++----- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/detection/de/de_linux.c b/src/detection/de/de_linux.c index 90326c226..5f7fd8839 100644 --- a/src/detection/de/de_linux.c +++ b/src/detection/de/de_linux.c @@ -12,7 +12,7 @@ static void getKDE(FFstrbuf* result, FFDEOptions* options) { - ffParsePropFileValues("/usr/share/xsessions/plasmax11.desktop", 1, (FFpropquery[]) { + ffParsePropFileValues(FASTFETCH_TARGET_DIR_USR "/share/xsessions/plasmax11.desktop", 1, (FFpropquery[]) { {"X-KDE-PluginInfo-Version =", result} }); if(result->length == 0) @@ -21,7 +21,7 @@ static void getKDE(FFstrbuf* result, FFDEOptions* options) ffParsePropFileData("xsessions/plasma5.desktop", "X-KDE-PluginInfo-Version =", result); if(result->length == 0) { - ffParsePropFileValues("/usr/share/wayland-sessions/plasma.desktop", 1, (FFpropquery[]) { + ffParsePropFileValues(FASTFETCH_TARGET_DIR_USR "/share/wayland-sessions/plasma.desktop", 1, (FFpropquery[]) { {"X-KDE-PluginInfo-Version =", result} }); } diff --git a/src/detection/gpu/gpu_bsd.c b/src/detection/gpu/gpu_bsd.c index e0ac12f11..2bca0137b 100644 --- a/src/detection/gpu/gpu_bsd.c +++ b/src/detection/gpu/gpu_bsd.c @@ -17,7 +17,7 @@ static bool loadPciIds(FFstrbuf* pciids) ffReadFileBuffer(_PATH_LOCALBASE "/share/pciids/pci.ids", pciids); if (pciids->length > 0) return true; - ffReadFileBuffer("/usr/share/pciids/pci.ids", pciids); + ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/share/pciids/pci.ids", pciids); if (pciids->length > 0) return true; return false; diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 1a8dead18..1c5b2f3c5 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -53,13 +53,13 @@ static void pciDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer static bool loadPciIds(FFstrbuf* pciids) { - ffReadFileBuffer("/usr/share/hwdata/pci.ids", pciids); + ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/share/hwdata/pci.ids", pciids); if (pciids->length > 0) return true; - ffReadFileBuffer("/usr/share/misc/pci.ids", pciids); // debian? + ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/share/misc/pci.ids", pciids); // debian? if (pciids->length > 0) return true; - ffReadFileBuffer("/usr/local/share/hwdata/pci.ids", pciids); + ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/local/share/hwdata/pci.ids", pciids); if (pciids->length > 0) return true; return false; diff --git a/src/detection/lm/lm_linux.c b/src/detection/lm/lm_linux.c index c91fdf477..a792da592 100644 --- a/src/detection/lm/lm_linux.c +++ b/src/detection/lm/lm_linux.c @@ -63,7 +63,7 @@ static const char* getSddmVersion(FFstrbuf* version) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzrewind) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzclose) - gzFile file = ffgzopen("/usr/share/man/man1/sddm.1.gz", "rb"); + gzFile file = ffgzopen(FASTFETCH_TARGET_DIR_USR "/share/man/man1/sddm.1.gz", "rb"); if (file == Z_NULL) return "ffgzopen(\"/usr/share/man/man1/sddm.1.gz\", \"rb\") failed"; diff --git a/src/detection/packages/packages_apple.c b/src/detection/packages/packages_apple.c index e770f3f59..385926626 100644 --- a/src/detection/packages/packages_apple.c +++ b/src/detection/packages/packages_apple.c @@ -45,14 +45,14 @@ static void getBrewPackages(FFPackagesResult* result) if(ffStrSet(prefix)) return countBrewPackages(prefix, result); - countBrewPackages(FASTFETCH_TARGET_DIR_ROOT"/opt/homebrew", result); - countBrewPackages(FASTFETCH_TARGET_DIR_ROOT"/usr/local", result); + countBrewPackages(FASTFETCH_TARGET_DIR_ROOT "/opt/homebrew", result); + countBrewPackages(FASTFETCH_TARGET_DIR_USR "/local", result); } static uint32_t countMacPortsPackages(const char* dirname) { FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateS(dirname); - ffStrbufAppendS(&baseDir, "/var/macports/software"); + ffStrbufAppendS(&baseDir, FASTFETCH_TARGET_DIR_ROOT "/var/macports/software"); return getNumElements(baseDir.chars, DT_DIR); } @@ -63,7 +63,7 @@ static uint32_t getMacPortsPackages() if(ffStrSet(prefix)) return countMacPortsPackages(prefix); - return countMacPortsPackages(FASTFETCH_TARGET_DIR_ROOT"/opt/local"); + return countMacPortsPackages(FASTFETCH_TARGET_DIR_ROOT "/opt/local"); } static uint32_t getNixPackagesImpl(char* path) @@ -81,7 +81,7 @@ static uint32_t getNixPackagesImpl(char* path) ffStrbufAppendS(&command, "); do if [ -d $x ]; then echo $x ; fi ; done | cut -d- -f2- | egrep '([0-9]{1,}\\.)+[0-9]{1,}' | egrep -v '\\-doc$|\\-man$|\\-info$|\\-dev$|\\-bin$|^nixos-system-nixos-' | uniq | wc -l"); ffProcessAppendStdOut(&output, (char* const[]) { - "/bin/sh", + FASTFETCH_TARGET_DIR_ROOT "/bin/sh", "-c", command.chars, NULL From 743eebaa6bf39117b0f9460c1f8844152125a173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 26 Feb 2024 13:35:11 +0800 Subject: [PATCH 05/14] CMake (macOS): force `dlopen` searching for `/usr/local/lib` --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33292fb32..0706620cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -724,8 +724,8 @@ if(yyjson_FOUND) else() # Used for dlopen finding dylibs installed by homebrew # `/opt/homebrew/lib` is not on in dlopen search path by default - if(APPLE AND DEFINED ENV{HOMEBREW_PREFIX}) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,$ENV{HOMEBREW_PREFIX}/lib") + if(APPLE) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/opt/homebrew/lib -Wl,-rpath,/usr/local/lib") endif() endif() From e046787aeca230693b4df792978258e15af4efcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 26 Feb 2024 23:33:30 +0800 Subject: [PATCH 06/14] Terminal: better tmux version detection --- src/detection/terminalshell/terminalshell.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index be83accd5..bd21025b2 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -423,6 +423,20 @@ static bool getTerminalVersionScreen(FFstrbuf* exe, FFstrbuf* version) return version->length > 0; } +static bool getTerminalVersionTmux(FFstrbuf* exe, FFstrbuf* version) +{ + if (ffProcessAppendStdOut(version, (char* const[]) { + exe->chars, + "-V", + NULL + }) != NULL) + return false; + + // tmux 3.4 + ffStrbufSubstrAfterFirstC(version, ' '); + return version->length > 0; +} + #ifdef _WIN32 static bool getTerminalVersionWindowsTerminal(FFstrbuf* exe, FFstrbuf* version) @@ -572,6 +586,9 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe } } + if(ffStrbufStartsWithIgnCaseS(processName, "tmux")) + return getTerminalVersionTmux(exe, version); + #ifdef _WIN32 return getFileVersion(exe->chars, version); From 8f205b8c30cf0a13190b9aca5e2136fc90e112bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 26 Feb 2024 15:12:04 +0800 Subject: [PATCH 07/14] Percent: rename FFPercentConfig to FFColorRangeConfig --- src/common/parsing.h | 8 +++++++- src/common/percent.c | 10 +++++----- src/common/percent.h | 17 ++++++----------- src/modules/battery/battery.c | 2 +- src/modules/battery/option.h | 2 +- src/modules/bluetooth/bluetooth.c | 2 +- src/modules/bluetooth/option.h | 2 +- src/modules/brightness/brightness.c | 2 +- src/modules/brightness/option.h | 2 +- src/modules/cpuusage/cpuusage.c | 2 +- src/modules/cpuusage/option.h | 2 +- src/modules/disk/disk.c | 2 +- src/modules/disk/option.h | 2 +- src/modules/gamepad/gamepad.c | 2 +- src/modules/gamepad/option.h | 2 +- src/modules/gpu/gpu.c | 2 +- src/modules/gpu/option.h | 2 +- src/modules/memory/memory.c | 2 +- src/modules/memory/option.h | 2 +- src/modules/sound/option.h | 2 +- src/modules/sound/sound.c | 2 +- src/modules/swap/option.h | 2 +- src/modules/swap/swap.c | 2 +- 23 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/common/parsing.h b/src/common/parsing.h index e98883b06..24fd13528 100644 --- a/src/common/parsing.h +++ b/src/common/parsing.h @@ -1,6 +1,6 @@ #pragma once -#include "fastfetch.h" +#include "util/FFstrbuf.h" #include @@ -11,6 +11,12 @@ typedef struct FFVersion uint32_t patch; } FFVersion; +typedef struct FFColorRangeConfig +{ + uint8_t green; + uint8_t yellow; +} FFColorRangeConfig; + #define FF_VERSION_INIT ((FFVersion) {0}) void ffParseSemver(FFstrbuf* buffer, const FFstrbuf* major, const FFstrbuf* minor, const FFstrbuf* patch); diff --git a/src/common/percent.c b/src/common/percent.c index 9c52970ed..a80f3ed10 100644 --- a/src/common/percent.c +++ b/src/common/percent.c @@ -6,7 +6,7 @@ #include "util/textModifier.h" #include "util/stringUtils.h" -void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentConfig config) +void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig config) { uint8_t green = config.green, yellow = config.yellow; assert(green <= 100 && yellow <= 100); @@ -75,7 +75,7 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentConfig config ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); } -void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentConfig config, bool parentheses) +void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFColorRangeConfig config, bool parentheses) { uint8_t green = config.green, yellow = config.yellow; assert(green <= 100 && yellow <= 100); @@ -126,7 +126,7 @@ void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentConfig config ffStrbufAppendC(buffer, ')'); } -bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFPercentConfig* config) +bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFColorRangeConfig* config) { if (!ffStrStartsWithIgnCase(subkey, "percent-")) return false; @@ -160,7 +160,7 @@ bool ffPercentParseCommandOptions(const char* key, const char* subkey, const cha return false; } -bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentConfig* config) +bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFColorRangeConfig* config) { if (!ffStrEqualsIgnCase(key, "percent")) return false; @@ -198,7 +198,7 @@ bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentConfi return true; } -void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentConfig defaultConfig, FFPercentConfig config) +void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFColorRangeConfig defaultConfig, FFColorRangeConfig config) { if (config.green == defaultConfig.green && config.yellow == defaultConfig.yellow) return; diff --git a/src/common/percent.h b/src/common/percent.h index e3e83b4a4..6d7c6b2e8 100644 --- a/src/common/percent.h +++ b/src/common/percent.h @@ -1,6 +1,7 @@ #pragma once #include "util/FFstrbuf.h" +#include "common/parsing.h" enum { @@ -10,12 +11,6 @@ enum FF_PERCENTAGE_TYPE_NUM_COLOR_BIT = 1 << 3, }; -typedef struct FFPercentConfig -{ - uint8_t green; - uint8_t yellow; -} FFPercentConfig; - // if (green <= yellow) // [0, green]: print green // (green, yellow]: print yellow @@ -26,12 +21,12 @@ typedef struct FFPercentConfig // [yellow, green): print yellow // [0, yellow): print red -void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentConfig config); -void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentConfig config, bool parentheses); +void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig config); +void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFColorRangeConfig config, bool parentheses); typedef struct yyjson_val yyjson_val; typedef struct yyjson_mut_doc yyjson_mut_doc; typedef struct yyjson_mut_val yyjson_mut_val; -bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFPercentConfig* config); -bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentConfig* config); -void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentConfig defaultConfig, FFPercentConfig config); +bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFColorRangeConfig* config); +bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFColorRangeConfig* config); +void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFColorRangeConfig defaultConfig, FFColorRangeConfig config); diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index bab7d5db0..ccfed5d09 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -250,7 +250,7 @@ void ffInitBatteryOptions(FFBatteryOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; - options->percent = (FFPercentConfig) { 50, 20 }; + options->percent = (FFColorRangeConfig) { 50, 20 }; #ifdef _WIN32 options->useSetupApi = false; diff --git a/src/modules/battery/option.h b/src/modules/battery/option.h index c03537a37..4fa9e8f5c 100644 --- a/src/modules/battery/option.h +++ b/src/modules/battery/option.h @@ -11,7 +11,7 @@ typedef struct FFBatteryOptions FFModuleArgs moduleArgs; bool temp; - FFPercentConfig percent; + FFColorRangeConfig percent; #ifdef _WIN32 bool useSetupApi; diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index 79a7539c1..02c14975c 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -198,7 +198,7 @@ void ffInitBluetoothOptions(FFBluetoothOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->showDisconnected = false; - options->percent = (FFPercentConfig) { 50, 20 }; + options->percent = (FFColorRangeConfig) { 50, 20 }; } void ffDestroyBluetoothOptions(FFBluetoothOptions* options) diff --git a/src/modules/bluetooth/option.h b/src/modules/bluetooth/option.h index bab9cce67..7938e77f0 100644 --- a/src/modules/bluetooth/option.h +++ b/src/modules/bluetooth/option.h @@ -11,5 +11,5 @@ typedef struct FFBluetoothOptions FFModuleArgs moduleArgs; bool showDisconnected; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFBluetoothOptions; diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index 49283474f..454a580d6 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -205,7 +205,7 @@ void ffInitBrightnessOptions(FFBrightnessOptions* options) ffOptionInitModuleArg(&options->moduleArgs); options->ddcciSleep = 10; - options->percent = (FFPercentConfig) { 100, 100 }; + options->percent = (FFColorRangeConfig) { 100, 100 }; } void ffDestroyBrightnessOptions(FFBrightnessOptions* options) diff --git a/src/modules/brightness/option.h b/src/modules/brightness/option.h index 89d08a8ed..2623d0aea 100644 --- a/src/modules/brightness/option.h +++ b/src/modules/brightness/option.h @@ -11,5 +11,5 @@ typedef struct FFBrightnessOptions FFModuleArgs moduleArgs; uint32_t ddcciSleep; // ms - FFPercentConfig percent; + FFColorRangeConfig percent; } FFBrightnessOptions; diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index e8787dd33..be852f076 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -190,7 +190,7 @@ void ffInitCPUUsageOptions(FFCPUUsageOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->separate = false; - options->percent = (FFPercentConfig) { 50, 80 }; + options->percent = (FFColorRangeConfig) { 50, 80 }; } void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options) diff --git a/src/modules/cpuusage/option.h b/src/modules/cpuusage/option.h index 380fc9b56..92d298f30 100644 --- a/src/modules/cpuusage/option.h +++ b/src/modules/cpuusage/option.h @@ -11,5 +11,5 @@ typedef struct FFCPUUsageOptions FFModuleArgs moduleArgs; bool separate; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFCPUUsageOptions; diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index a874cc892..ea209dcea 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -484,7 +484,7 @@ void ffInitDiskOptions(FFDiskOptions* options) ffStrbufInit(&options->folders); options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT; options->calcType = FF_DISK_CALC_TYPE_FREE; - options->percent = (FFPercentConfig) { 50, 80 }; + options->percent = (FFColorRangeConfig) { 50, 80 }; } void ffDestroyDiskOptions(FFDiskOptions* options) diff --git a/src/modules/disk/option.h b/src/modules/disk/option.h index a02505d5e..7c2abdcaa 100644 --- a/src/modules/disk/option.h +++ b/src/modules/disk/option.h @@ -30,5 +30,5 @@ typedef struct FFDiskOptions FFstrbuf folders; FFDiskVolumeType showTypes; FFDiskCalcType calcType; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFDiskOptions; diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index 2c5341333..e50fb22d7 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -162,7 +162,7 @@ void ffInitGamepadOptions(FFGamepadOptions* options) ffGenerateGamepadJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); - options->percent = (FFPercentConfig) { 50, 20 }; + options->percent = (FFColorRangeConfig) { 50, 20 }; } void ffDestroyGamepadOptions(FFGamepadOptions* options) diff --git a/src/modules/gamepad/option.h b/src/modules/gamepad/option.h index bc49128e8..b4ecaf94d 100644 --- a/src/modules/gamepad/option.h +++ b/src/modules/gamepad/option.h @@ -9,5 +9,5 @@ typedef struct FFGamepadOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFGamepadOptions; diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index 270872127..c933d7832 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -373,7 +373,7 @@ void ffInitGPUOptions(FFGPUOptions* options) options->forceVulkan = false; options->temp = false; options->hideType = FF_GPU_TYPE_UNKNOWN; - options->percent = (FFPercentConfig) { 50, 80 }; + options->percent = (FFColorRangeConfig) { 50, 80 }; } void ffDestroyGPUOptions(FFGPUOptions* options) diff --git a/src/modules/gpu/option.h b/src/modules/gpu/option.h index e251f834e..438e4d309 100644 --- a/src/modules/gpu/option.h +++ b/src/modules/gpu/option.h @@ -21,5 +21,5 @@ typedef struct FFGPUOptions bool temp; bool driverSpecific; bool forceVulkan; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFGPUOptions; diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index 485b62130..e7bd5c105 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -148,7 +148,7 @@ void ffInitMemoryOptions(FFMemoryOptions* options) ffGenerateMemoryJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); - options->percent = (FFPercentConfig) { 50, 80 }; + options->percent = (FFColorRangeConfig) { 50, 80 }; } void ffDestroyMemoryOptions(FFMemoryOptions* options) diff --git a/src/modules/memory/option.h b/src/modules/memory/option.h index a63153264..4936b252b 100644 --- a/src/modules/memory/option.h +++ b/src/modules/memory/option.h @@ -10,5 +10,5 @@ typedef struct FFMemoryOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFMemoryOptions; diff --git a/src/modules/sound/option.h b/src/modules/sound/option.h index dae67bb49..ad659a557 100644 --- a/src/modules/sound/option.h +++ b/src/modules/sound/option.h @@ -18,5 +18,5 @@ typedef struct FFSoundOptions FFModuleArgs moduleArgs; FFSoundType soundType; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFSoundOptions; diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index 0d0950011..31a9d32ea 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -255,7 +255,7 @@ void ffInitSoundOptions(FFSoundOptions* options) ffOptionInitModuleArg(&options->moduleArgs); options->soundType = FF_SOUND_TYPE_MAIN; - options->percent = (FFPercentConfig) { 80, 90 }; + options->percent = (FFColorRangeConfig) { 80, 90 }; } void ffDestroySoundOptions(FFSoundOptions* options) diff --git a/src/modules/swap/option.h b/src/modules/swap/option.h index 6940a39e1..1c96ce41f 100644 --- a/src/modules/swap/option.h +++ b/src/modules/swap/option.h @@ -10,5 +10,5 @@ typedef struct FFSwapOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFSwapOptions; diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index bf7c7481a..cb4cad7f2 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -157,7 +157,7 @@ void ffInitSwapOptions(FFSwapOptions* options) ffGenerateSwapJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); - options->percent = (FFPercentConfig) { 50, 80 }; + options->percent = (FFColorRangeConfig) { 50, 80 }; } void ffDestroySwapOptions(FFSwapOptions* options) From ba60d9059fb6ab9a69f926ac6627216d62a2fa0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 26 Feb 2024 16:39:41 +0800 Subject: [PATCH 08/14] Temps: support color range customization --- CMakeLists.txt | 1 + doc/json_schema.json | 48 ++++--- src/common/parsing.c | 38 ------ src/common/parsing.h | 1 - src/common/temps.c | 171 ++++++++++++++++++++++++ src/common/temps.h | 8 ++ src/data/help.json | 23 ++++ src/modules/battery/battery.c | 19 +-- src/modules/battery/option.h | 1 + src/modules/cpu/cpu.c | 19 +-- src/modules/cpu/option.h | 1 + src/modules/gpu/gpu.c | 19 +-- src/modules/gpu/option.h | 1 + src/modules/physicaldisk/option.h | 1 + src/modules/physicaldisk/physicaldisk.c | 19 +-- 15 files changed, 268 insertions(+), 102 deletions(-) create mode 100644 src/common/temps.c create mode 100644 src/common/temps.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0706620cb..a4b16f798 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -277,6 +277,7 @@ set(LIBFASTFETCH_SRC src/common/printing.c src/common/properties.c src/common/settings.c + src/common/temps.c src/detection/chassis/chassis.c src/detection/cpu/cpu.c src/detection/cpuusage/cpuusage.c diff --git a/doc/json_schema.json b/doc/json_schema.json index 5b7b89b7e..ff1750196 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/schema", + "$schema": "https://json-schema.org/draft-07/schema", "$defs": { "colors": { "type": "string", @@ -44,6 +44,32 @@ "description": "Value greater than green and less then yellow will be shown in yellow.\nValue greater than yellow will be shown in red" } } + }, + "temperature": { + "description": "Detect and display temperature if supported", + "oneOf": [ + { + "type": "boolean", + "default": false + }, + { + "type": "object", + "properties": { + "green": { + "type": "integer", + "minimum": 0, + "maximum": 100, + "description": "Value less then green will be shown in green" + }, + "yellow": { + "type": "integer", + "minimum": 0, + "maximum": 100, + "description": "Value greater than green and less then yellow will be shown in yellow.\nValue greater than yellow will be shown in red" + } + } + } + ] } }, "type": "object", @@ -272,7 +298,7 @@ "description": "Force display detection to use DRM. Linux only", "oneOf": [ { - "type": "bool", + "type": "boolean", "const": false, "description": "Try `wayland`, then `x11`, then `drm`" }, @@ -282,7 +308,7 @@ "const": "sysfs-only" }, { - "type": "bool", + "type": "boolean", "const": true, "description": "Try `libdrm` first, then `sysfs` if libdrm failed" } @@ -870,9 +896,7 @@ "default": false }, "temp": { - "description": "Detect and display Battery temperature if supported", - "type": "boolean", - "default": false + "$ref": "#/$defs/temperature" }, "percent": { "$ref": "#/$defs/percent" @@ -970,9 +994,7 @@ "const": "cpu" }, "temp": { - "description": "Detect and display CPU temperature if supported", - "type": "boolean", - "default": false + "$ref": "#/$defs/temperature" }, "freqNdigits": { "description": "Set the number of digits to keep after the decimal point when printing CPU frequency", @@ -1317,9 +1339,7 @@ "const": "gpu" }, "temp": { - "description": "Detect and display GPU temperature if supported", - "type": "boolean", - "default": false + "$ref": "#/$defs/temperature" }, "driverSpecific": { "description": "Use driver specific method to detect more detailed GPU information (memory usage, core count, etc)", @@ -1542,9 +1562,7 @@ "type": "string" }, "temp": { - "description": "Detect and display SSD temperature if supported", - "type": "boolean", - "default": false + "$ref": "#/$defs/temperature" }, "key": { "$ref": "#/$defs/key" diff --git a/src/common/parsing.c b/src/common/parsing.c index f4833fd35..b3f07a509 100644 --- a/src/common/parsing.c +++ b/src/common/parsing.c @@ -1,6 +1,5 @@ #include "fastfetch.h" #include "common/parsing.h" -#include "util/textModifier.h" #include #include @@ -97,43 +96,6 @@ void ffParseSize(uint64_t bytes, FFstrbuf* result) } } -void ffParseTemperature(double celsius, FFstrbuf* buffer) -{ - if (celsius != celsius) // ignores NaN - return; - - const FFOptionsDisplay* options = &instance.config.display; - const char* colorGreen = options->temperatureColorGreen.chars; - const char* colorYellow = options->temperatureColorYellow.chars; - const char* colorRed = options->temperatureColorRed.chars; - - if (!options->pipe) - { - if (celsius < 50) - ffStrbufAppendF(buffer, "\e[%sm", colorGreen); - else if (celsius < 80) - ffStrbufAppendF(buffer, "\e[%sm", colorYellow); - else - ffStrbufAppendF(buffer, "\e[%sm", colorRed); - } - - switch (options->temperatureUnit) - { - case FF_TEMPERATURE_UNIT_CELSIUS: - ffStrbufAppendF(buffer, "%.*f°C", options->temperatureNdigits, celsius); - break; - case FF_TEMPERATURE_UNIT_FAHRENHEIT: - ffStrbufAppendF(buffer, "%.*f°F", options->temperatureNdigits, celsius * 1.8 + 32); - break; - case FF_TEMPERATURE_UNIT_KELVIN: - ffStrbufAppendF(buffer, "%.*f K", options->temperatureNdigits, celsius + 273.15); - break; - } - - if (!options->pipe) - ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); -} - void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4) { if(gtk2->length > 0 && gtk3->length > 0 && gtk4->length > 0) diff --git a/src/common/parsing.h b/src/common/parsing.h index 24fd13528..f295c74cc 100644 --- a/src/common/parsing.h +++ b/src/common/parsing.h @@ -26,4 +26,3 @@ void ffVersionToPretty(const FFVersion* version, FFstrbuf* pretty); int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2); void ffParseSize(uint64_t bytes, FFstrbuf* result); -void ffParseTemperature(double celsius, FFstrbuf* buffer); diff --git a/src/common/temps.c b/src/common/temps.c new file mode 100644 index 000000000..b46abad79 --- /dev/null +++ b/src/common/temps.c @@ -0,0 +1,171 @@ +#include "fastfetch.h" +#include "common/temps.h" +#include "util/textModifier.h" +#include "util/stringUtils.h" + +void ffTempsAppendNum(double celsius, FFstrbuf* buffer, FFColorRangeConfig config) +{ + if (celsius != celsius) // ignores NaN + return; + + const FFOptionsDisplay* options = &instance.config.display; + const char* colorGreen = options->temperatureColorGreen.chars; + const char* colorYellow = options->temperatureColorYellow.chars; + const char* colorRed = options->temperatureColorRed.chars; + + uint8_t green = config.green, yellow = config.yellow; + + if (!options->pipe) + { + if(green <= yellow) + { + if (celsius > yellow) + ffStrbufAppendF(buffer, "\e[%sm", colorRed); + else if (celsius > green) + ffStrbufAppendF(buffer, "\e[%sm", colorYellow); + else + ffStrbufAppendF(buffer, "\e[%sm", colorGreen); + } + else + { + if (celsius < yellow) + ffStrbufAppendF(buffer, "\e[%sm", colorRed); + else if (celsius < green) + ffStrbufAppendF(buffer, "\e[%sm", colorYellow); + else + ffStrbufAppendF(buffer, "\e[%sm", colorGreen); + } + } + + switch (options->temperatureUnit) + { + case FF_TEMPERATURE_UNIT_CELSIUS: + ffStrbufAppendF(buffer, "%.*f°C", options->temperatureNdigits, celsius); + break; + case FF_TEMPERATURE_UNIT_FAHRENHEIT: + ffStrbufAppendF(buffer, "%.*f°F", options->temperatureNdigits, celsius * 1.8 + 32); + break; + case FF_TEMPERATURE_UNIT_KELVIN: + ffStrbufAppendF(buffer, "%.*f K", options->temperatureNdigits, celsius + 273.15); + break; + } + + if (!options->pipe) + ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); +} + +bool ffTempsParseCommandOptions(const char* key, const char* subkey, const char* value, bool* useTemp, FFColorRangeConfig* config) +{ + if (!ffStrStartsWithIgnCase(subkey, "temp")) + return false; + + if (subkey[strlen("temp")] == '\0') + { + *useTemp = ffOptionParseBoolean(value); + return true; + } + + if (subkey[strlen("temp")] != '-') + return false; + + subkey += strlen("temp-"); + + if (ffStrEqualsIgnCase(subkey, "green")) + { + uint32_t num = ffOptionParseUInt32(key, value); + if (num > 100) + { + fprintf(stderr, "Error: usage: %s must be between 0 and 100\n", key); + exit(480); + } + config->green = (uint8_t) num; + return true; + } + + if (ffStrEqualsIgnCase(subkey, "yellow")) + { + uint32_t num = ffOptionParseUInt32(key, value); + if (num > 100) + { + fprintf(stderr, "Error: usage: %s must be between 0 and 100\n", key); + exit(480); + } + config->yellow = (uint8_t) num; + return true; + } + + return false; +} + +bool ffTempsParseJsonObject(const char* key, yyjson_val* value, bool* useTemp, FFColorRangeConfig* config) +{ + if (!ffStrEqualsIgnCase(key, "temp")) + return false; + + if (yyjson_is_bool(value)) + { + *useTemp = yyjson_get_bool(value); + return true; + } + + if (yyjson_is_null(value)) + { + *useTemp = false; + return true; + } + + if (!yyjson_is_obj(value)) + { + fprintf(stderr, "Error: usage: %s must be an object or a boolean\n", key); + exit(480); + } + + *useTemp = true; + + yyjson_val* greenVal = yyjson_obj_get(value, "green"); + if (greenVal) + { + int num = yyjson_get_int(greenVal); + if (num < 0 || num > 100) + { + fputs("Error: usage: temp.green must be between 0 and 100\n", stderr); + exit(480); + } + config->green = (uint8_t) num; + } + + yyjson_val* yellowVal = yyjson_obj_get(value, "yellow"); + if (yellowVal) + { + int num = yyjson_get_int(yellowVal); + if (num < 0 || num > 100) + { + fputs("Error: usage: temp.yellow must be between 0 and 100\n", stderr); + exit(480); + } + config->yellow = (uint8_t) num; + } + + return true; +} + +void ffTempsGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FF_MAYBE_UNUSED bool defaultTemp, FFColorRangeConfig defaultConfig, bool temp, FFColorRangeConfig config) +{ + assert(defaultTemp == false); // assume defaultTemp is always false + + if (!temp) + return; + + if (config.green != defaultConfig.green || config.yellow != defaultConfig.yellow) + { + yyjson_mut_val* temp = yyjson_mut_obj_add_obj(doc, module, "temp"); + if (config.green != defaultConfig.green) + yyjson_mut_obj_add_uint(doc, temp, "green", config.green); + if (config.yellow != defaultConfig.yellow) + yyjson_mut_obj_add_uint(doc, temp, "yellow", config.yellow); + } + else + { + yyjson_mut_obj_add_bool(doc, module, "temp", true); + } +} diff --git a/src/common/temps.h b/src/common/temps.h new file mode 100644 index 000000000..bbbc74766 --- /dev/null +++ b/src/common/temps.h @@ -0,0 +1,8 @@ +#pragma once + +#include "common/parsing.h" + +void ffTempsAppendNum(double celsius, FFstrbuf* buffer, FFColorRangeConfig config); +bool ffTempsParseCommandOptions(const char* key, const char* subkey, const char* value, bool* useTemp, FFColorRangeConfig* config); +bool ffTempsParseJsonObject(const char* key, yyjson_val* value, bool* useTemp, FFColorRangeConfig* config); +void ffTempsGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FF_MAYBE_UNUSED bool defaultTemp, FFColorRangeConfig defaultConfig, bool temp, FFColorRangeConfig config); diff --git a/src/data/help.json b/src/data/help.json index 5199b1b42..9fa6dd08a 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -1532,6 +1532,29 @@ "type": "num" }, "pseudo": true + }, + { + "long": "-temp-green", + "desc": [ + "Threshold of temperature colors", + "Value less then temp-green will be shown in green" + ], + "arg": { + "type": "num" + }, + "pseudo": true + }, + { + "long": "-temp-yellow", + "desc": [ + "Threshold of temperature colors", + "Value greater than temp-green and less then yellow will be shown in yellow", + "Value greater than temp-yellow will be shown in red" + ], + "arg": { + "type": "num" + }, + "pseudo": true } ] } diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index ccfed5d09..39f43b1d2 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -2,6 +2,7 @@ #include "common/jsonconfig.h" #include "common/percent.h" #include "common/parsing.h" +#include "common/temps.h" #include "detection/battery/battery.h" #include "modules/battery/battery.h" #include "util/stringUtils.h" @@ -49,7 +50,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin if(str.length > 0) ffStrbufAppendS(&str, " - "); - ffParseTemperature(result->temperature, &str); + ffTempsAppendNum(result->temperature, &str, options->tempConfig); } ffStrbufPutTo(&str, stdout); @@ -59,7 +60,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin FF_STRBUF_AUTO_DESTROY capacityStr = ffStrbufCreate(); ffPercentAppendNum(&capacityStr, result->capacity, options->percent, false); FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); - ffParseTemperature(result->temperature, &tempStr); + ffTempsAppendNum(result->temperature, &tempStr, options->tempConfig); ffPrintFormat(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName}, @@ -110,11 +111,8 @@ bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, co if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; - if (ffStrEqualsIgnCase(subKey, "temp")) - { - options->temp = ffOptionParseBoolean(value); + if (ffTempsParseCommandOptions(key, subKey, value, &options->temp, &options->tempConfig)) return true; - } #ifdef _WIN32 if (ffStrEqualsIgnCase(subKey, "use-setup-api")) @@ -151,11 +149,8 @@ void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module) } #endif - if (ffStrEqualsIgnCase(key, "temp")) - { - options->temp = yyjson_get_bool(val); + if (ffTempsParseJsonObject(key, val, &options->temp, &options->tempConfig)) continue; - } if (ffPercentParseJsonObject(key, val, &options->percent)) continue; @@ -176,8 +171,7 @@ void ffGenerateBatteryJsonConfig(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_obj_add_bool(doc, module, "useSetupApi", options->useSetupApi); #endif - if (options->temp != defaultOptions.temp) - yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); + ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig); ffPercentGenerateJsonConfig(doc, module, defaultOptions.percent, options->percent); } @@ -250,6 +244,7 @@ void ffInitBatteryOptions(FFBatteryOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; + options->tempConfig = (FFColorRangeConfig) { 60, 80 }; options->percent = (FFColorRangeConfig) { 50, 20 }; #ifdef _WIN32 diff --git a/src/modules/battery/option.h b/src/modules/battery/option.h index 4fa9e8f5c..ecaa45ccc 100644 --- a/src/modules/battery/option.h +++ b/src/modules/battery/option.h @@ -11,6 +11,7 @@ typedef struct FFBatteryOptions FFModuleArgs moduleArgs; bool temp; + FFColorRangeConfig tempConfig; FFColorRangeConfig percent; #ifdef _WIN32 diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index c2716b528..c7ee463e8 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -1,6 +1,7 @@ #include "common/printing.h" #include "common/jsonconfig.h" #include "common/parsing.h" +#include "common/temps.h" #include "detection/cpu/cpu.h" #include "modules/cpu/cpu.h" #include "util/stringUtils.h" @@ -53,7 +54,7 @@ void ffPrintCPU(FFCPUOptions* options) if(cpu.temperature == cpu.temperature) //FF_CPU_TEMP_UNSET { ffStrbufAppendS(&str, " - "); - ffParseTemperature(cpu.temperature, &str); + ffTempsAppendNum(cpu.temperature, &str, options->tempConfig); } ffStrbufPutTo(&str, stdout); @@ -61,7 +62,7 @@ void ffPrintCPU(FFCPUOptions* options) else { FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); - ffParseTemperature(cpu.temperature, &tempStr); + ffTempsAppendNum(cpu.temperature, &tempStr, options->tempConfig); ffPrintFormat(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &cpu.name}, {FF_FORMAT_ARG_TYPE_STRBUF, &cpu.vendor}, @@ -86,11 +87,8 @@ bool ffParseCPUCPUOptions(FFCPUOptions* options, const char* key, const char* va if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; - if (ffStrEqualsIgnCase(subKey, "temp")) - { - options->temp = ffOptionParseBoolean(value); + if (ffTempsParseCommandOptions(key, subKey, value, &options->temp, &options->tempConfig)) return true; - } if (ffStrEqualsIgnCase(subKey, "freq-ndigits")) { @@ -114,11 +112,8 @@ void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; - if (ffStrEqualsIgnCase(key, "temp")) - { - options->temp = yyjson_get_bool(val); + if (ffTempsParseJsonObject(key, val, &options->temp, &options->tempConfig)) continue; - } if (ffStrEqualsIgnCase(key, "freqNdigits")) { @@ -137,8 +132,7 @@ void ffGenerateCPUJsonConfig(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_ ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); - if (defaultOptions.temp != options->temp) - yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); + ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig); if (defaultOptions.freqNdigits != options->freqNdigits) yyjson_mut_obj_add_uint(doc, module, "freqNdigits", options->freqNdigits); @@ -214,6 +208,7 @@ void ffInitCPUOptions(FFCPUOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; + options->tempConfig = (FFColorRangeConfig) { 60, 80 }; options->freqNdigits = 2; } diff --git a/src/modules/cpu/option.h b/src/modules/cpu/option.h index ae5699939..1fee8a3d6 100644 --- a/src/modules/cpu/option.h +++ b/src/modules/cpu/option.h @@ -10,5 +10,6 @@ typedef struct FFCPUOptions FFModuleArgs moduleArgs; bool temp; + FFColorRangeConfig tempConfig; uint8_t freqNdigits; } FFCPUOptions; diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index c933d7832..7c3d5b55f 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -2,6 +2,7 @@ #include "common/parsing.h" #include "common/printing.h" #include "common/jsonconfig.h" +#include "common/temps.h" #include "detection/host/host.h" #include "detection/gpu/gpu.h" #include "modules/gpu/gpu.h" @@ -44,7 +45,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET { ffStrbufAppendS(&output, " - "); - ffParseTemperature(gpu->temperature, &output); + ffTempsAppendNum(gpu->temperature, &output, options->tempConfig); } if(gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET && gpu->dedicated.total != 0) @@ -73,7 +74,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu else { FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); - ffParseTemperature(gpu->temperature, &tempStr); + ffTempsAppendNum(gpu->temperature, &tempStr, options->tempConfig); ffPrintFormat(FF_GPU_MODULE_NAME, index, &options->moduleArgs, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor}, {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name}, @@ -148,11 +149,8 @@ bool ffParseGPUCommandOptions(FFGPUOptions* options, const char* key, const char return true; } - if (ffStrEqualsIgnCase(subKey, "temp")) - { - options->temp = ffOptionParseBoolean(value); + if (ffTempsParseCommandOptions(key, subKey, value, &options->temp, &options->tempConfig)) return true; - } if (ffStrEqualsIgnCase(subKey, "hide-type")) { @@ -183,11 +181,8 @@ void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; - if (ffStrEqualsIgnCase(key, "temp")) - { - options->temp = yyjson_get_bool(val); + if (ffTempsParseJsonObject(key, val, &options->temp, &options->tempConfig)) continue; - } if (ffStrEqualsIgnCase(key, "driverSpecific")) { @@ -237,8 +232,7 @@ void ffGenerateGPUJsonConfig(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_ if (options->forceVulkan != defaultOptions.forceVulkan) yyjson_mut_obj_add_bool(doc, module, "forceVulkan", options->forceVulkan); - if (options->temp != defaultOptions.temp) - yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); + ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig); if (options->hideType != defaultOptions.hideType) { @@ -373,6 +367,7 @@ void ffInitGPUOptions(FFGPUOptions* options) options->forceVulkan = false; options->temp = false; options->hideType = FF_GPU_TYPE_UNKNOWN; + options->tempConfig = (FFColorRangeConfig) { 60, 80 }; options->percent = (FFColorRangeConfig) { 50, 80 }; } diff --git a/src/modules/gpu/option.h b/src/modules/gpu/option.h index 438e4d309..a68b8ad3a 100644 --- a/src/modules/gpu/option.h +++ b/src/modules/gpu/option.h @@ -21,5 +21,6 @@ typedef struct FFGPUOptions bool temp; bool driverSpecific; bool forceVulkan; + FFColorRangeConfig tempConfig; FFColorRangeConfig percent; } FFGPUOptions; diff --git a/src/modules/physicaldisk/option.h b/src/modules/physicaldisk/option.h index f57770d67..fbd2dc685 100644 --- a/src/modules/physicaldisk/option.h +++ b/src/modules/physicaldisk/option.h @@ -11,4 +11,5 @@ typedef struct FFPhysicalDiskOptions FFstrbuf namePrefix; bool temp; + FFColorRangeConfig tempConfig; } FFPhysicalDiskOptions; diff --git a/src/modules/physicaldisk/physicaldisk.c b/src/modules/physicaldisk/physicaldisk.c index 01f5033c5..7bb9187cb 100644 --- a/src/modules/physicaldisk/physicaldisk.c +++ b/src/modules/physicaldisk/physicaldisk.c @@ -1,6 +1,7 @@ #include "common/printing.h" #include "common/jsonconfig.h" #include "common/parsing.h" +#include "common/temps.h" #include "detection/physicaldisk/physicaldisk.h" #include "modules/physicaldisk/physicaldisk.h" #include "util/stringUtils.h" @@ -96,14 +97,14 @@ void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options) if(buffer.length > 0) ffStrbufAppendS(&buffer, " - "); - ffParseTemperature(dev->temperature, &buffer); + ffTempsAppendNum(dev->temperature, &buffer, options->tempConfig); } ffStrbufPutTo(&buffer, stdout); } else { FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); - ffParseTemperature(dev->temperature, &tempStr); + ffTempsAppendNum(dev->temperature, &tempStr, options->tempConfig); if (dev->type & FF_PHYSICALDISK_TYPE_READWRITE) readOnlyType = "Read-write"; ffParseSize(dev->size, &buffer); @@ -145,11 +146,8 @@ bool ffParsePhysicalDiskCommandOptions(FFPhysicalDiskOptions* options, const cha return true; } - if (ffStrEqualsIgnCase(subKey, "temp")) - { - options->temp = ffOptionParseBoolean(value); + if (ffTempsParseCommandOptions(key, subKey, value, &options->temp, &options->tempConfig)) return true; - } return false; } @@ -173,11 +171,8 @@ void ffParsePhysicalDiskJsonObject(FFPhysicalDiskOptions* options, yyjson_val* m continue; } - if (ffStrEqualsIgnCase(key, "temp")) - { - options->temp = yyjson_get_bool(val); + if (ffTempsParseJsonObject(key, val, &options->temp, &options->tempConfig)) continue; - } ffPrintError(FF_PHYSICALDISK_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } @@ -193,8 +188,7 @@ void ffGeneratePhysicalDiskJsonConfig(FFPhysicalDiskOptions* options, yyjson_mut if (!ffStrbufEqual(&options->namePrefix, &defaultOptions.namePrefix)) yyjson_mut_obj_add_strbuf(doc, module, "namePrefix", &options->namePrefix); - if (options->temp != defaultOptions.temp) - yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); + ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig); } void ffGeneratePhysicalDiskJsonResult(FFPhysicalDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) @@ -286,6 +280,7 @@ void ffInitPhysicalDiskOptions(FFPhysicalDiskOptions* options) ffStrbufInit(&options->namePrefix); options->temp = false; + options->tempConfig = (FFColorRangeConfig) { 40, 60 }; } void ffDestroyPhysicalDiskOptions(FFPhysicalDiskOptions* options) From 5147651bcbca9efd8198a1a802f1024d10e8fffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 27 Feb 2024 13:11:39 +0800 Subject: [PATCH 09/14] Temps: rename `display.temperature` to `display.temp` --- CHANGELOG.md | 6 +++--- doc/json_schema.json | 8 ++++---- src/common/temps.c | 12 +++++------ src/data/help.json | 10 +++++----- src/options/display.c | 46 +++++++++++++++++++++---------------------- src/options/display.h | 8 ++++---- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80dc9de96..7657821e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,15 @@ # 2.8.6 Changes: -* Due to newly introduced configs, JSONC option `{ "temperatureUnit": "C" }` has been changed to `{ "temperature": { "unit": "C" } }` +* Due to newly introduced configs, JSONC option `{ "temperatureUnit": "C" }` has been changed to `{ "temp": { "unit": "C" } }` Bugfixes: * Fix incorrect GPU name detection for Intel iGPU on Linux (#736, GPU, Linux) Features: * Support additional temperature formatting options (#737) - * `{ "temperature": { "ndigits": 1 } }` - * `{ "temperature": { "color": { "green": "green", "yellow": "yellow", "red": "red" } } }` + * `{ "temp": { "ndigits": 1 } }` + * `{ "temp": { "color": { "green": "green", "yellow": "yellow", "red": "red" } } }` # 2.8.5 diff --git a/doc/json_schema.json b/doc/json_schema.json index ff1750196..73c8adce1 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -59,13 +59,13 @@ "type": "integer", "minimum": 0, "maximum": 100, - "description": "Value less then green will be shown in green" + "description": "Value (in celsius) less then green will be shown in green" }, "yellow": { "type": "integer", "minimum": 0, "maximum": 100, - "description": "Value greater than green and less then yellow will be shown in yellow.\nValue greater than yellow will be shown in red" + "description": "Value (in celsius) greater than green and less then yellow will be shown in yellow.\nValue greater than yellow will be shown in red" } } } @@ -433,9 +433,9 @@ } } }, - "temperature": { + "temp": { "type": "object", - "description": "Set how a temperature value should be displayed", + "description": "Set how temperature values should be displayed", "properties": { "unit": { "type": "string", diff --git a/src/common/temps.c b/src/common/temps.c index b46abad79..d72f46f0e 100644 --- a/src/common/temps.c +++ b/src/common/temps.c @@ -9,9 +9,9 @@ void ffTempsAppendNum(double celsius, FFstrbuf* buffer, FFColorRangeConfig confi return; const FFOptionsDisplay* options = &instance.config.display; - const char* colorGreen = options->temperatureColorGreen.chars; - const char* colorYellow = options->temperatureColorYellow.chars; - const char* colorRed = options->temperatureColorRed.chars; + const char* colorGreen = options->tempColorGreen.chars; + const char* colorYellow = options->tempColorYellow.chars; + const char* colorRed = options->tempColorRed.chars; uint8_t green = config.green, yellow = config.yellow; @@ -40,13 +40,13 @@ void ffTempsAppendNum(double celsius, FFstrbuf* buffer, FFColorRangeConfig confi switch (options->temperatureUnit) { case FF_TEMPERATURE_UNIT_CELSIUS: - ffStrbufAppendF(buffer, "%.*f°C", options->temperatureNdigits, celsius); + ffStrbufAppendF(buffer, "%.*f°C", options->tempNdigits, celsius); break; case FF_TEMPERATURE_UNIT_FAHRENHEIT: - ffStrbufAppendF(buffer, "%.*f°F", options->temperatureNdigits, celsius * 1.8 + 32); + ffStrbufAppendF(buffer, "%.*f°F", options->tempNdigits, celsius * 1.8 + 32); break; case FF_TEMPERATURE_UNIT_KELVIN: - ffStrbufAppendF(buffer, "%.*f K", options->temperatureNdigits, celsius + 273.15); + ffStrbufAppendF(buffer, "%.*f K", options->tempNdigits, celsius + 273.15); break; } diff --git a/src/data/help.json b/src/data/help.json index 9fa6dd08a..621d2d71e 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -656,7 +656,7 @@ } }, { - "long": "temperature-unit", + "long": "temp-unit", "desc": "Set the unit of the temperature", "arg": { "type": "enum", @@ -669,7 +669,7 @@ } }, { - "long": "temperature-ndigits", + "long": "temp-ndigits", "desc": "Set the number of digits to keep after the decimal point when printing temperature", "arg": { "type": "num", @@ -677,7 +677,7 @@ } }, { - "long": "temperature-color-green", + "long": "temp-color-green", "desc": "Set color used in green state of temperature values", "remark": "See `-h color` for the list of available colors", "arg": { @@ -686,7 +686,7 @@ } }, { - "long": "temperature-color-yellow", + "long": "temp-color-yellow", "desc": "Set color used in yellow state of temperature values", "remark": "See `-h color` for the list of available colors", "arg": { @@ -695,7 +695,7 @@ } }, { - "long": "temperature-color-red", + "long": "temp-color-red", "desc": "Set color used in red state of temperature values", "remark": "See `-h color` for the list of available colors", "arg": { diff --git a/src/options/display.c b/src/options/display.c index 7adccaa8c..528c46e80 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -94,10 +94,10 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va yyjson_val* ndigits = yyjson_obj_get(val, "ndigits"); if (ndigits) options->percentNdigits = (uint8_t) yyjson_get_uint(ndigits); } - else if (ffStrEqualsIgnCase(key, "temperature")) + else if (ffStrEqualsIgnCase(key, "temp")) { if (!yyjson_is_obj(val)) - return "display.temperature must be an object"; + return "display.temp must be an object"; yyjson_val* unit = yyjson_obj_get(val, "unit"); if (unit) @@ -117,7 +117,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va } yyjson_val* ndigits = yyjson_obj_get(val, "ndigits"); - if (ndigits) options->temperatureNdigits = (uint8_t) yyjson_get_uint(ndigits); + if (ndigits) options->tempNdigits = (uint8_t) yyjson_get_uint(ndigits); yyjson_val* color = yyjson_obj_get(val, "color"); if (color) @@ -126,13 +126,13 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va return "display.temperature.color must be an object"; yyjson_val* green = yyjson_obj_get(color, "green"); - if (green) ffOptionParseColor(yyjson_get_str(green), &options->temperatureColorGreen); + if (green) ffOptionParseColor(yyjson_get_str(green), &options->tempColorGreen); yyjson_val* yellow = yyjson_obj_get(color, "yellow"); - if (yellow) ffOptionParseColor(yyjson_get_str(yellow), &options->temperatureColorYellow); + if (yellow) ffOptionParseColor(yyjson_get_str(yellow), &options->tempColorYellow); yyjson_val* red = yyjson_obj_get(color, "red"); - if (red) ffOptionParseColor(yyjson_get_str(red), &options->temperatureColorRed); + if (red) ffOptionParseColor(yyjson_get_str(red), &options->tempColorRed); } } else if (ffStrEqualsIgnCase(key, "percent")) @@ -295,13 +295,13 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key }); } else if (ffStrEqualsIgnCase(subkey, "ndigits")) - options->temperatureNdigits = (uint8_t) ffOptionParseUInt32(key, value); + options->tempNdigits = (uint8_t) ffOptionParseUInt32(key, value); else if(ffStrEqualsIgnCase(subkey, "color-green")) - ffOptionParseColor(value, &options->temperatureColorGreen); + ffOptionParseColor(value, &options->tempColorGreen); else if(ffStrEqualsIgnCase(subkey, "color-yellow")) - ffOptionParseColor(value, &options->temperatureColorYellow); + ffOptionParseColor(value, &options->tempColorYellow); else if(ffStrEqualsIgnCase(subkey, "color-red")) - ffOptionParseColor(value, &options->temperatureColorRed); + ffOptionParseColor(value, &options->tempColorRed); else return false; } @@ -368,10 +368,10 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options) options->keyWidth = 0; options->temperatureUnit = FF_TEMPERATURE_UNIT_CELSIUS; - options->temperatureNdigits = 1; - ffStrbufInitStatic(&options->temperatureColorGreen, FF_COLOR_FG_GREEN); - ffStrbufInitStatic(&options->temperatureColorYellow, FF_COLOR_FG_LIGHT_YELLOW); - ffStrbufInitStatic(&options->temperatureColorRed, FF_COLOR_FG_LIGHT_RED); + options->tempNdigits = 1; + ffStrbufInitStatic(&options->tempColorGreen, FF_COLOR_FG_GREEN); + ffStrbufInitStatic(&options->tempColorYellow, FF_COLOR_FG_LIGHT_YELLOW); + ffStrbufInitStatic(&options->tempColorRed, FF_COLOR_FG_LIGHT_RED); ffStrbufInitStatic(&options->barCharElapsed, "■"); ffStrbufInitStatic(&options->barCharTotal, "-"); @@ -492,21 +492,21 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do break; } } - if (options->temperatureNdigits != defaultOptions.temperatureNdigits) - yyjson_mut_obj_add_uint(doc, temperature, "ndigits", options->temperatureNdigits); + if (options->tempNdigits != defaultOptions.tempNdigits) + yyjson_mut_obj_add_uint(doc, temperature, "ndigits", options->tempNdigits); { yyjson_mut_val* color = yyjson_mut_obj(doc); - if (!ffStrbufEqual(&options->temperatureColorGreen, &defaultOptions.temperatureColorGreen)) - yyjson_mut_obj_add_strbuf(doc, color, "green", &options->temperatureColorGreen); - if (!ffStrbufEqual(&options->temperatureColorYellow, &defaultOptions.temperatureColorYellow)) - yyjson_mut_obj_add_strbuf(doc, color, "yellow", &options->temperatureColorYellow); - if (!ffStrbufEqual(&options->temperatureColorRed, &defaultOptions.temperatureColorRed)) - yyjson_mut_obj_add_strbuf(doc, color, "red", &options->temperatureColorRed); + if (!ffStrbufEqual(&options->tempColorGreen, &defaultOptions.tempColorGreen)) + yyjson_mut_obj_add_strbuf(doc, color, "green", &options->tempColorGreen); + if (!ffStrbufEqual(&options->tempColorYellow, &defaultOptions.tempColorYellow)) + yyjson_mut_obj_add_strbuf(doc, color, "yellow", &options->tempColorYellow); + if (!ffStrbufEqual(&options->tempColorRed, &defaultOptions.tempColorRed)) + yyjson_mut_obj_add_strbuf(doc, color, "red", &options->tempColorRed); if (yyjson_mut_obj_size(color) > 0) yyjson_mut_obj_add_val(doc, temperature, "color", color); } if (yyjson_mut_obj_size(temperature) > 0) - yyjson_mut_obj_add_val(doc, obj, "temperature", temperature); + yyjson_mut_obj_add_val(doc, obj, "temp", temperature); } { diff --git a/src/options/display.h b/src/options/display.h index 2d800150e..ef02336cb 100644 --- a/src/options/display.h +++ b/src/options/display.h @@ -35,10 +35,10 @@ typedef struct FFOptionsDisplay uint8_t sizeNdigits; uint8_t sizeMaxPrefix; FFTemperatureUnit temperatureUnit; - uint8_t temperatureNdigits; - FFstrbuf temperatureColorGreen; - FFstrbuf temperatureColorYellow; - FFstrbuf temperatureColorRed; + uint8_t tempNdigits; + FFstrbuf tempColorGreen; + FFstrbuf tempColorYellow; + FFstrbuf tempColorRed; FFstrbuf barCharElapsed; FFstrbuf barCharTotal; uint8_t barWidth; From 111f7111b28162ee056e81aeb03377e689214a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 27 Feb 2024 15:20:02 +0800 Subject: [PATCH 10/14] GPU (Linux): Support specifying custom `pci.ids` path for Linux --- CHANGELOG.md | 1 + CMakeLists.txt | 9 +++++++++ src/detection/gpu/gpu_linux.c | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7657821e3..6f24f1410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Features: * Support additional temperature formatting options (#737) * `{ "temp": { "ndigits": 1 } }` * `{ "temp": { "color": { "green": "green", "yellow": "yellow", "red": "red" } } }` +* Support specifying custom `pci.ids` path for Linux (GPU, Linux) # 2.8.5 diff --git a/CMakeLists.txt b/CMakeLists.txt index a4b16f798..7f264a168 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,10 @@ option(ENABLE_PROPRIETARY_GPU_DRIVER_API "Enable proprietary GPU driver API (NVM option(BUILD_TESTS "Build tests" OFF) # Also create test executables option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds +if (LINUX) + set(CUSTOM_PCI_IDS_PATH "" CACHE STRING "Custom path to file pci.ids, defaults to `/usr/share/hwdata/pci.ids`") +endif() + #################### # Compiler options # #################### @@ -763,6 +767,11 @@ if(HAVE_WCWIDTH) target_compile_definitions(libfastfetch PRIVATE FF_HAVE_WCWIDTH) endif() +if(NOT "${CUSTOM_PCI_IDS_PATH}" STREQUAL "") + message(STATUS "Custom file path of pci.ids: ${CUSTOM_PCI_IDS_PATH}") + target_compile_definitions(libfastfetch PRIVATE FF_CUSTOM_PCI_IDS_PATH=${CUSTOM_PCI_IDS_PATH}) +endif() + function(ff_lib_enable VARNAME PKGCONFIG_NAMES CMAKE_NAME) if(NOT ENABLE_${VARNAME}) return() diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 1c5b2f3c5..d1fb13e4f 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -9,6 +9,9 @@ #include "detection/gpu/gpu_driver_specific.h" #endif +#define FF_STR_INDIR(x) #x +#define FF_STR(x) FF_STR_INDIR(x) + #include FF_MAYBE_UNUSED static void pciDetectTemp(FFGPUResult* gpu, uint32_t deviceClass) @@ -53,6 +56,11 @@ static void pciDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer static bool loadPciIds(FFstrbuf* pciids) { + #ifdef FF_CUSTOM_PCI_IDS_PATH + ffReadFileBuffer(FF_STR(FF_CUSTOM_PCI_IDS_PATH), pciids); + if (pciids->length > 0) return true; + #endif + ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/share/hwdata/pci.ids", pciids); if (pciids->length > 0) return true; From 79b7b15b46c7e696abaa489df756eab158dd9e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 27 Feb 2024 16:19:36 +0800 Subject: [PATCH 11/14] Terminal: detect tty name Fix #738 --- src/detection/terminalshell/terminalshell.h | 1 + src/detection/terminalshell/terminalshell_linux.c | 1 + src/detection/terminalshell/terminalshell_windows.c | 1 + src/modules/terminal/terminal.c | 5 ++++- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/detection/terminalshell/terminalshell.h b/src/detection/terminalshell/terminalshell.h index 235a29f60..cebc4647d 100644 --- a/src/detection/terminalshell/terminalshell.h +++ b/src/detection/terminalshell/terminalshell.h @@ -23,6 +23,7 @@ typedef struct FFTerminalResult const char* exeName; //pointer to a char in exe FFstrbuf exePath; //Full real path to executable file FFstrbuf version; + FFstrbuf tty; uint32_t pid; uint32_t ppid; } FFTerminalResult; diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 2b6b350ed..286cdc662 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -571,6 +571,7 @@ const FFTerminalResult* ffDetectTerminal() result.exeName = result.exe.chars; ffStrbufInit(&result.exePath); ffStrbufInit(&result.version); + ffStrbufInitS(&result.tty, ttyname(STDOUT_FILENO)); result.pid = 0; result.ppid = 0; diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index 69e0ca944..ce165ea67 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -369,6 +369,7 @@ const FFShellResult* ffDetectShell(void) ffStrbufInit(&result.exePath); ffStrbufInit(&result.prettyName); ffStrbufInit(&result.version); + ffStrbufInit(&result.tty); result.pid = 0; result.ppid = 0; result.tty = -1; diff --git a/src/modules/terminal/terminal.c b/src/modules/terminal/terminal.c index c5295d5bb..d73d0c1d3 100644 --- a/src/modules/terminal/terminal.c +++ b/src/modules/terminal/terminal.c @@ -6,7 +6,7 @@ #include -#define FF_TERMINAL_NUM_FORMAT_ARGS 7 +#define FF_TERMINAL_NUM_FORMAT_ARGS 8 void ffPrintTerminal(FFTerminalOptions* options) { @@ -37,6 +37,7 @@ void ffPrintTerminal(FFTerminalOptions* options) {FF_FORMAT_ARG_TYPE_STRBUF, &result->prettyName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->version}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->exePath}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->tty}, }); } } @@ -95,6 +96,7 @@ void ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yy yyjson_mut_obj_add_uint(doc, obj, "ppid", result->ppid); yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->prettyName); yyjson_mut_obj_add_strbuf(doc, obj, "version", &result->version); + yyjson_mut_obj_add_strbuf(doc, obj, "tty", &result->tty); } void ffPrintTerminalHelpFormat(void) @@ -107,6 +109,7 @@ void ffPrintTerminalHelpFormat(void) "Terminal pretty name", "Terminal version", "Terminal full exe path", + "Terminal tty / pts used", }); } From a3c3f3829d64a8b50ca4c502c398ca5a439b10e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 27 Feb 2024 16:35:47 +0800 Subject: [PATCH 12/14] Shell (Linux): always detect tty id --- src/detection/terminalshell/terminalshell_linux.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 286cdc662..8af68f598 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -148,12 +148,7 @@ static const char* getProcessNameAndPpid(pid_t pid, char* name, pid_t* ppid, int return "sscanf(stat) failed"; if (tty) - { - if ((tty_ >> 8) == 0x88) - *tty = tty_ & 0xFF; - else - *tty = -1; - } + *tty = tty_ & 0xFF; #elif defined(__APPLE__) From ba45073e04deba29e23e36c2a2b29a6c39b2b536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 27 Feb 2024 19:20:13 +0800 Subject: [PATCH 13/14] CI: fix windows build --- src/detection/terminalshell/terminalshell_windows.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index ce165ea67..cce353c29 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -369,7 +369,6 @@ const FFShellResult* ffDetectShell(void) ffStrbufInit(&result.exePath); ffStrbufInit(&result.prettyName); ffStrbufInit(&result.version); - ffStrbufInit(&result.tty); result.pid = 0; result.ppid = 0; result.tty = -1; @@ -407,6 +406,7 @@ const FFTerminalResult* ffDetectTerminal(void) ffStrbufInit(&result.exePath); ffStrbufInit(&result.prettyName); ffStrbufInit(&result.version); + ffStrbufInit(&result.tty); result.pid = 0; result.ppid = 0; From cc40ef42f001d76b707329cf5e42d7c622f5ef04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 27 Feb 2024 21:28:01 +0800 Subject: [PATCH 14/14] Release: v2.8.6 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f264a168..a36240276 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url project(fastfetch - VERSION 2.8.5 + VERSION 2.8.6 LANGUAGES C DESCRIPTION "Fast neofetch-like system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"