Merge branch 'dev' of github.com:LinusDierheimer/fastfetch into dev

This commit is contained in:
Linus Dierheimer
2023-01-14 16:38:52 +01:00
18 changed files with 134 additions and 108 deletions
+1
View File
@@ -9,6 +9,7 @@ enum
{
FF_PERCENTAGE_TYPE_NUM_BIT = 1,
FF_PERCENTAGE_TYPE_BAR_BIT = 2,
FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT = 4,
};
void ffAppendPercentBar(FFinstance* instance, FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_t yellow, uint8_t red);
+4
View File
@@ -402,6 +402,10 @@ static void resetConsole()
if(ffHideCursor)
fputs("\033[?25h", stdout);
#if defined(_WIN32) && defined(FF_ENABLE_BUFFER)
fflush(stdout);
#endif
}
#ifdef _WIN32
+1 -1
View File
@@ -259,7 +259,7 @@
# Percentage output type option
# Applies to all modules that prints percentage values. Currently memory, swap, disk, battery and CPU usage are supported.
# Only works with default format ( without --module-format option ).
# 0: prints none; 1: prints percent number only; 2: prints bar only; 3: prints both percent number and bar
# 0: prints none; 1: prints percent number only; 2: prints bar only; 3: prints both percent number and bar; 6: prints bar and hide other texts
#--percent-type 1
# Key options:
+1 -1
View File
@@ -125,7 +125,7 @@ Module specific options:
--weather-output-format: The output weather format to be used. It must be URI encoded.
--player-name: The name of the player to use
--gl <value>: Set the OpenGL context creation library to use. Must be auto, egl, glx or osmesa. Default is auto
--percent-type <value>: Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both. Default is 1
--percent-type <value>: Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only. Default is 1
Parsing is not case sensitive. E.g. "--lib-PCI" is equal to "--Lib-Pci"
If a value starts with a ?, it is optional. "true" will be used if not set.
+1
View File
@@ -8,6 +8,7 @@
#define FF_GPU_TEMP_UNSET (0/0.0)
#define FF_GPU_CORE_COUNT_UNSET -1
#define FF_GPU_VENDOR_NAME_APPLE "Apple"
#define FF_GPU_VENDOR_NAME_AMD "AMD"
#define FF_GPU_VENDOR_NAME_INTEL "Intel"
#define FF_GPU_VENDOR_NAME_NVIDIA "NVIDIA"
+26 -1
View File
@@ -5,6 +5,7 @@
#include "util/apple/cf_helpers.h"
#include <IOKit/graphics/IOGraphicsLib.h>
#include <wchar.h>
static double detectGpuTemp(const FFstrbuf* gpuName)
{
@@ -61,7 +62,31 @@ const char* ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
gpu->type = FF_GPU_TYPE_UNKNOWN;
ffStrbufInitA(&gpu->vendor, 0);
ffStrbufInit(&gpu->vendor);
int vendorId;
if(!ffCfDictGetInt(properties, CFSTR("vendor-id"), &vendorId))
{
if(vendorId == 0x106b)
{
ffStrbufAppendS(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE);
gpu->type = FF_GPU_TYPE_INTEGRATED;
}
else if(wmemchr((const wchar_t[]) {0x1002, 0x1022}, (wchar_t)vendorId, 2))
{
ffStrbufAppendS(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
gpu->type = FF_GPU_TYPE_DISCRETE; // Apple never used AMD CPUs
}
else if(wmemchr((const wchar_t[]) {0x03e7, 0x8086, 0x8087}, (wchar_t)vendorId, 3))
{
ffStrbufAppendS(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
gpu->type = FF_GPU_TYPE_INTEGRATED;
}
else if(wmemchr((const wchar_t[]) {0x0955, 0x10de, 0x12d2}, (wchar_t)vendorId, 3))
{
ffStrbufAppendS(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
gpu->type = FF_GPU_TYPE_DISCRETE;
}
}
ffStrbufInit(&gpu->driver);
ffCfDictGetString(properties, CFSTR("CFBundleIdentifier"), &gpu->driver);
+2 -2
View File
@@ -26,8 +26,6 @@ static const char* detectWithDxgi(FFlist* gpus)
FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
gpu->type = FF_GPU_TYPE_UNKNOWN;
if(wmemchr((const wchar_t[]) {0x1002, 0x1022}, (wchar_t)desc.VendorId, 2))
ffStrbufInitS(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
else if(wmemchr((const wchar_t[]) {0x03e7, 0x8086, 0x8087}, (wchar_t)desc.VendorId, 3))
@@ -42,6 +40,8 @@ static const char* detectWithDxgi(FFlist* gpus)
ffStrbufInit(&gpu->driver);
gpu->type = desc.DedicatedVideoMemory >= 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
adapter->Release();
gpu->temperature = FF_GPU_TEMP_UNSET;
+2 -1
View File
@@ -13,6 +13,7 @@ static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t in
ffPrintLogoAndKey(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.battery.key);
bool showStatus =
!(instance->config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT) &&
result->status.length > 0 &&
ffStrbufIgnCaseCompS(&result->status, "Unknown") != 0;
@@ -35,7 +36,7 @@ static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t in
{
if(str.length > 0)
ffStrbufAppendC(&str, ' ');
ffStrbufAppendF(&str, "%.0f%%", result->capacity);
ffStrbufAppendF(&str, str.length > 0 ? "(%u%%)" : "%u%%", (unsigned) result->capacity);
}
}
+10 -5
View File
@@ -47,17 +47,22 @@ static void printDisk(FFinstance* instance, const FFDisk* disk)
ffAppendPercentBar(instance, &str, bytesPercentage, 0, 5, 8);
ffStrbufAppendC(&str, ' ');
}
ffStrbufAppendF(&str, "%s / %s", usedPretty.chars, totalPretty.chars);
if(!(instance->config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars);
if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffStrbufAppendF(&str, " (%u%%)", bytesPercentage);
{
ffStrbufAppendF(&str, str.length > 0 ? "(%u%%) " : "%u%% ", bytesPercentage);
}
}
else
ffStrbufAppendS(&str, "Unknown");
ffStrbufAppendS(&str, "Unknown ");
if(disk->type == FF_DISK_TYPE_EXTERNAL)
ffStrbufAppendS(&str, " [Removable]");
if(disk->type == FF_DISK_TYPE_EXTERNAL && !(instance->config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppendS(&str, "[Removable]");
ffStrbufTrimRight(&str, ' ');
ffStrbufPutTo(&str, stdout);
ffStrbufDestroy(&str);
}
+5 -7
View File
@@ -37,13 +37,13 @@ static void printGPUResult(FFinstance* instance, uint8_t index, const FFGPUResul
}
else
{
FFstrbuf type;
const char* type;
if(gpu->type == FF_GPU_TYPE_INTEGRATED)
ffStrbufInitS(&type, "Integrated");
type = "Integrated";
else if(gpu->type == FF_GPU_TYPE_DISCRETE)
ffStrbufInitS(&type, "Discrete");
type = "Discrete";
else
ffStrbufInitS(&type, "Unknown");
type = "Unknown";
ffPrintFormat(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor},
@@ -51,10 +51,8 @@ static void printGPUResult(FFinstance* instance, uint8_t index, const FFGPUResul
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver},
{FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature},
{FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount},
{FF_FORMAT_ARG_TYPE_STRBUF, &type},
{FF_FORMAT_ARG_TYPE_STRING, type},
});
ffStrbufDestroy(&type);
}
}
+4 -2
View File
@@ -52,11 +52,13 @@ static void printMemory(FFinstance* instance, const char* name, const FFModuleAr
ffStrbufAppendC(&str, ' ');
}
ffStrbufAppendF(&str, "%s / %s", usedPretty.chars, totalPretty.chars);
if(!(instance->config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars);
if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffStrbufAppendF(&str, " (%u%%)", percentage);
ffStrbufAppendF(&str, str.length > 0 ? "(%u%%)" : "%u%%", percentage);
ffStrbufTrimRight(&str, ' ');
ffStrbufPutTo(&str, stdout);
ffStrbufDestroy(&str);
}
+22
View File
@@ -1,6 +1,7 @@
#include "FFlist.h"
#include <stdlib.h>
#include <string.h>
void ffListInitA(FFlist* list, uint32_t elementSize, uint32_t capacity)
{
@@ -34,6 +35,27 @@ uint32_t ffListFirstIndexComp(const FFlist* list, void* compElement, bool(*compF
return list->length;
}
bool ffListShift(FFlist* list, void* result)
{
if(list->length == 0)
return false;
memcpy(result, list->data, list->elementSize);
memmove(list->data, list->data + list->elementSize, list->elementSize * (list->length - 1));
--list->length;
return true;
}
bool ffListPop(FFlist* list, void* result)
{
if(list->length == 0)
return false;
memcpy(result, ffListGet(list, list->length - 1), list->elementSize);
--list->length;
return result;
}
void ffListDestroy(FFlist* list)
{
//Avoid free-after-use. These 3 assignments are cheap so don't remove them
+5
View File
@@ -26,6 +26,11 @@ void* ffListAdd(FFlist* list);
FF_C_NODISCARD uint32_t ffListFirstIndexComp(const FFlist* list, void* compElement, bool(*compFunc)(const void*, const void*));
// Removes the first element, and copy its value to `*result`
bool ffListShift(FFlist* list, void* result);
// Removes the last element, and copy its value to `*result`
bool ffListPop(FFlist* list, void* result);
void ffListDestroy(FFlist* list);
static inline void ffListInit(FFlist* list, uint32_t elementSize)
+22 -7
View File
@@ -44,7 +44,10 @@ const char* ffCfDictGetString(CFDictionaryRef dict, CFStringRef key, FFstrbuf* r
const char* ffCfDictGetBool(CFDictionaryRef dict, CFStringRef key, bool* result)
{
CFBooleanRef cf = (CFBooleanRef)CFDictionaryGetValue(dict, key);
if(cf == NULL || CFGetTypeID(cf) != CFBooleanGetTypeID())
if(cf == NULL)
return "CFDictionaryGetValue() failed";
if(CFGetTypeID(cf) != CFBooleanGetTypeID())
return "TypeID is not 'CFBoolean'";
*result = CFBooleanGetValue(cf);
@@ -53,13 +56,25 @@ const char* ffCfDictGetBool(CFDictionaryRef dict, CFStringRef key, bool* result)
const char* ffCfDictGetInt(CFDictionaryRef dict, CFStringRef key, int* result)
{
CFNumberRef cf = (CFNumberRef)CFDictionaryGetValue(dict, key);
if (cf == NULL || CFGetTypeID(cf) != CFNumberGetTypeID())
return "TypeID is not 'CFNumber'";
CFTypeRef cf = (CFTypeRef)CFDictionaryGetValue(dict, key);
if(cf == NULL)
return "CFDictionaryGetValue() failed";
if(!CFNumberGetValue(cf, kCFNumberSInt32Type, result))
return "Number type is not SInt32";
return NULL;
if(CFGetTypeID(cf) == CFNumberGetTypeID())
{
if(!CFNumberGetValue((CFNumberRef)cf, kCFNumberSInt32Type, result))
return "Number type is not SInt32";
return NULL;
}
else if(CFGetTypeID(cf) == CFDataGetTypeID())
{
if(CFDataGetLength((CFDataRef)cf) != sizeof(int))
return "Data length is not sizeof(int)";
CFDataGetBytes((CFDataRef)cf, CFRangeMake(0, sizeof(int)), (uint8_t*)result);
return NULL;
}
return "TypeID is neither 'CFNumber' nor 'CFData'";
}
const char* ffCfDictGetDict(CFDictionaryRef dict, CFStringRef key, CFDictionaryRef* result)