mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 08:13:44 +01:00
Color name mapping
This commit is contained in:
@@ -5,7 +5,6 @@ Here i just add things that are easy to forget.
|
||||
|
||||
## Features i am planning to implement
|
||||
|
||||
- [ ] Support for color name mapping (e.g. --color red)
|
||||
- [ ] Support for printing images as ascii art logos (using imlib2 and libcaca probably)
|
||||
- [ ] Support for printing images in terminals that support it
|
||||
- [ ] Better documentation (especially default config file and the various --help options. Colored output?)
|
||||
|
||||
+5
-5
@@ -37,10 +37,10 @@
|
||||
|
||||
# Color option:
|
||||
# Sets the color of the keys.
|
||||
# Must be linux console color codes.
|
||||
# Must be linux console color codes or the name of a color.
|
||||
# Default is the primary color of the logo.
|
||||
# Use "fastfetch --help color" to learn more and see examples.
|
||||
#--color 35
|
||||
#--color magenta
|
||||
|
||||
# Spacing option:
|
||||
# Sets the amount of whitespace between the logo and keys.
|
||||
@@ -105,14 +105,14 @@
|
||||
# Logo color options:
|
||||
# Overwrite a color in the logo. Also works for user provided logos.
|
||||
# In the user logo, they replace $[1-9]. Use $$ to print a single $ sign.
|
||||
# Must be linux console color codes.
|
||||
# Must be linux console color codes or the name of a color.
|
||||
# Default is the one specified by the logo.
|
||||
# Use "fastfetch --help color" to learn more and see examples.
|
||||
# Valid index range is [1-9].
|
||||
#--color-1 31
|
||||
#--color-1 red
|
||||
#--color-2 32
|
||||
# [...]
|
||||
#--color-9 39
|
||||
#--color-9 yellow
|
||||
|
||||
# User logo raw option:
|
||||
# Sets if color replacements should be performed on the user provided logo.
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ Informative options:
|
||||
General options:
|
||||
--structure <structure>: sets the structure of the fetch. Must be a colon separated list of keys. Use "fastfetch --list-modules" to see the ones available.
|
||||
--set <key=value>: hard set the value of a key
|
||||
-c <color>, --color <color>: sets the color of the keys. Must be a linux console color code (+)
|
||||
--color-[1-9] <color>: overwrites a color of the logo. Must be a linux console color code
|
||||
-c <color>, --color <color>: sets the color of the keys. Must be a linux console color code or the name of a color (+)
|
||||
--color-[1-9] <color>: overwrites a color of the logo. Must be a linux console color code or the name of a color
|
||||
--spacing <width>: sets the distance between logo and text
|
||||
-s <str>, --separator <str>: sets the separator between key and value. Default is a colon with a space
|
||||
-x <offset>, --offsetx <offset>: sets the x offset. Can be negative to cut the logo, but no more than logo width.
|
||||
|
||||
+85
-4
@@ -485,7 +485,7 @@ static void optionParseConfigFile(FFinstance* instance, FFdata* data, const char
|
||||
exit(414);
|
||||
}
|
||||
|
||||
static inline bool optionParseBoolean(const char* str)
|
||||
static bool optionParseBoolean(const char* str)
|
||||
{
|
||||
return (
|
||||
str == NULL ||
|
||||
@@ -497,7 +497,7 @@ static inline bool optionParseBoolean(const char* str)
|
||||
);
|
||||
}
|
||||
|
||||
static inline void optionParseString(const char* key, const char* value, FFstrbuf* buffer)
|
||||
static inline void optionCheckString(const char* key, const char* value, FFstrbuf* buffer)
|
||||
{
|
||||
if(value == NULL)
|
||||
{
|
||||
@@ -505,9 +505,90 @@ static inline void optionParseString(const char* key, const char* value, FFstrbu
|
||||
exit(477);
|
||||
}
|
||||
ffStrbufEnsureFree(buffer, 63); //This is not needed, as ffStrbufSetS will resize capacity if needed, but giving a higher start should improve performance
|
||||
}
|
||||
|
||||
static void optionParseString(const char* key, const char* value, FFstrbuf* buffer)
|
||||
{
|
||||
optionCheckString(key, value, buffer);
|
||||
ffStrbufSetS(buffer, value);
|
||||
}
|
||||
|
||||
static void optionParseColor(const char* key, const char* value, FFstrbuf* buffer)
|
||||
{
|
||||
optionCheckString(key, value, buffer);
|
||||
|
||||
static const char reset[] = "reset_";
|
||||
static const char bright[] = "bright_";
|
||||
|
||||
static const char black[] = "black";
|
||||
static const char red[] = "red";
|
||||
static const char green[] = "green";
|
||||
static const char yellow[] = "yellow";
|
||||
static const char blue[] = "blue";
|
||||
static const char magenta[] = "magenta";
|
||||
static const char cyan[] = "cyan";
|
||||
static const char white[] = "white";
|
||||
|
||||
while(*value != '\0')
|
||||
{
|
||||
if(strncasecmp(value, reset, sizeof(reset) - 1) == 0)
|
||||
{
|
||||
ffStrbufAppendS(buffer, "0;");
|
||||
value += sizeof(reset) - 1;
|
||||
}
|
||||
else if(strncasecmp(value, bright, sizeof(bright) - 1) == 0)
|
||||
{
|
||||
ffStrbufAppendS(buffer, "1;");
|
||||
value += sizeof(bright) - 1;
|
||||
}
|
||||
else if(strncasecmp(value, black, sizeof(black) - 1) == 0)
|
||||
{
|
||||
ffStrbufAppendS(buffer, "30");
|
||||
value += sizeof(black) - 1;
|
||||
}
|
||||
else if(strncasecmp(value, red, sizeof(red) - 1) == 0)
|
||||
{
|
||||
ffStrbufAppendS(buffer, "31");
|
||||
value += sizeof(red) - 1;
|
||||
}
|
||||
else if(strncasecmp(value, green, sizeof(green) - 1) == 0)
|
||||
{
|
||||
ffStrbufAppendS(buffer, "32");
|
||||
value += sizeof(green) - 1;
|
||||
}
|
||||
else if(strncasecmp(value, yellow, sizeof(yellow) - 1) == 0)
|
||||
{
|
||||
ffStrbufAppendS(buffer, "33");
|
||||
value += sizeof(yellow) - 1;
|
||||
}
|
||||
else if(strncasecmp(value, blue, sizeof(blue) - 1) == 0)
|
||||
{
|
||||
ffStrbufAppendS(buffer, "34");
|
||||
value += sizeof(blue) - 1;
|
||||
}
|
||||
else if(strncasecmp(value, magenta, sizeof(magenta) - 1) == 0)
|
||||
{
|
||||
ffStrbufAppendS(buffer, "35");
|
||||
value += sizeof(magenta) - 1;
|
||||
}
|
||||
else if(strncasecmp(value, cyan, sizeof(cyan) - 1) == 0)
|
||||
{
|
||||
ffStrbufAppendS(buffer, "36");
|
||||
value += sizeof(cyan) - 1;
|
||||
}
|
||||
else if(strncasecmp(value, white, sizeof(white) - 1) == 0)
|
||||
{
|
||||
ffStrbufAppendS(buffer, "37");
|
||||
value += sizeof(white) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ffStrbufAppendC(buffer, *value);
|
||||
++value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void parseOption(FFinstance* instance, FFdata* data, const char* key, const char* value)
|
||||
{
|
||||
if(strcasecmp(key, "-h") == 0 || strcasecmp(key, "--help") == 0)
|
||||
@@ -642,7 +723,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else if(strcasecmp(key, "-s") == 0 || strcasecmp(key, "--separator") == 0)
|
||||
optionParseString(key, value, &instance->config.separator);
|
||||
else if(strcasecmp(key, "-c") == 0 || strcasecmp(key, "--color") == 0)
|
||||
optionParseString(key, value, &instance->config.color);
|
||||
optionParseColor(key, value, &instance->config.color);
|
||||
else if(strcasecmp(key, "--os-format") == 0)
|
||||
optionParseString(key, value, &instance->config.osFormat);
|
||||
else if(strcasecmp(key, "--os-key") == 0)
|
||||
@@ -785,7 +866,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
exit(472);
|
||||
}
|
||||
|
||||
optionParseString(key, value, &data->logoColors[index]);
|
||||
optionParseColor(key, value, &data->logoColors[index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user