mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Global: support bar output for percentage value #294
This commit is contained in:
+35
-15
@@ -1,11 +1,12 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "common/bar.h"
|
||||
#include "detection/battery/battery.h"
|
||||
|
||||
#define FF_BATTERY_MODULE_NAME "Battery"
|
||||
#define FF_BATTERY_NUM_FORMAT_ARGS 5
|
||||
|
||||
static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t index)
|
||||
static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t index)
|
||||
{
|
||||
if(instance->config.battery.outputFormat.length == 0)
|
||||
{
|
||||
@@ -15,27 +16,47 @@ static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t i
|
||||
result->status.length > 0 &&
|
||||
ffStrbufIgnCaseCompS(&result->status, "Unknown") != 0;
|
||||
|
||||
if(result->capacity.length > 0)
|
||||
{
|
||||
ffStrbufWriteTo(&result->capacity, stdout);
|
||||
putchar('%');
|
||||
FFstrbuf str;
|
||||
ffStrbufInit(&str);
|
||||
|
||||
if(showStatus)
|
||||
fputs(" [", stdout);
|
||||
if(result->capacity >= 0)
|
||||
{
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
{
|
||||
if(result->capacity <= 20)
|
||||
ffAppendPercentBar(instance, &str, (uint8_t)result->capacity, 10, 10, 0);
|
||||
else if(result->capacity <= 50)
|
||||
ffAppendPercentBar(instance, &str, (uint8_t)result->capacity, 10, 0, 10);
|
||||
else
|
||||
ffAppendPercentBar(instance, &str, (uint8_t)result->capacity, 0, 10, 10);
|
||||
}
|
||||
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
{
|
||||
if(str.length > 0)
|
||||
ffStrbufAppendC(&str, ' ');
|
||||
ffStrbufAppendF(&str, "%.0f%%", result->capacity);
|
||||
}
|
||||
}
|
||||
|
||||
if(showStatus)
|
||||
{
|
||||
ffStrbufWriteTo(&result->status, stdout);
|
||||
|
||||
if(result->capacity.length > 0)
|
||||
putchar(']');
|
||||
if(str.length > 0)
|
||||
ffStrbufAppendF(&str, " [%s]", result->status.chars);
|
||||
else
|
||||
ffStrbufAppend(&str, &result->status);
|
||||
}
|
||||
|
||||
if(result->temperature == result->temperature) //FF_BATTERY_TEMP_UNSET
|
||||
printf(" - %.1f°C", result->temperature);
|
||||
{
|
||||
if(str.length > 0)
|
||||
ffStrbufAppendS(&str, " - ");
|
||||
|
||||
putchar('\n');
|
||||
ffStrbufAppendF(&str, "%.1f°C", result->temperature);
|
||||
}
|
||||
|
||||
ffStrbufPutTo(&str, stdout);
|
||||
ffStrbufDestroy(&str);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -43,7 +64,7 @@ static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t i
|
||||
{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, &result->capacity},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &result->capacity},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->status},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature},
|
||||
});
|
||||
@@ -71,7 +92,6 @@ void ffPrintBattery(FFinstance* instance)
|
||||
ffStrbufDestroy(&result->manufacturer);
|
||||
ffStrbufDestroy(&result->modelName);
|
||||
ffStrbufDestroy(&result->technology);
|
||||
ffStrbufDestroy(&result->capacity);
|
||||
ffStrbufDestroy(&result->status);
|
||||
}
|
||||
if(results.length == 0)
|
||||
|
||||
+16
-4
@@ -1,5 +1,6 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "common/bar.h"
|
||||
#include "detection/cpuUsage/cpuUsage.h"
|
||||
|
||||
#define FF_CPU_USAGE_MODULE_NAME "CPU Usage"
|
||||
@@ -7,8 +8,8 @@
|
||||
|
||||
void ffPrintCPUUsage(FFinstance* instance)
|
||||
{
|
||||
double cpuPercent = 0.0/0.0;
|
||||
const char* error = ffGetCpuUsageResult(&cpuPercent);
|
||||
double percentage = 0.0/0.0;
|
||||
const char* error = ffGetCpuUsageResult(&percentage);
|
||||
|
||||
if(error)
|
||||
{
|
||||
@@ -20,12 +21,23 @@ void ffPrintCPUUsage(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsage.key);
|
||||
|
||||
printf("%.2lf%%\n", cpuPercent);
|
||||
FFstrbuf str;
|
||||
ffStrbufInit(&str);
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
ffAppendPercentBar(instance, &str, (uint8_t)percentage, 0, 5, 8);
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
{
|
||||
if(str.length > 0)
|
||||
ffStrbufAppendC(&str, ' ');
|
||||
ffStrbufAppendF(&str, "%.2lf%%", percentage);
|
||||
}
|
||||
ffStrbufPutTo(&str, stdout);
|
||||
ffStrbufDestroy(&str);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsage, FF_CPU_USAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpuPercent}
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &percentage}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+21
-4
@@ -1,6 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "common/parsing.h"
|
||||
#include "common/bar.h"
|
||||
#include "detection/disk/disk.h"
|
||||
|
||||
#define FF_DISK_MODULE_NAME "Disk"
|
||||
@@ -35,14 +36,30 @@ static void printDisk(FFinstance* instance, const FFDisk* disk)
|
||||
if(instance->config.disk.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, key.chars, 0, NULL);
|
||||
|
||||
FFstrbuf str;
|
||||
ffStrbufInit(&str);
|
||||
|
||||
if(disk->bytesTotal > 0)
|
||||
printf("%s / %s (%u%%)", usedPretty.chars, totalPretty.chars, bytesPercentage);
|
||||
{
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
{
|
||||
ffAppendPercentBar(instance, &str, bytesPercentage, 0, 5, 8);
|
||||
ffStrbufAppendC(&str, ' ');
|
||||
}
|
||||
ffStrbufAppendF(&str, "%s / %s", usedPretty.chars, totalPretty.chars);
|
||||
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
ffStrbufAppendF(&str, " (%u%%)", bytesPercentage);
|
||||
}
|
||||
else
|
||||
fputs("unknown", stdout);
|
||||
ffStrbufAppendS(&str, "Unknown");
|
||||
|
||||
if(disk->type == FF_DISK_TYPE_EXTERNAL)
|
||||
printf(" [Removable]");
|
||||
putchar('\n');
|
||||
ffStrbufAppendS(&str, " [Removable]");
|
||||
|
||||
ffStrbufPutTo(&str, stdout);
|
||||
ffStrbufDestroy(&str);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+19
-1
@@ -1,6 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "common/parsing.h"
|
||||
#include "common/bar.h"
|
||||
#include "detection/memory/memory.h"
|
||||
#include "detection/swap/swap.h"
|
||||
|
||||
@@ -41,7 +42,24 @@ static void printMemory(FFinstance* instance, const char* name, const FFModuleAr
|
||||
if (storage->bytesTotal == 0)
|
||||
puts("Disabled");
|
||||
else
|
||||
printf("%s / %s (%u%%)\n", usedPretty.chars, totalPretty.chars, percentage);
|
||||
{
|
||||
FFstrbuf str;
|
||||
ffStrbufInit(&str);
|
||||
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
{
|
||||
ffAppendPercentBar(instance, &str, percentage, 0, 5, 8);
|
||||
ffStrbufAppendC(&str, ' ');
|
||||
}
|
||||
|
||||
ffStrbufAppendF(&str, "%s / %s", usedPretty.chars, totalPretty.chars);
|
||||
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
ffStrbufAppendF(&str, " (%u%%)", percentage);
|
||||
|
||||
ffStrbufPutTo(&str, stdout);
|
||||
ffStrbufDestroy(&str);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user