mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 17:41:41 +01:00
CPU: move option freqNdigits into display section
This commit is contained in:
+14
-7
@@ -574,6 +574,20 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"freq": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"description": "Set how frequency values should be displayed",
|
||||
"properties": {
|
||||
"ndigits": {
|
||||
"type": "integer",
|
||||
"description": "Set the number of digits to keep after the decimal point when formatting frequency values\nA possitive value will show the frequency in GHz of decimal\n-1 will show the frequency in MHz",
|
||||
"minimum": -1,
|
||||
"maximum": 9,
|
||||
"default": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
"noBuffer": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to disable the stdout application buffer",
|
||||
@@ -1103,13 +1117,6 @@
|
||||
"temp": {
|
||||
"$ref": "#/$defs/temperature"
|
||||
},
|
||||
"freqNdigits": {
|
||||
"description": "Set the number of digits to keep after the decimal point when printing frequency in GHz, or MHz if set to -1",
|
||||
"type": "integer",
|
||||
"minimum": -1,
|
||||
"maximum": 9,
|
||||
"default": 2
|
||||
},
|
||||
"showPeCoreCount": {
|
||||
"description": "Detect and display CPU frequency of different core types (eg. Pcore and Ecore) if supported",
|
||||
"type": "boolean",
|
||||
|
||||
@@ -96,13 +96,15 @@ void ffParseSize(uint64_t bytes, FFstrbuf* result)
|
||||
}
|
||||
}
|
||||
|
||||
bool ffParseFrequency(uint32_t mhz, FFstrbuf* result, int8_t freqNdigits)
|
||||
bool ffParseFrequency(uint32_t mhz, FFstrbuf* result)
|
||||
{
|
||||
if (mhz == 0)
|
||||
return false;
|
||||
|
||||
if (freqNdigits >= 0)
|
||||
ffStrbufAppendF(result, "%.*f GHz", freqNdigits, mhz / 1000.);
|
||||
int8_t ndigits = instance.config.display.freqNdigits;
|
||||
|
||||
if (ndigits >= 0)
|
||||
ffStrbufAppendF(result, "%.*f GHz", ndigits, mhz / 1000.);
|
||||
else
|
||||
ffStrbufAppendF(result, "%u MHz", (unsigned) mhz);
|
||||
return true;
|
||||
|
||||
@@ -26,4 +26,4 @@ void ffVersionToPretty(const FFVersion* version, FFstrbuf* pretty);
|
||||
int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2);
|
||||
|
||||
void ffParseSize(uint64_t bytes, FFstrbuf* result);
|
||||
bool ffParseFrequency(uint32_t mhz, FFstrbuf* result, int8_t freqNdigits);
|
||||
bool ffParseFrequency(uint32_t mhz, FFstrbuf* result);
|
||||
|
||||
+8
-8
@@ -688,6 +688,14 @@
|
||||
"default": "YB"
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "freq-ndigits",
|
||||
"desc": "Set the number of digits to keep after the decimal point when printing CPU / GPU frequency in GHz",
|
||||
"arg": {
|
||||
"type": "num",
|
||||
"default": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "temp-unit",
|
||||
"desc": "Set the unit of the temperature",
|
||||
@@ -1177,14 +1185,6 @@
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "cpu-freq-ndigits",
|
||||
"desc": "Set the number of digits to keep after the decimal point when printing CPU frequency in GHz",
|
||||
"arg": {
|
||||
"type": "num",
|
||||
"default": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "cpu-show-pe-core-count",
|
||||
"desc": "Detect and display CPU frequency of different core types (eg. Pcore and Ecore) if supported",
|
||||
|
||||
+5
-15
@@ -79,7 +79,7 @@ void ffPrintCPU(FFCPUOptions* options)
|
||||
if(freq > 0)
|
||||
{
|
||||
ffStrbufAppendS(&str, " @ ");
|
||||
ffParseFrequency(freq, &str, options->freqNdigits);
|
||||
ffParseFrequency(freq, &str);
|
||||
}
|
||||
|
||||
if(cpu.temperature == cpu.temperature) //FF_CPU_TEMP_UNSET
|
||||
@@ -93,11 +93,11 @@ void ffPrintCPU(FFCPUOptions* options)
|
||||
else
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY freqBase = ffStrbufCreate();
|
||||
ffParseFrequency(cpu.frequencyBase, &freqBase, options->freqNdigits);
|
||||
ffParseFrequency(cpu.frequencyBase, &freqBase);
|
||||
FF_STRBUF_AUTO_DESTROY freqMax = ffStrbufCreate();
|
||||
ffParseFrequency(cpu.frequencyBase, &freqBase, options->freqNdigits);
|
||||
ffParseFrequency(cpu.frequencyBase, &freqBase);
|
||||
FF_STRBUF_AUTO_DESTROY freqBioslimit = ffStrbufCreate();
|
||||
ffParseFrequency(cpu.frequencyBiosLimit, &freqBioslimit, options->freqNdigits);
|
||||
ffParseFrequency(cpu.frequencyBiosLimit, &freqBioslimit);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate();
|
||||
ffTempsAppendNum(cpu.temperature, &tempStr, options->tempConfig, &options->moduleArgs);
|
||||
@@ -130,12 +130,6 @@ bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char
|
||||
if (ffTempsParseCommandOptions(key, subKey, value, &options->temp, &options->tempConfig))
|
||||
return true;
|
||||
|
||||
if (ffStrEqualsIgnCase(subKey, "freq-ndigits"))
|
||||
{
|
||||
options->freqNdigits = (int8_t) ffOptionParseInt32(key, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ffStrEqualsIgnCase(subKey, "show-pe-core-count"))
|
||||
{
|
||||
options->showPeCoreCount = ffOptionParseBoolean(value);
|
||||
@@ -163,7 +157,7 @@ void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module)
|
||||
|
||||
if (ffStrEqualsIgnCase(key, "freqNdigits"))
|
||||
{
|
||||
options->freqNdigits = (int8_t) yyjson_get_int(val);
|
||||
ffPrintError(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "modules.CPU.freqNdigits has been moved to display.freq.ndigits");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -186,9 +180,6 @@ void ffGenerateCPUJsonConfig(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
|
||||
|
||||
ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig);
|
||||
|
||||
if (defaultOptions.freqNdigits != options->freqNdigits)
|
||||
yyjson_mut_obj_add_int(doc, module, "freqNdigits", options->freqNdigits);
|
||||
|
||||
if (defaultOptions.showPeCoreCount != options->showPeCoreCount)
|
||||
yyjson_mut_obj_add_bool(doc, module, "showPeCoreCount", options->showPeCoreCount);
|
||||
}
|
||||
@@ -277,7 +268,6 @@ void ffInitCPUOptions(FFCPUOptions* options)
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
options->temp = false;
|
||||
options->tempConfig = (FFColorRangeConfig) { 60, 80 };
|
||||
options->freqNdigits = 2;
|
||||
options->showPeCoreCount = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,5 @@ typedef struct FFCPUOptions
|
||||
|
||||
bool temp;
|
||||
FFColorRangeConfig tempConfig;
|
||||
int8_t freqNdigits;
|
||||
bool showPeCoreCount;
|
||||
} FFCPUOptions;
|
||||
|
||||
+23
-2
@@ -208,8 +208,14 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
|
||||
yyjson_arr_foreach(val, idx, max, item)
|
||||
ffStrbufInitS(ffListAdd(&options->constants), yyjson_get_str(item));
|
||||
}
|
||||
else if (ffStrEqualsIgnCase(key, "tsVersion"))
|
||||
return "display.tsVersion has been renamed to general.detectVersion";
|
||||
else if (ffStrEqualsIgnCase(key, "freq"))
|
||||
{
|
||||
if (!yyjson_is_obj(val))
|
||||
return "display.freq must be an object";
|
||||
|
||||
yyjson_val* ndigits = yyjson_obj_get(val, "ndigits");
|
||||
if (ndigits) options->freqNdigits = (int8_t) yyjson_get_int(ndigits);
|
||||
}
|
||||
else
|
||||
return "Unknown display property";
|
||||
}
|
||||
@@ -366,6 +372,12 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if(ffStrStartsWithIgnCase(key, "--freq-"))
|
||||
{
|
||||
const char* subkey = key + strlen("--freq-");
|
||||
if(ffStrEqualsIgnCase(subkey, "ndigits"))
|
||||
options->freqNdigits = (int8_t) ffOptionParseInt32(key, value);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
@@ -413,6 +425,7 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options)
|
||||
ffStrbufInitStatic(&options->percentColorGreen, FF_COLOR_FG_GREEN);
|
||||
ffStrbufInitStatic(&options->percentColorYellow, instance.state.terminalLightTheme ? FF_COLOR_FG_YELLOW : FF_COLOR_FG_LIGHT_YELLOW);
|
||||
ffStrbufInitStatic(&options->percentColorRed, instance.state.terminalLightTheme ? FF_COLOR_FG_RED : FF_COLOR_FG_LIGHT_RED);
|
||||
options->freqNdigits = 2;
|
||||
|
||||
ffListInit(&options->constants, sizeof(FFstrbuf));
|
||||
}
|
||||
@@ -595,6 +608,14 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do
|
||||
if (options->keyWidth != defaultOptions.keyWidth)
|
||||
yyjson_mut_obj_add_uint(doc, obj, "keyWidth", options->keyWidth);
|
||||
|
||||
{
|
||||
yyjson_mut_val* freq = yyjson_mut_obj(doc);
|
||||
if (options->freqNdigits != defaultOptions.freqNdigits)
|
||||
yyjson_mut_obj_add_int(doc, freq, "ndigits", options->freqNdigits);
|
||||
if (yyjson_mut_obj_size(freq) > 0)
|
||||
yyjson_mut_obj_add_val(doc, obj, "freq", freq);
|
||||
}
|
||||
|
||||
if (yyjson_mut_obj_size(obj) > 0)
|
||||
yyjson_mut_obj_add_val(doc, doc->root, "display", obj);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ typedef struct FFOptionsDisplay
|
||||
FFstrbuf percentColorRed;
|
||||
bool noBuffer;
|
||||
uint32_t keyWidth;
|
||||
int8_t freqNdigits;
|
||||
FFlist constants; // list of FFstrbuf
|
||||
} FFOptionsDisplay;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user