From e38d5ca0d163b3e6f65daa65269f9ba910333bca Mon Sep 17 00:00:00 2001 From: Toni500git Date: Mon, 9 Sep 2024 22:26:33 +0200 Subject: [PATCH] gui: parse distro ascii art for getting auto colors instead of using always white --- Makefile | 2 -- include/parse.hpp | 2 +- src/display.cpp | 8 ++++---- src/gui.cpp | 12 +++++++++++- src/parse.cpp | 17 ++++++----------- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index d6377bb..6c4a8dd 100644 --- a/Makefile +++ b/Makefile @@ -50,8 +50,6 @@ CXXFLAGS += -fvisibility=hidden -Iinclude -std=c++20 $(VARS) -DVERSION=\" all: fmt toml $(TARGET) -recompile: clean all - fmt: ifeq ($(wildcard $(BUILDDIR)/fmt/libfmt.a),) mkdir -p $(BUILDDIR)/fmt diff --git a/include/parse.hpp b/include/parse.hpp index 40e2f3f..787ff29 100644 --- a/include/parse.hpp +++ b/include/parse.hpp @@ -15,7 +15,7 @@ * @param is_image If the source path is an image (used for GUI mode only) */ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::string& pureOutput, const Config& config, - const colors_t& colors, const bool parsingLayout, const bool is_image = false); + const colors_t& colors, const bool parsingLayout); /* Set module members values to a systemInfo_t map. * If the name of said module matches any module name, it will be added diff --git a/src/display.cpp b/src/display.cpp index da72881..7de3ffc 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -19,14 +19,14 @@ std::string Display::detect_distro(const Config& config) { debug("/etc/os-release = \n{}", shell_exec("cat /etc/os-release")); + const std::string& ascii_logo_type = (config.ascii_logo_type.empty() ? "" : "_" + config.ascii_logo_type); + if (!config.m_custom_distro.empty()) { - return fmt::format("{}/ascii/{}.txt", config.data_dir, config.m_custom_distro); + return fmt::format("{}/ascii/{}{}.txt", config.data_dir, config.m_custom_distro, ascii_logo_type); } else { - const std::string& ascii_logo_type = (config.ascii_logo_type.empty() ? "" : "_" + config.ascii_logo_type); - Query::System system; std::string format; @@ -50,7 +50,7 @@ std::vector Display::render(const Config& config, const colors_t& c if (!config.m_display_distro && !config.m_disable_source && !config.source_path.empty()) { - if (!config.m_custom_distro.empty()) + if (!config.m_custom_distro.empty() && !config.gui) die("You need to specify if either using a custom distro ascii art OR a custom source path"); } diff --git a/src/gui.cpp b/src/gui.cpp index 1779570..9c88a5f 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -34,6 +34,7 @@ using namespace GUI; // Display::render but only for images on GUI static std::vector render_with_image(const Config& config, const colors_t& colors) { + const std::string& path = Display::detect_distro(config); systemInfo_t systemInfo{}; std::vector layout{ config.layout }; @@ -46,10 +47,19 @@ static std::vector render_with_image(const Config& config, const co stbi_image_free(img); else die("Unable to load image '{}'", config.source_path); + + // this is just for parse() to auto add the distro colors + std::ifstream file(path, std::ios::binary); + std::string line; + while (std::getline(file, line)) + { + std::string _; + parse(line, systemInfo, _, config, colors, false); + } std::string _; for (std::string& layout : layout) - layout = parse(layout, systemInfo, _, config, colors, true, true); + layout = parse(layout, systemInfo, _, config, colors, true); // erase each element for each instance of MAGIC_LINE layout.erase(std::remove_if(layout.begin(), layout.end(), diff --git a/src/parse.cpp b/src/parse.cpp index 68522c3..2e2209e 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -145,7 +145,7 @@ std::string getInfoFromName(const systemInfo_t& systemInfo, const std::string_vi } std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::string& pureOutput, const Config& config, - const colors_t& colors, const bool parsingLayout, const bool is_image) + const colors_t& colors, const bool parsingLayout) { std::string output = input.data(); pureOutput = output; @@ -356,22 +356,17 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s if (hasStart(command, "auto")) { - std::uint8_t ver = - static_cast(command.length() > 4 ? std::stoi(command.substr(4)) - 1 : 0); + std::uint16_t ver = + static_cast(command.length() > 4 ? std::stoi(command.substr(4)) - 1 : 0); if (ver >= auto_colors.size() || ver < 1) ver = 0; if (auto_colors.empty()) { - if (is_image) - auto_colors.push_back(config.gui ? "white" : NOCOLOR_BOLD); + if (firstrun_noclr) + auto_colors.push_back(config.gui ? "" : NOCOLOR_BOLD); else - { - if (firstrun_noclr) - auto_colors.push_back(config.gui ? "" : NOCOLOR_BOLD); - else - auto_colors.push_back(config.gui ? "" : NOCOLOR_BOLD); - } + auto_colors.push_back(config.gui ? "" : NOCOLOR_BOLD); } command = auto_colors.at(ver);