mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 08:13:44 +01:00
prettier GPU output
This commit is contained in:
+3
-2
@@ -407,10 +407,11 @@ static inline void printCommandHelp(const char* command)
|
||||
}
|
||||
else if(strcasecmp(command, "gpu-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("gpu", "{2} {3}", 3,
|
||||
constructAndPrintCommandHelpFormat("gpu", "{2} {4}", 4,
|
||||
"GPU vendor",
|
||||
"GPU vendor pretty",
|
||||
"GPU name"
|
||||
"GPU name",
|
||||
"GPU name pretty"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "memory-format") == 0)
|
||||
|
||||
+13
-3
@@ -5,11 +5,12 @@
|
||||
#include <pci/pci.h>
|
||||
|
||||
#define FF_GPU_MODULE_NAME "GPU"
|
||||
#define FF_GPU_NUM_FORMAT_ARGS 3
|
||||
#define FF_GPU_NUM_FORMAT_ARGS 4
|
||||
|
||||
static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_dev* dev, FFcache* cache, uint8_t counter, char*(*ffpci_lookup_name)(struct pci_access*, char*, int, int, ...))
|
||||
{
|
||||
char vendor[512];
|
||||
vendor[0] = '\0';
|
||||
ffpci_lookup_name(pacc, vendor, sizeof(vendor), PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id);
|
||||
|
||||
const char* vendorPretty;
|
||||
@@ -23,20 +24,29 @@ static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_
|
||||
vendorPretty = vendor;
|
||||
|
||||
char name[512];
|
||||
name[0] = '\0';
|
||||
ffpci_lookup_name(pacc, name, sizeof(name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
|
||||
|
||||
FFstrbuf namePretty;
|
||||
ffStrbufInitA(&namePretty, 512);
|
||||
ffStrbufAppendS(&namePretty, name);
|
||||
ffStrbufSubstrBeforeLastC(&namePretty, ']');
|
||||
ffStrbufSubstrAfterFirstC(&namePretty, '[');
|
||||
|
||||
FFstrbuf gpu;
|
||||
ffStrbufInitA(&gpu, 128);
|
||||
|
||||
ffStrbufSetF(&gpu, "%s %s", vendorPretty, name);
|
||||
ffStrbufSetF(&gpu, "%s %s", vendorPretty, namePretty.chars);
|
||||
|
||||
ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, counter, &instance->config.gpuKey, cache, &gpu, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRING, vendor},
|
||||
{FF_FORMAT_ARG_TYPE_STRING, vendorPretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRING, name}
|
||||
{FF_FORMAT_ARG_TYPE_STRING, name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &namePretty}
|
||||
});
|
||||
|
||||
ffStrbufDestroy(&gpu);
|
||||
ffStrbufDestroy(&namePretty);
|
||||
}
|
||||
|
||||
void ffPrintGPU(FFinstance* instance)
|
||||
|
||||
@@ -417,6 +417,11 @@ void ffStrbufSubstrBeforeFirstC(FFstrbuf* strbuf, const char c)
|
||||
ffStrbufSubstrBefore(strbuf, ffStrbufFirstIndexC(strbuf, c));
|
||||
}
|
||||
|
||||
void ffStrbufSubstrBeforeLastC(FFstrbuf* strbuf, const char c)
|
||||
{
|
||||
ffStrbufSubstrBefore(strbuf, ffStrbufLastIndexC(strbuf, c));
|
||||
}
|
||||
|
||||
void ffStrbufSubstrAfter(FFstrbuf* strbuf, uint32_t index)
|
||||
{
|
||||
if(index >= strbuf->length)
|
||||
@@ -430,6 +435,13 @@ void ffStrbufSubstrAfter(FFstrbuf* strbuf, uint32_t index)
|
||||
strbuf->chars[strbuf->length] = '\0';
|
||||
}
|
||||
|
||||
void ffStrbufSubstrAfterFirstC(FFstrbuf* strbuf, const char c)
|
||||
{
|
||||
uint32_t index = ffStrbufFirstIndexC(strbuf, c);
|
||||
if(index < strbuf->length)
|
||||
ffStrbufSubstrAfter(strbuf, index);
|
||||
}
|
||||
|
||||
void ffStrbufSubstrAfterLastC(FFstrbuf* strbuf, const char c)
|
||||
{
|
||||
uint32_t index = ffStrbufLastIndexC(strbuf, c);
|
||||
|
||||
@@ -78,7 +78,9 @@ uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, const char c);
|
||||
|
||||
void ffStrbufSubstrBefore(FFstrbuf* strbuf, uint32_t index);
|
||||
void ffStrbufSubstrBeforeFirstC(FFstrbuf* strbuf, const char c);
|
||||
void ffStrbufSubstrBeforeLastC(FFstrbuf* strbuf, const char c);
|
||||
void ffStrbufSubstrAfter(FFstrbuf* strbuf, uint32_t index);
|
||||
void ffStrbufSubstrAfterFirstC(FFstrbuf* strbuf, const char c);
|
||||
void ffStrbufSubstrAfterLastC(FFstrbuf* strbuf, const char c);
|
||||
|
||||
bool ffStrbufStartsWith(const FFstrbuf* strbuf, const FFstrbuf* start);
|
||||
|
||||
Reference in New Issue
Block a user