mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-31 10:02:49 +01:00
Global: support bar output for percentage value #294
This commit is contained in:
@@ -12,7 +12,7 @@ typedef struct BatteryResult
|
||||
FFstrbuf manufacturer;
|
||||
FFstrbuf modelName;
|
||||
FFstrbuf technology;
|
||||
FFstrbuf capacity;
|
||||
double capacity;
|
||||
FFstrbuf status;
|
||||
double temperature;
|
||||
} BatteryResult;
|
||||
|
||||
@@ -55,7 +55,7 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
const char* error;
|
||||
|
||||
BatteryResult* battery = ffListAdd(results);
|
||||
ffStrbufInit(&battery->capacity);
|
||||
battery->capacity = 0.0/0.0;
|
||||
int currentCapacity, maxCapacity;
|
||||
|
||||
if ((error = ffCfDictGetInt(properties, CFSTR("MaxCapacity"), &maxCapacity)))
|
||||
@@ -68,7 +68,7 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
if(currentCapacity <= 0)
|
||||
return "Querying CurrentCapacity failed";
|
||||
|
||||
ffStrbufAppendF(&battery->capacity, "%.0f", currentCapacity * 100.0 / maxCapacity);
|
||||
battery->capacity = currentCapacity * 100.0 / maxCapacity;
|
||||
|
||||
ffStrbufInit(&battery->manufacturer);
|
||||
ffStrbufInit(&battery->modelName);
|
||||
|
||||
@@ -33,18 +33,18 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
|
||||
return;
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&testBatteryBuffer);
|
||||
BatteryResult* result = ffListAdd(results);
|
||||
|
||||
//capacity must exist and be not empty
|
||||
ffStrbufInit(&result->capacity);
|
||||
ffStrbufAppendS(dir, "/capacity");
|
||||
ffReadFileBuffer(dir->chars, &result->capacity);
|
||||
bool available = ffReadFileBuffer(dir->chars, &testBatteryBuffer);
|
||||
ffStrbufSubstrBefore(dir, dirLength);
|
||||
|
||||
if(result->capacity.length == 0)
|
||||
if(available)
|
||||
result->capacity = ffStrbufToDouble(&testBatteryBuffer);
|
||||
ffStrbufDestroy(&testBatteryBuffer);
|
||||
if(!available)
|
||||
{
|
||||
ffStrbufDestroy(&result->capacity);
|
||||
result->capacity = 0.0/0.0;
|
||||
--results->length;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,9 +38,7 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
default: ffStrbufInit(&battery->technology); break;
|
||||
}
|
||||
|
||||
uint64_t capacity;
|
||||
record.getUnsigned(L"EstimatedChargeRemaining", &capacity);
|
||||
ffStrbufInitF(&battery->capacity, "%d", (int)capacity);
|
||||
record.getReal(L"EstimatedChargeRemaining", &battery->capacity);
|
||||
|
||||
uint64_t batteryStatus;
|
||||
record.getUnsigned(L"BatteryStatus", &batteryStatus);
|
||||
|
||||
Reference in New Issue
Block a user