Skip to content

Commit 220e812

Browse files
committed
misc: improve docs + more compile-time in pci.ids.hpp
also remove trailing newline when executing the command tag
1 parent 8eb92cf commit 220e812

File tree

5 files changed

+40
-61
lines changed

5 files changed

+40
-61
lines changed

include/pci.ids.hpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#if !CF_ANDROID
88

99
#include <array>
10-
#include <string>
10+
#include <string_view>
1111

12-
inline constexpr std::array<std::string_view, 2424> get_pci_vendors_array()
13-
{
14-
return {
12+
using namespace std::string_view_literals;
13+
14+
inline constexpr std::array<std::string_view, 2424> pci_vendors_array = {
1515
"0001", "0010", "0014", "0018", "001c", "003d", "0059", "0070", "0071", "0095", "00a7", "0100", "0123", "0128",
1616
"018a", "01de", "0200", "021b", "025e", "0270", "0291", "02ac", "02e0", "0303", "0308", "0315", "0357", "0432",
1717
"0497", "060e", "0675", "0709", "0721", "0731", "0777", "0795", "07d1", "0824", "0911", "0925", "0a89", "0b0b",
@@ -187,11 +187,8 @@ inline constexpr std::array<std::string_view, 2424> get_pci_vendors_array()
187187
"f111", "f117", "f15e", "f1d0", "f5f5", "f849", "fa57", "fab7", "fe19", "febd", "feda", "fede", "ffe1", "fffd",
188188
"fffe", "ffff"
189189
};
190-
}
191190

192-
inline constexpr std::array<int, 2424> get_pci_vendors_location_array()
193-
{
194-
return {
191+
inline constexpr std::array<int, 2424> pci_vendors_location_array = {
195192
842, 867, 965, 1987, 2075, 2240, 2340, 2380, 2442, 2472, 2624, 2650,
196193
2673, 2696, 2776, 2833, 3020, 3098, 3184, 4801, 4848, 4953, 5021, 5058,
197194
5099, 5149, 5180, 5255, 5345, 5372, 5415, 5557, 5632, 5653, 6374, 6404,
@@ -395,11 +392,8 @@ inline constexpr std::array<int, 2424> get_pci_vendors_location_array()
395392
1491995, 1492053, 1492083, 1493844, 1493884, 1493921, 1494051, 1494090, 1494135, 1494165, 1494271, 1494349,
396393
1495118, 1495199, 1495237, 1495291, 1495319, 1495387, 1495423, 1495512, 1495551, 1495649, 1495777, 1495829
397394
};
398-
}
399395

400-
inline std::string get_pci_ids()
401-
{
402-
return R"(#
396+
inline constexpr std::string_view all_ids = R"(#
403397
# List of PCI ID's
404398
#
405399
# Version: 2025.02.12
@@ -39890,16 +39884,11 @@ C 12 Processing accelerators
3989039884
C 13 Non-Essential Instrumentation
3989139885
C 40 Coprocessor
3989239886
C ff Unassigned class
39893-
)";
39894-
}
39895-
39896-
extern const std::string& all_ids;
39897-
inline constexpr std::array<std::string_view, 2424> pci_vendors_array = get_pci_vendors_array();
39898-
inline constexpr std::array<int, 2424> pci_vendors_location_array = get_pci_vendors_location_array();
39887+
)"sv;
3989939888

3990039889
#else
3990139890

39902-
extern const std::string& all_ids;
39891+
inline constexpr std::string_view all_ids = {};
3990339892
inline constexpr std::array<std::string_view, 2424> pci_vendors_array = {};
3990439893
inline constexpr std::array<int, 2424> pci_vendors_location_array = {};
3990539894

include/texts.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,22 @@ For details, see `man customfetch` or run `--how-it-works`.
164164
)");
165165

