Global: fix percent formatting for --*-format

fix #535
This commit is contained in:
李通洲
2023-08-24 09:12:24 +08:00
parent 7218164088
commit 326d83f25b
6 changed files with 25 additions and 13 deletions
+5 -4
View File
@@ -10,17 +10,16 @@
static void printBattery(FFBatteryOptions* options, BatteryResult* result, uint8_t index)
{
if(instance.config.battery.moduleArgs.outputFormat.length == 0)
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
bool showStatus =
!(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT) &&
result->status.length > 0 &&
ffStrbufIgnCaseCompS(&result->status, "Unknown") != 0;
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
if(result->capacity >= 0)
{
if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
@@ -62,11 +61,13 @@ static void printBattery(FFBatteryOptions* options, BatteryResult* result, uint8
}
else
{
FF_STRBUF_AUTO_DESTROY capacityStr = ffStrbufCreate();
ffAppendPercentNum(&capacityStr, result->capacity, 51, 21, false);
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_DOUBLE, &result->capacity},
{FF_FORMAT_ARG_TYPE_STRBUF, &capacityStr},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->status},
{FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature},
});
+4 -3
View File
@@ -43,10 +43,9 @@ void ffPrintBrightness(FFBrightnessOptions* options)
});
}
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
if(options->moduleArgs.outputFormat.length == 0)
{
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
if (instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
@@ -66,8 +65,10 @@ void ffPrintBrightness(FFBrightnessOptions* options)
}
else
{
FF_STRBUF_AUTO_DESTROY valueStr = ffStrbufCreate();
ffAppendPercentNum(&valueStr, item->value, 10, 10, false);
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_BRIGHTNESS_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_FLOAT, &item->value},
{FF_FORMAT_ARG_TYPE_STRBUF, &valueStr},
{FF_FORMAT_ARG_TYPE_STRBUF, &item->name},
});
}
+3 -1
View File
@@ -36,8 +36,10 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
}
else
{
FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate();
ffAppendPercentNum(&percentageStr, percentage, 50, 80, false);
ffPrintFormat(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_CPUUSAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_DOUBLE, &percentage}
{FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr}
});
}
}
+7 -3
View File
@@ -92,17 +92,21 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
}
else
{
uint8_t filesPercentage = disk->filesTotal > 0 ? (uint8_t) (((double) disk->filesUsed / (double) disk->filesTotal) * 100.0) : 0;
FF_STRBUF_AUTO_DESTROY bytesPercentageStr = ffStrbufCreate();
ffAppendPercentNum(&bytesPercentageStr, bytesPercentage, 50, 80, false);
FF_STRBUF_AUTO_DESTROY filesPercentageStr = ffStrbufCreate();
double filesPercentage = disk->filesTotal > 0 ? ((double) disk->filesUsed / (double) disk->filesTotal) * 100.0 : 0;
ffAppendPercentNum(&filesPercentageStr, filesPercentage, 50, 80, false);
bool isExternal = !!(disk->type & FF_DISK_TYPE_EXTERNAL_BIT);
bool isHidden = !!(disk->type & FF_DISK_TYPE_HIDDEN_BIT);
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
{FF_FORMAT_ARG_TYPE_UINT8, &bytesPercentage},
{FF_FORMAT_ARG_TYPE_STRBUF, &bytesPercentageStr},
{FF_FORMAT_ARG_TYPE_UINT, &disk->filesUsed},
{FF_FORMAT_ARG_TYPE_UINT, &disk->filesTotal},
{FF_FORMAT_ARG_TYPE_UINT8, &filesPercentage},
{FF_FORMAT_ARG_TYPE_STRBUF, &filesPercentageStr},
{FF_FORMAT_ARG_TYPE_BOOL, &isExternal},
{FF_FORMAT_ARG_TYPE_BOOL, &isHidden},
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem},
+3 -1
View File
@@ -56,10 +56,12 @@ void ffPrintMemory(FFMemoryOptions* options)
}
else
{
FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate();
ffAppendPercentNum(&percentageStr, percentage, 50, 80, false);
ffPrintFormat(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
{FF_FORMAT_ARG_TYPE_UINT8, &percentage},
{FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr},
});
}
}
+3 -1
View File
@@ -63,10 +63,12 @@ void ffPrintSwap(FFSwapOptions* options)
}
else
{
FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate();
ffAppendPercentNum(&percentageStr, percentage, 50, 80, false);
ffPrintFormat(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, FF_SWAP_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
{FF_FORMAT_ARG_TYPE_UINT8, &percentage},
{FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr},
});
}
}