Skip to content

Commit

Permalink
parse (ascii art): fully fix alignment and GUI mode with escaping in …
Browse files Browse the repository at this point in the history
…some ascii arts
  • Loading branch information
Toni500github committed Sep 14, 2024
1 parent 4363eb8 commit f928a24
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 46 deletions.
20 changes: 10 additions & 10 deletions assets/ascii/funtoo.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
${c1} .dKXXd .
:XXl;:. .OXo
.'OXO'' .''''''''''''''''''''':XNd..'oco.lco,
xXXXXXX, cXXXNNNXXXXNNXXXXXXXXNNNNKOOK; d0O .k
kXX xXo KNNN0 KNN. 'xXNo :c; 'cc.
kXX xNo KNNN0 KNN. :xxxx. 'NNo
kXX xNo loooc KNN. oNNNN. 'NNo
kXX xN0:. KNN' oNNNX' ,XNk
kXX xNNXNNNNNNNNXNNNNNNNNXNNOxXNX0Xl
... ......................... .;cc;.
${magenta} .dKXXd .
${magenta} :XXl;:. .OXo
${magenta}.'OXO'' .''''''''''''''''''''':XNd..'oco.lco,
${magenta}xXXXXXX, cXXXNNNXXXXNNXXXXXXXXNNNNKOOK; d0O .k
${magenta} kXX xXo KNNN0 KNN. 'xXNo :c; 'cc.
${magenta} kXX xNo KNNN0 KNN. :xxxx. 'NNo
${magenta} kXX xNo loooc KNN. oNNNN. 'NNo
${magenta} kXX xN0:. KNN' oNNNX' ,XNk
${magenta} kXX xNNXNNNNNNNNXNNNNNNNNXNNOxXNX0Xl
${magenta} ... ......................... .;cc;.
2 changes: 1 addition & 1 deletion src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c
if (config.gui)
{
// check parse.cpp
size_t pos = asciiArt_s.rfind("$ <");
const size_t pos = asciiArt_s.rfind("$ </");
if (pos != std::string::npos)
asciiArt_s.replace(pos, 2, "$");
}
Expand Down
7 changes: 4 additions & 3 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
#include "config.hpp"
#include "display.hpp"
#include "fmt/ranges.h"
#include "gdkmm/pixbufanimation.h"
#include "gtkmm/enums.h"
#include "pangomm/fontdescription.h"
#include "parse.hpp"
#include "query.hpp"
#include "stb_image.h"
#include "util.hpp"

#include "gdkmm/pixbufanimation.h"
#include "gtkmm/enums.h"
#include "pangomm/fontdescription.h"

using namespace GUI;

// https://www.codespeedy.com/convert-rgb-to-hex-color-code-in-cpp/
Expand Down
60 changes: 28 additions & 32 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,33 +150,49 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
std::string output = input.data();
pureOutput = output;

size_t dollarSignIndex = 0;
size_t dollarSignIndex = 0;
size_t oldDollarSignIndex = 0;
bool start = false;
bool start = false;

// we only use it in GUI mode,
// prevent issue where in the ascii art,
// theres at first either ${1} or ${0}
// and that's a problem with pango markup
bool firstrun_noclr = true;


static std::vector<std::string> auto_colors;

if (!config.sep_reset.empty() && parsingLayout)
{
if (config.sep_reset_after)
{
replace_str(output, config.sep_reset, config.sep_reset + "${0}");
replace_str(output, config.sep_reset, config.sep_reset + "${0}");
replace_str(pureOutput, config.sep_reset, config.sep_reset + "${0}");
}
else
{
replace_str(output, config.sep_reset, "${0}" + config.sep_reset);
replace_str(output, config.sep_reset, "${0}" + config.sep_reset);
replace_str(pureOutput, config.sep_reset, "${0}" + config.sep_reset);
}
}

// escape pango markup
// https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gmarkup.c#L2150
// workaround: just put "\<" or "\&" in the config, e.g "$<os.kernel> \<- Kernel"
if (config.gui)
{
replace_str(output, "\\<", "&lt;");
replace_str(output, "\\&", "&amp;");
}
else
{
replace_str(output, "\\<", "<");
replace_str(output, "\\&", "&");
}

replace_str(pureOutput, "\\<", "<");
replace_str(pureOutput, "\\&", "&");

while (true)
{
oldDollarSignIndex = dollarSignIndex;
Expand Down Expand Up @@ -356,8 +372,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s

if (hasStart(command, "auto"))
{
std::uint16_t ver =
static_cast<std::uint16_t>(command.length() > 4 ? std::stoi(command.substr(4)) - 1 : 0);
std::uint16_t ver = static_cast<std::uint16_t>(command.length() > 4 ? std::stoi(command.substr(4)) - 1 : 0);
if (ver >= auto_colors.size() || ver < 1)
ver = 0;

Expand Down Expand Up @@ -442,9 +457,9 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
const std::string_view color = clrs.at(0);
const std::string_view weight = clrs.at(1);
const std::string_view type = clrs.at(2);
output.replace(dollarSignIndex, output.length() - dollarSignIndex,
fmt::format("<span {}='{}' weight='{}'>{}</span>",
type, color, weight, output.substr(endBracketIndex + 1)));
output.replace( dollarSignIndex, output.length() - dollarSignIndex,
fmt::format("<span {}='{}' weight='{}'>{}</span>",
type, color, weight, output.substr(endBracketIndex + 1)));
}

else
Expand Down Expand Up @@ -524,27 +539,6 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
}
}

// https://github.com/dunst-project/dunst/issues/900
// pango markup doesn't like '<' if it's not a tag
// and doesn't like '&' too
// workaround: just put "\<" or "\&" in the config, e.g "$<os.kernel> \<- Kernel"
if (config.gui)
{
replace_str(output, "\\<", "&lt;");
replace_str(output, "\\&", "&amp;");
replace_str(output, "&amp;lt;", "&lt;");
replace_str(output, "&lt;span", "\\<span");
replace_str(output, "&lt;/span>", "\\</span>");
}
else
{
replace_str(output, "\\<", "<");
replace_str(output, "\\&", "&");
}

replace_str(pureOutput, "\\<", "<");
replace_str(pureOutput, "\\&", "&");

return output;
}

Expand Down Expand Up @@ -584,13 +578,15 @@ static std::string get_auto_gtk_format(const std::string_view gtk2, const std::s
else
return fmt::format("{} [GTK2], {} [GTK3], {} [GTK4]", gtk2, gtk3, gtk4);
}

else if (gtk3 != MAGIC_LINE && gtk4 != MAGIC_LINE)
{
if (gtk3 == gtk4)
return fmt::format("{} [GTK3/4]", gtk4);
else
return fmt::format("{} [GTK3], {} [GTK4]", gtk3, gtk4);
}

else if (gtk2 != MAGIC_LINE && gtk3 != MAGIC_LINE)
{
if (gtk2 == gtk3)
Expand Down Expand Up @@ -654,7 +650,7 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
const Config& config, const colors_t& colors, bool parsingLayout)
{
#define SYSINFO_INSERT(x) sysInfo[moduleName].insert({ moduleMemberName, variant(x) })
// yikes, here we go.

const auto& moduleMember_hash = fnv1a16::hash(moduleMemberName);
static std::vector<std::uint16_t> queried_gpus;
static std::vector<std::string_view> queried_disks;
Expand Down

0 comments on commit f928a24

Please sign in to comment.