Skip to content

Commit 9c636cc

Browse files
committed
parse: fix ASCII arts that has commands such as cbonsai
1 parent f928a24 commit 9c636cc

File tree

7 files changed

+61
-15
lines changed

7 files changed

+61
-15
lines changed

assets/config-examples/config_cool.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@
4949
# without quotes ofc
5050

5151
# Little FAQ
52-
# Q: "Why when I use something like "$<os.kernel> <- Kernel" it won't work on GUI mode?"
53-
# A: replace "<-" with "\\<-". It won't affect the printing in terminal
52+
# Q: Why when I use & or < in the config or ASCII art, it won't work on GUI mode?
53+
# A: replace "<" with "\\<" in the config, or "\<" in the ascii art. Same goes for &
54+
# It won't affect the printing in terminal
55+
56+
# Q: I want to use `cbonsai` as ASCII art, how do I use it?
57+
# A: First off, create a text file and there put only `$(!cbonsai -p)`
58+
# Save the file and use `-s "/path/to/text/file"`.
59+
# Use `--offset` (`-o`) for aligning and put it under the bonsai.
60+
#
61+
# Read the manual cufetch.1 for more infos with $() tag
62+
5463

5564
# Old pipelines screensavers inspired layout
5665
# This is really system depedent and really meassy

assets/config-examples/config_simple.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@
4949
# without quotes ofc
5050

5151
# Little FAQ
52-
# Q: "Why when I use something like "$<os.kernel> <- Kernel" it won't work on GUI mode?"
53-
# A: replace "<-" with "\\<-". It won't affect the printing in terminal
52+
# Q: Why when I use & or < in the config or ASCII art, it won't work on GUI mode?
53+
# A: replace "<" with "\\<" in the config, or "\<" in the ascii art. Same goes for &
54+
# It won't affect the printing in terminal
55+
56+
# Q: I want to use `cbonsai` as ASCII art, how do I use it?
57+
# A: First off, create a text file and there put only `$(!cbonsai -p)`
58+
# Save the file and use `-s "/path/to/text/file"`.
59+
# Use `--offset` (`-o`) for aligning and put it under the bonsai.
60+
#
61+
# Read the manual cufetch.1 for more infos with $() tag
62+
5463

5564
layout = [
5665
"${1}┌────────── Hardware Information ──────────┐",

assets/config-examples/nitch_like_config.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@
4949
# without quotes ofc
5050

5151
# Little FAQ
52-
# Q: "Why when I use something like "$<os.kernel> <- Kernel" it won't work on GUI mode?"
53-
# A: replace "<-" with "\\<-". It won't affect the printing in terminal
52+
# Q: Why when I use & or < in the config or ASCII art, it won't work on GUI mode?
53+
# A: replace "<" with "\\<" in the config, or "\<" in the ascii art. Same goes for &
54+
# It won't affect the printing in terminal
55+
56+
# Q: I want to use `cbonsai` as ASCII art, how do I use it?
57+
# A: First off, create a text file and there put only `$(!cbonsai -p)`
58+
# Save the file and use `-s "/path/to/text/file"`.
59+
# Use `--offset` (`-o`) for aligning and put it under the bonsai.
60+
#
61+
# Read the manual cufetch.1 for more infos with $() tag
62+
5463

5564
# Inspired by nitch default config
5665
# and this reddit post https://www.reddit.com/r/unixporn/comments/1eedqnm/gnome_clean_daily_driver/

cufetch.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ layout = [
8585
* The \fBBash command tag $()\fR speaks for itself.
8686
.br
8787
It can execute normal bash commands and print the output of it.
88+
.PP
89+
\fBNOTE:\fR if you try to use programs such as cbonsai in an ASCII art, put a '!' before the command.
90+
.br
91+
example: $(!cbonsai -p)
8892
.PP
8993
* The \fBPercentage tag $%%\fR is used for displaying the percentage between 2 numbers.
9094
.br

include/config.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,16 @@ inline constexpr std::string_view AUTOCONFIG = R"#([config]
140140
# without quotes ofc
141141
142142
# Little FAQ
143-
# Q: Why when I use something like "$<os.kernel> <- Kernel" it won't work on GUI mode?
144-
# A: replace "<-" with "\\<-" in the config, or "\<-" in the ascii art. It won't affect the printing in terminal
145-
146-
# Q: It happens with '&' too, like "Yin & yang"
147-
# A: do the same as above explained, "\\&" in the config, or "\&" in the ascii art.
143+
# Q: Why when I use & or < in the config or ASCII art, it won't work on GUI mode?
144+
# A: replace "<" with "\\<" in the config, or "\<" in the ascii art. Same goes for &
145+
# It won't affect the printing in terminal
146+
147+
# Q: I want to use `cbonsai` as ASCII art, how do I use it?
148+
# A: First off, create a text file and there put only `$(!cbonsai -p)`
149+
# Save the file and use `-s "/path/to/text/file"`.
150+
# Use `--offset` (`-o`) for aligning and put it under the bonsai.
151+
#
152+
# Read the manual cufetch.1 for more infos with $() tag
148153
149154
layout = [
150155
"$<builtin.title>",

src/display.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c
5555
debug("path = {}", path);
5656

5757
std::ifstream file;
58+
std::ifstream fileToAnalyze; // both have same path
5859
if (!config.m_disable_source)
5960
{
6061
file.open(path.data(), std::ios::binary);
61-
if (!file.is_open())
62+
fileToAnalyze.open(path.data(), std::ios::binary);
63+
if (!file.is_open() || !fileToAnalyze.is_open())
6264
die("Could not open ascii art file \"{}\"", path);
6365
}
6466

@@ -73,12 +75,11 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c
7375
{
7476
debug("Display::render() analyzing file");
7577
std::array<unsigned char, 16> buffer;
76-
file.read(reinterpret_cast<char*>(&buffer.at(0)), buffer.size());
78+
fileToAnalyze.read(reinterpret_cast<char*>(&buffer.at(0)), buffer.size());
7779
if (is_file_image(buffer.data()))
7880
die("The source file '{}' is a binary file.\n"
7981
"Please currently use the GUI mode for rendering the image/gif (use -h for more details)",
8082
path);
81-
file.seekg(0);
8283
}
8384

8485
for (int i = 0; i < config.logo_padding_top; i++)

src/parse.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,20 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
265265
{
266266
case ')':
267267
{
268+
const bool removetag = (command.front() == '!');
269+
if (removetag)
270+
command.erase(0,1);
271+
268272
const std::string& shell_cmd = shell_exec(command);
269273
output.replace(dollarSignIndex, taglen, shell_cmd);
270274

271275
if (!parsingLayout && tagpos != std::string::npos)
272-
pureOutput.replace(tagpos, taglen, shell_cmd);
276+
{
277+
if (!removetag)
278+
pureOutput.replace(tagpos, taglen, shell_cmd);
279+
else
280+
pureOutput.erase(tagpos, taglen);
281+
}
273282

274283
} break;
275284

0 commit comments

Comments
 (0)