166166
constexpr std::string_view explain_customfetch = (R"(
167-
customfetch is designed for maximum customizability, allowing users to display system information exactly how they want it.
168-
The layout and logo is controlled through special tags that can output system info, execute commands, apply conditional logic, add colors, and calculate percentages with some colors.
167+
customfetch is designed for super customizability, allowing users to display fetched information the way they want.
168+
The layout and logo is controlled through special tags that can output fetched infos, execute commands, apply conditional logic, add colors, and calculate percentages with some colors.
169169
170170
Tag References:
171171
1. Information Tag ($<>)
172-
Retrieves system information from modules.
172+
Retrieves fetched information from modules.
173+
Information can be from installed plugins or builtin system-information fetching.
173174
174-
Syntax: $<module.submodule.sub...> or $<module>
175+
Syntax: $<module.submodule.recurisve..> or $<module>
175176
176177
Examples:
177-
- $<user.name> # Displays login username
178+
- $<user.name> # Shows login username
178179
- $<os.kernel.name> # Shows kernel name only
179180
- $<ram> # Shows formatted RAM usage
180181
181-
Use `--list-modules` to see all available modules and members.
182+
Use `--list-modules` to see all available modules and recursive submodules.
182183
183184
2. Bash Command Tag ($())
184185
Executes shell commands and outputs the result.
@@ -188,29 +189,28 @@ Tag References:
188189
189190
Examples:
190191
- $(echo "hello") # Outputs: hello
191-
- $(date +%F) # Shows current date
192192
- $(uname -r | cut -d'-' -f1) # Shows kernel version number only
193193
194194
3. Conditional Tag ($[])
195195
Displays different outputs based on conditions.
196196
197-
Syntax: $[condition,comparison,true_output,false_output]
197+
Syntax: $[something,something_else,if_equal,if_not_equal]
198198
199199
Examples:
200200
- $[$<user.name>,toni,Welcome back!,Access denied]
201201
- $[$(date +%m-%d),12-25,Merry Christmas!,]
202202
- $[$<os.name.id>,arch,${green}I use arch btw,${red}Non-arch user]
203203
204204
4. Color Tag (${})
205-
Applies colors and text formatting.
205+
Applies colors and text formatting for following text.
206206
207207
Basic syntax: ${color} or ${modifiers#RRGGBB}
208208
209209
Color options:
210-
- Named colors from config
210+
- Named colors from config (cyan, from alias-colors, ...)
211211
- Hex colors: ${#ff00cc}
212212
- Special colors: ${auto} (uses logo colors)
213-
- Reset styles: ${0} (normal), ${1} (bold reset)
213+
- Reset styles: ${0} (normal reset), ${1} (bold reset)
214214
215215
Formatting modifiers (prefix before hexcolor):
216216
- ! = Bold
@@ -232,18 +232,18 @@ Tag References:
232232
- w(value) = Font weight (light/normal/bold/ultrabold or 100-1000)
233233
234234
Examples:
235-
GUI App only:
235+
GUI App only:
236236
${oU(#ff0000)L(double)}Error # Double red underline
237237
${a(50%)#00ff00}Semi-transparent green
238-
Cross-platform:
238+
GUI and Terminal:
239239
${\e[1;33m}Bold yellow
240240
${b#222222}${white}White on gray
241241
${auto3}The 3rd logo color
242242
243243
Notes:
244-
- customfetch will try to convert ANSI escape codes to GUI app equivalent
245244
- customfetch will ignore GUI-specific modifiers on terminal.
246-
- if you're using the GUI app and want to display a custom logo that's an image, all the auto colors will be the same colors as the distro ones.
245+
- if you're using the GUI app and want to display a custom logo that's an image,
246+
all the ${auto} colors will be the same colors as the auto-detected distro ASCII art.
247247
248248
5. Percentage Tag ($%%)
249249
Calculates and displays colored percentages.
@@ -261,13 +261,13 @@ Pro Tip:
261261
262262
FAQ:
263263
Q: Why do special characters (&, <) break the GUI display?
264-
A: Escape these characters with \\ (e.g replace "<" with "\\<" from both config and ASCII art):
264+
A: Escape these characters with \\ (e.g replace "<" with "\\<"):
265265
This doesn't affect terminal output.
266266
267267
Q: How can I use cbonsai as ASCII art?
268268
A: 1. Create a text file containing: $(!cbonsai -p)
269269
2. Use: customfetch -s "/path/to/file.txt"
270-
3. Adjust offset for proper alignment
270+
3. Adjust offset for proper alignment (not dynamic)
271271
272272
Q: Does customfetch support nested tags?
273273
A: Yes! Complex nesting is supported, for example:

libcufetch/parse.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ std::optional<std::string> parse_command_tag(Parser& parser, parse_args_t& parse
402402
if (!parse_args.parsingLayout && !removetag && parser.dollar_pos != std::string::npos)
403403
parse_args.pureOutput.replace(parser.dollar_pos, command.length() + "$()"_len, cmd_output);
404404

405+
if (!cmd_output.empty() && cmd_output.back() == '\n')
406+
cmd_output.pop_back();
405407
return cmd_output;
406408
}
407409

scripts/generate_pci_arrays.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,29 @@
9696
f.write("""#ifndef _PCI_IDS_HPP
9797
#define _PCI_IDS_HPP
9898
99+
/* TODO: delete any subdevices (what the fuck man this REALLY needs a rewrite) */
100+
99101
#include "platform.hpp"
100102
#if !CF_ANDROID
101103
102104
#include <array>
103-
#include <string>
105+
#include <string_view>
104106
105-
inline constexpr std::array<std::string_view, %s> get_pci_vendors_array() {
106-
return %s;
107-
}
107+
using namespace std::string_view_literals;
108108
109-
inline constexpr std::array<int, %s> get_pci_vendors_location_array() {
110-
return %s;
111-
}
109+
inline constexpr std::array<std::string_view, %s> pci_vendors_array = %s;
112110
113-
inline std::string get_pci_ids() {
114-
return R"(%s)";
115-
}
111+
inline constexpr std::array<int, %s> pci_vendors_location_array = %s;
116112
117-
inline const std::string& all_ids = get_pci_ids();
118-
inline constexpr std::array<std::string_view, %s> pci_vendors_array = get_pci_vendors_array();
119-
inline constexpr std::array<int, %s> pci_vendors_location_array = get_pci_vendors_location_array();
113+
inline constexpr std::string_view all_ids = R"(%s)"sv;
120114
121115
#else
122116
123-
inline const std::string& all_ids = {}
124-
inline constexpr std::array<std::string_view, %s> pci_vendors_array = {}
125-
inline constexpr std::array<int, %s> pci_vendors_location_array = {}
117+
inline constexpr std::string_view all_ids = {};
118+
inline constexpr std::array<std::string_view, %s> pci_vendors_array = {};
119+
inline constexpr std::array<int, %s> pci_vendors_location_array = {};
126120
127-
#endif // !CF_ANDROID
121+
#endif // !CF_ANDROID
128122
129123
#endif // _PCI_IDS_HPP""" % (len(vendor_array), repr(vendor_array).replace("'", '"').replace('[', '{').replace(']', '}'), len(location_array), repr(location_array).replace("'", '"').replace('[', '{').replace(']', '}'), file, len(vendor_array), len(location_array)))
130124

src/util.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@
4848
#include "platform.hpp"
4949
#include "tiny-process-library/process.hpp"
5050

51-
#if !CF_ANDROID
52-
const std::string& all_ids = get_pci_ids();
53-
#else
54-
const std::string& all_ids = "";
55-
#endif
56-
5751
bool hasEnding(const std::string_view fullString, const std::string_view ending)
5852
{
5953
if (ending.length() > fullString.length())
@@ -480,7 +474,7 @@ std::string name_from_entry(size_t dev_entry_pos)
480474
{
481475
dev_entry_pos += 6; // Offset from the first character to the actual name that we want (xxxx <device name>)
482476

483-
std::string name = all_ids.substr(dev_entry_pos, all_ids.find('\n', dev_entry_pos) - dev_entry_pos);
477+
std::string name = std::string(all_ids.substr(dev_entry_pos, all_ids.find('\n', dev_entry_pos) - dev_entry_pos));
484478

485479
const size_t bracket_open_pos = name.find('[');
486480
const size_t bracket_close_pos = name.find(']');
@@ -496,7 +490,7 @@ std::string vendor_from_entry(const size_t vendor_entry_pos, const std::string_v
496490
if (end_line_pos == std::string::npos)
497491
end_line_pos = all_ids.length(); // If no newline is found, set to end of string
498492

499-
const std::string& line = all_ids.substr(vendor_entry_pos, end_line_pos - vendor_entry_pos);
493+
const std::string& line = std::string(all_ids.substr(vendor_entry_pos, end_line_pos - vendor_entry_pos));
500494

501495
const size_t after_id_pos = line.find(vendor_id_s) + 4;
502496
const std::string& description = line.substr(after_id_pos);

0 commit comments

Comments
 (0)