Skip to content

Commit 2c96c90

Browse files
committed
parse: add multiple color options in hexcodes colors
1 parent fc0c021 commit 2c96c90

File tree

6 files changed

+160
-115
lines changed

6 files changed

+160
-115
lines changed

cufetch.1

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,60 @@
11
.\" It was automatically generated by help2man 1.49.3 at the beggining
22
.TH CUSTOMFETCH "1" "August 2024" "customfetch @VERSION@ branch @BRANCH@" "User Commands"
33
.SH NAME
4-
customfetch \- A command\-line and GUI system information tool (or neofetch like program), which its focus point is customizability and perfomance
4+
customfetch \- A command\-line and GUI system information tool (or neofetch like program)
55
.SH SYNOPSIS
66
.B cufetch
77
[\fI\,OPTION\/\fR]...
8+
.SH CONFIGURATION
9+
customfetch focus point is to be customizable and fast at the same time.
10+
.PP
11+
How does it work?
12+
.PP
13+
We got the config.toml file, in there we got an array variable called "layout". That's the variable where you customize how the infos should be displayed.
14+
.br
15+
You have 3 components: $<module.submod>, ${color}, $(bash command). They can be used in the ascii art text file and layout, but how to use them?
16+
.PP
17+
Here's a simple bare-minimal example:
18+
.br
19+
layout = [
20+
.br
21+
"My OS is $<os.name>, and username is $<user.name>",
22+
.br
23+
"The color of the following text will be ${red}red",
24+
.br
25+
"And this is a $(echo \\"bash command\\")"
26+
.br
27+
]
28+
.PP
29+
The \fBInfo component $<>\fR let's you print a part of a module. All the modules and their parts are listed in the `--list-modules` argument
30+
.PP
31+
The \fBColor component ${}\fR is used for printing the text of a certain color.
32+
.br
33+
The colors can be: \fIblack\fR, \fIred\fR, \fIgreen\fR, \fIblue\fR, \fIcyan\fR, \fIyellow\fR, \fImagenta\fR, \fIwhite\fR and they can be configured in the config file.
34+
.br
35+
They can have hexcodes colors, e.g "#5522dd".
36+
.br
37+
It's possible to enable multiple options, put these symbols before '#':
38+
.br
39+
* \fBb\fR for making the color in the background
40+
.br
41+
* \fBu\fR for underline the text
42+
.br
43+
* \fB!\fR for making the text bold
44+
.br
45+
* \fBi\fR for making the text italic
46+
47+
OR They can have ANSI escape codes, e.g "\\e[1;31m" and "\\e[38;5;160m" (\fBNOTE\fR: 256 colors ANSI escape codes, those that have \\e[38 or \\e[48, can't be used in GUI)
48+
.br
49+
You can also use them inside the component, like ${!#343345} or ${\\e[1;31m}.
50+
.PP
51+
To reset colors use ${0} or ${1} for reset and bold text.
52+
.br
53+
To instead use the colors that the ascii art logo uses, use ${auto} for getting the 1st color, ${auto4} for the 4th one and so on.
54+
.PP
55+
The \fBBash command component $()\fR speaks for itself. It can execute normal bash commands.
56+
.PP
57+
To escape any $ or bracket, just use \\
858
.SH OPTIONS
959
.TP
1060
\fB\-n\fR, \fB\-\-no\-display\fR
@@ -82,46 +132,6 @@ Syntax MUST be "name=value" with no space beetween "=", example: --color "foo=#4
82132
Thus replaces any instance of foo with #444333. Can be done with multiple colors separetly.
83133
.br
84134
Matter of fact, you can: --color "#hexcode=#anotherhexcode"
85-
.SH CONFIGURATION
86-
customfetch is a command\-line and GUI system information tool (or "neofetch like program"). It's focus point is being customizable and fast at the same time.
87-
.PP
88-
How does it work?
89-
.PP
90-
We got the config.toml file, in there we got an array variable called "layout". That's the variable where you customize how the infos should be displayed.
91-
.br
92-
You have 3 components: $<module.submod>, ${color}, $(bash command). They can be used in the ascii art text file and layout, but how to use them?
93-
.PP
94-
Here's a simple bare-minimal example:
95-
.br
96-
layout = [
97-
.br
98-
"My OS is $<os.name>, and username is $<user.name>",
99-
.br
100-
"The color of the following text will be ${red}red",
101-
.br
102-
"And this is a $(echo \\"bash command\\")"
103-
.br
104-
]
105-
.PP
106-
The \fBInfo component $<>\fR let's you print a part of a module. All the modules and their parts are listed in the `--list-modules` argument
107-
.PP
108-
The \fBColor component ${}\fR is used for printing the text of a certain color.
109-
.br
110-
The colors can be: \fIblack\fR, \fIred\fR, \fIgreen\fR, \fIblue\fR, \fIcyan\fR, \fIyellow\fR, \fImagenta\fR, \fIwhite\fR and they can be configured in the config file.
111-
.br
112-
These can have hexcodes colors, e.g "#5522dd" or "!#888eed" for bold color text
113-
.br
114-
OR They can have ANSI escape codes, e.g "\\e[1;31m" and "\\e[38;5;160m" (\fBNOTE\fR: 256 colors ANSI escape codes, those that have \\e[38 or \\e[48, can't be used in GUI)
115-
.br
116-
You can also use them inside the component, like ${!#343345} or ${\\e[1;31m}.
117-
.PP
118-
To reset colors use ${0} or ${1} for reset and bold text.
119-
.br
120-
To instead use the colors that the ascii art logo uses, use ${auto} for getting the 1st color, ${auto4} for the 4th one and so on.
121-
.PP
122-
The \fBBash command component $()\fR speaks for itself. It can execute normal bash commands.
123-
.PP
124-
To escape any $ or bracket, just use \\
125135
.SH BUGS
126136
\fR
127137
Report any bugs to \fIhttps://github.com/Toni500github/customfetch/issues\fR

include/config.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Config
7272
std::string getThemeValue(const std::string& value, const std::string& fallback) const;
7373
void generateConfig(const std::string_view filename);
7474

75-
std::vector<std::string> getValueArrayStr(const std::string& value, const std::vector<std::string>& fallback);
75+
std::vector<std::string> getValueArrayStr(const std::string_view value, const std::vector<std::string>& fallback);
7676

7777
template <typename T>
7878
T getValue(const std::string& value, const T&& fallback) const
@@ -106,7 +106,14 @@ inline constexpr std::string_view AUTOCONFIG = R"#([config]
106106
107107
# ${} is used for which color to use for colorizing the text
108108
# e.g "${red}hello world" will indeed print "hello world" in red (or the color you set in the variable)
109-
# you can even put a custom hex color e.g: ${#ff6622} (for bold text put ! before # e.g ${!#ff6622} )
109+
# you can even put a custom hex color e.g: ${#ff6622}
110+
#
111+
# It's possible to enable multiple options, put these symbols before '#':
112+
# * b, for making the color in the background
113+
# * u, for underline the text
114+
# * !, for making the text bold
115+
# * i, for making the text italic
116+
#
110117
# OR bash escape code colors e.g ${\e[1;32m} or ${\e[0;34m}.
111118
# For auto coloring, depending on the ascii logo colors, use ${auto}.
112119
# They can be used for different colors too. So for getting the 2nd color of the ascii logo,

include/parse.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
1818

1919
std::string getInfoFromName(const systemInfo_t& systemInfo, const std::string_view moduleName,
2020
const std::string_view moduleValueName);
21+
22+
// Function to combine multiple fmt::text_style arguments
23+
template <typename... Styles>
24+
void append_styles(fmt::text_style& current_style, Styles&&... styles)
25+
{
26+
current_style = current_style | (styles | ...);
27+
}
28+
2129
#endif

src/config.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void Config::loadConfigFile(const std::string_view filename, colors_t& colors)
3838

3939
// clang-format off
4040
// Idk but with `this->` looks more readable
41-
this->layout = this->getValueArrayStr("config.layout", {});
41+
this->layout = this->getValueArrayStr("config.layout", {});
4242
this->gui = this->getValue<bool>("gui.enable", false);
4343
this->ascii_logo_type = this->getValue<std::string>("config.ascii-logo-type", "");
4444
this->source_path = this->getValue<std::string>("config.source-path", "os");
@@ -90,20 +90,21 @@ std::string Config::getThemeValue(const std::string& value, const std::string& f
9090
return this->tbl.at_path(value).value<std::string>().value_or(fallback);
9191
}
9292

93-
std::vector<std::string> Config::getValueArrayStr(const std::string& value, const std::vector<std::string>& fallback)
93+
std::vector<std::string> Config::getValueArrayStr(const std::string_view value,
94+
const std::vector<std::string>& fallback)
9495
{
9596
std::vector<std::string> ret;
9697

9798
// https://stackoverflow.com/a/78266628
9899
const auto& array = tbl.at_path(value);
99-
if (toml::array* array_it = array.as_array())
100+
if (const toml::array* array_it = array.as_array())
100101
{
101102
array_it->for_each(
102-
[&ret, value](auto&& el)
103+
[&](auto&& el)
103104
{
104-
if (toml::value<std::string>* str_elem = el.as_string())
105+
if (const toml::value<std::string>* str_elem = el.as_string())
105106
{
106-
toml::value<std::string> v = *str_elem;
107+
const toml::value<std::string>& v = *str_elem;
107108
ret.push_back(v->data());
108109
}
109110
else

src/display.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@
1919
std::string Display::detect_distro(const Config& config)
2020
{
2121
debug("/etc/os-release = \n{}", shell_exec("cat /etc/os-release"));
22+
2223
if (!config.m_custom_distro.empty())
2324
{
2425
return fmt::format("{}/ascii/{}.txt", config.data_dir, config.m_custom_distro);
2526
}
2627
else
2728
{
29+
const std::string& ascii_logo_type = (config.ascii_logo_type.empty() ? "" : "_" + config.ascii_logo_type);
30+
2831
Query::System system;
2932
std::string format;
3033

31-
format = fmt::format("{}/ascii/{}.txt", config.data_dir, str_tolower(system.os_id()) + (config.ascii_logo_type.empty() ? "" : "_" + config.ascii_logo_type));
34+
format = fmt::format("{}/ascii/{}.txt", config.data_dir, str_tolower(system.os_id()) + ascii_logo_type);
3235
if (std::filesystem::exists(format))
3336
return format;
3437

35-
format = fmt::format("{}/ascii/{}.txt", config.data_dir, str_tolower(system.os_name()) + (config.ascii_logo_type.empty() ? "" : "_" + config.ascii_logo_type));
38+
format = fmt::format("{}/ascii/{}.txt", config.data_dir, str_tolower(system.os_name()) + ascii_logo_type);
3639
if (std::filesystem::exists(format))
3740
return format;
3841

0 commit comments

Comments
 (0)