mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
battery-format
This commit is contained in:
@@ -29,6 +29,7 @@ void ffDefaultConfig(FFconfig* config)
|
||||
config->batteryShowTechnology = true;
|
||||
config->batteryShowCapacity = true;
|
||||
config->batteryShowStatus = true;
|
||||
config->batteryFormat[0] = '\0';
|
||||
}
|
||||
|
||||
void ffPrintKey(FFconfig* config, const char* key)
|
||||
|
||||
+33
-2
@@ -75,6 +75,7 @@ static void printHelp()
|
||||
" --battery-technology <?value>: Show the technology of the battery, if possible\n"
|
||||
" --battery-capacity <?value>: Show the capacity of the battery, if possible\n"
|
||||
" --battery-status <?value>: Show the status of the battery, if possible\n"
|
||||
" --battery-formart <format>: Provide the printf format string for battery output (+)\n"
|
||||
"\n"
|
||||
"If an value starts with an ?, it is optional. \"true\" will be used if not set.\n"
|
||||
"An (+) at the end indicates that more help can be printed with --help <option>\n"
|
||||
@@ -82,7 +83,7 @@ static void printHelp()
|
||||
);
|
||||
}
|
||||
|
||||
static void printCommandHelpColor()
|
||||
static inline void printCommandHelpColor()
|
||||
{
|
||||
puts(
|
||||
"usage: fastfetch --color <color>\n"
|
||||
@@ -97,10 +98,25 @@ static void printCommandHelpColor()
|
||||
);
|
||||
}
|
||||
|
||||
static inline void printCommandHelpBatteryFormat()
|
||||
{
|
||||
puts(
|
||||
"usage fastfetch --battery-format <format>\n"
|
||||
"\n"
|
||||
"<format> is a string of maximum length 32, which is passed to printf as the format string.\n"
|
||||
"The arguments passed to printf are 5 strings in following order:\n"
|
||||
"manufacturer, model, technology, capacity, status\n"
|
||||
"If an value was disabled via battery-* argument, or could not be determined, it will be an zero length string.\n"
|
||||
"The default value is something like \"%s %s (%s) [%s; %s]\"."
|
||||
);
|
||||
}
|
||||
|
||||
static void printCommandHelp(const char* command)
|
||||
{
|
||||
if(strcasecmp(command, "c") == 0 || strcasecmp(command, "-c") == 0 || strcasecmp(command, "color") == 0 || strcasecmp(command, "--color") == 0)
|
||||
if(strcasecmp(command, "c") == 0 || strcasecmp(command, "color") == 0)
|
||||
printCommandHelpColor();
|
||||
else if(strcasecmp(command, "battery-format") == 0)
|
||||
printCommandHelpBatteryFormat();
|
||||
else
|
||||
printf("No specific help for command %s provided\n", command);
|
||||
}
|
||||
@@ -331,6 +347,21 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else
|
||||
instance->config.batteryShowStatus = parseBoolean(value);
|
||||
}
|
||||
else if(strcasecmp(key, "--battery-format") == 0)
|
||||
{
|
||||
if(value == NULL)
|
||||
{
|
||||
printf("Error: usage: %s <format>\n", key);
|
||||
exit(48);
|
||||
}
|
||||
size_t len = strlen(value);
|
||||
if(len > 32)
|
||||
{
|
||||
printf("max battery format string length is 32, %zu given\n", len);
|
||||
exit(49);
|
||||
}
|
||||
strcpy(instance->config.batteryFormat, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error: unknown option: %s\n", key);
|
||||
|
||||
@@ -40,6 +40,7 @@ typedef struct FFconfig
|
||||
bool showErrors;
|
||||
bool recache;
|
||||
|
||||
char batteryFormat[32];
|
||||
bool batteryShowManufacturer;
|
||||
bool batteryShowModel;
|
||||
bool batteryShowTechnology;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include "string.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FFinstance instance;
|
||||
|
||||
@@ -65,6 +65,13 @@ static void printBattery(FFinstance* instance, uint8_t index)
|
||||
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
|
||||
if(instance->config.batteryFormat[0] != '\0')
|
||||
{
|
||||
printf(instance->config.batteryFormat, manufactor, model, technology, capacity, status);
|
||||
putchar('\n');
|
||||
return;
|
||||
}
|
||||
|
||||
if(manufactor[0] != '\0')
|
||||
printf("%s ", manufactor);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "X11/extensions/Xrandr.h"
|
||||
#include "dlfcn.h"
|
||||
|
||||
short getCurrentRate(Display* display)
|
||||
static short getCurrentRate(Display* display)
|
||||
{
|
||||
void* xrandr = dlopen("libXrandr.so", RTLD_LAZY);
|
||||
if(xrandr == NULL)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
void printTerminalName(FFinstance* instance, const char* pid)
|
||||
static void printTerminalName(FFinstance* instance, const char* pid)
|
||||
{
|
||||
char file[256];
|
||||
sprintf(file, "/proc/%s/stat", pid);
|
||||
|
||||
@@ -24,10 +24,7 @@ void ffValuestoreSet(FFvaluestore* vs, const char* name, const char* value)
|
||||
|
||||
if(vs->size == vs->capacity)
|
||||
{
|
||||
FFvaluestorePair* pairs = (FFvaluestorePair*) calloc(vs->capacity * 2, sizeof(FFvaluestorePair));
|
||||
memcpy(pairs, vs->pairs, sizeof(FFvaluestorePair) * vs->size);
|
||||
free(vs->pairs);
|
||||
vs->pairs = pairs;
|
||||
vs->pairs = realloc(vs->pairs, vs->capacity * sizeof(FFvaluestorePair) * 2);
|
||||
vs->capacity *= 2;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user