diff --git a/include/config.hpp b/include/config.hpp index 46fac6f..be8f4bc 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -288,7 +288,7 @@ flatpak-dirs = ["/var/lib/flatpak/app/", "~/.local/share/flatpak/app/"] apk-files = ["/var/lib/apk/db/installed"] # GUI options -# note: customfetch needs to be compiled with GUI_MODE=1 (check with "cufetch --version") +# note: customfetch needs to be compiled with GUI_MODE=1 (check with "cufetch --version" if GUI mode was enabled) [gui] enable = false diff --git a/include/parse.hpp b/include/parse.hpp index 929d146..7bb8b01 100644 --- a/include/parse.hpp +++ b/include/parse.hpp @@ -33,12 +33,9 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s /* Set module members values to a systemInfo_t map. * If the name of said module matches any module name, it will be added * else, error out. - * @param sysInfo The systemInfo_t map * @param moduleName The module name * @param moduleMemberName The module member name - * @param config The config - * @param colors The colors - * @param parsingLayout If we are parsing the layout or not (default true) + * @param parse_args The parse() like arguments */ void addValueFromModule(const std::string& moduleName, const std::string& moduleMemberName, parse_args_t& parse_args); @@ -53,7 +50,7 @@ std::string getInfoFromName(const systemInfo_t& systemInfo, const std::string_vi template void append_styles(fmt::text_style& current_style, Styles&&... styles) { - current_style = current_style | (styles | ...); + current_style |= (styles | ...); } diff --git a/src/display.cpp b/src/display.cpp index b6d82f7..7afda43 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -50,12 +50,10 @@ std::string Display::detect_distro(const Config& config) } } -static std::vector render_with_image(systemInfo_t& systemInfo, const Config& config, const colors_t& colors, - const std::string_view path, const std::uint16_t font_width, - const std::uint16_t font_height) +static std::vector render_with_image(systemInfo_t& systemInfo, std::vector& layout, + const Config& config, const colors_t& colors, const std::string_view path, + const std::uint16_t font_width, const std::uint16_t font_height) { - std::vector layout{ config.layout }; - int image_width, image_height, channels; // load the image and get its width and height @@ -211,7 +209,7 @@ std::vector Display::render(const Config& config, const colors_t& c get_pos(y, x); fmt::print("\033[{};{}H", y, x); - return render_with_image(systemInfo, config, colors, path, font_width, font_height); + return render_with_image(systemInfo, layout, config, colors, path, font_width, font_height); } } diff --git a/src/main.cpp b/src/main.cpp index 0a4f07b..d014e09 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -173,7 +173,7 @@ theme-gtk-all # example: if you want to show your 512MiB of used RAM in GiB # use the `used-GiB` variant (they don't print the unit tho) ram - ram : used and total amount of RAM (auto) [2.81 GiB / 15.88 GiB] + ram : used and total amount of RAM (auto) with used percentage [2.81 GiB / 15.88 GiB (5.34%)] used : used amount of RAM (auto) [2.81 GiB] free : available amount of RAM (auto) [10.46 GiB] total : total amount of RAM (auto) [15.88 GiB] @@ -182,7 +182,7 @@ ram # same comments as RAM (above) swap - swap : used and total amount of the swapfile (auto) [477.68 MiB / 512.00 MiB] + swap : used and total amount of the swapfile (auto) with used percentage [477.68 MiB / 512.00 MiB (88.45%)] free : available amount of the swapfile (auto) [34.32 MiB] total : total amount of the swapfile (auto) [512.00 MiB] used : used amount of the swapfile (auto) [477.68 MiB] @@ -194,7 +194,7 @@ swap # or a filesystem path # e.g disk(/) or disk(/dev/sda5) disk(/path/to/fs) - disk : used and total amount of disk space (auto) with type of filesystem [360.02 GiB / 438.08 GiB - ext4] + disk : used and total amount of disk space (auto) with type of filesystem and used percentage [379.83 GiB / 438.08 GiB (86.70%) - ext4] used : used amount of disk space (auto) [360.02 GiB] free : available amount of disk space (auto) [438.08 GiB] total : total amount of disk space (auto) [100.08 GiB] diff --git a/src/parse.cpp b/src/parse.cpp index c4ec85a..27dfa9a 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -125,6 +125,20 @@ static std::string parse(const std::string_view input, std::string& _, parse_arg return parse(input, parse_args.systemInfo, _, parse_args.config, parse_args.colors, parse_args.parsingLayout); } +static char gettype(const char opentag) +{ + switch (opentag) + { + case '(': return ')'; + case '<': return '>'; + case '%': return '%'; + case '[': return ']'; + case '{': return '}'; + } + + return ' '; // neither of them +} + static std::string get_and_color_percentage(const float& n1, const float& n2, parse_args_t& parse_args, const bool invert = false) { @@ -236,7 +250,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s retry: if (dollarSignIndex == std::string::npos) break; - + // small workaround cuz idk how to fix this else if (dollarSignIndex <= oldDollarSignIndex && start && !config.m_disable_colors) { dollarSignIndex = output.find('$', dollarSignIndex + 1); @@ -254,7 +268,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s if (skip_bypass) { if (dollarSignIndex > 0 and - (output[dollarSignIndex - 1] == '\\' and (dollarSignIndex == 1 or output[dollarSignIndex - 2] != '\\'))) + (output.at(dollarSignIndex - 1) == '\\' and (dollarSignIndex == 1 or output.at(dollarSignIndex - 2) != '\\'))) { skip_bypass = false; continue; @@ -279,27 +293,41 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s command.reserve(256); // should be enough for not allocating over and over size_t endBracketIndex = -1; - char type = ' '; // ' ' = undefined, ')' = shell exec, 2 = ')' asking for a module const char opentag = output.at(dollarSignIndex + 1); - - switch (opentag) - { - case '(': type = ')'; break; - case '<': type = '>'; break; - case '%': type = '%'; break; - case '[': type = ']'; break; - case '{': type = '}'; break; - default: // neither of them - break; - } - + + const char type = gettype(opentag); // ' ' = undefined, ')' = shell exec, 2 = ')' asking for a module if (type == ' ') continue; + // if we get a tag inside a tag, then let's skip until we skipped the subtag + // entirely + size_t skip_lenght = 0; + // let's get what's inside the brackets for (size_t i = dollarSignIndex + 2; i < output.size(); i++) { - if (output.at(i) == type && output.at(i - 1) != '\\') + if (skip_lenght > 0) + { + skip_lenght--; + continue; + } + + if (output.at(i) == '$') + { + const char type = gettype(output.at(i + 1)); + if (type != ' ') + { + const size_t pos = output.find(type, i); + if (pos == output.npos) + die("PARSER: Opened tag is not closed at index {} in string {}", dollarSignIndex, output); + + const size_t len = (pos + 1) - i; + command += parse(output.substr(i, len), _, parse_args); + skip_lenght = len - 1; + continue; + } + } + else if (output.at(i) == type && output.at(i - 1) != '\\') { endBracketIndex = i; break; @@ -1171,8 +1199,8 @@ void addValueFromModule(const std::string& moduleName, const std::string& module { switch (moduleMember_hash) { - case "name"_fnv1a16: SYSINFO_INSERT(query_gpu.name()); break; - case "vendor"_fnv1a16: SYSINFO_INSERT(shorten_vendor_name(query_gpu.vendor())); break; + case "name"_fnv1a16: SYSINFO_INSERT(query_gpu.name()); break; + case "vendor"_fnv1a16: SYSINFO_INSERT(shorten_vendor_name(query_gpu.vendor())); break; case "vendor_long"_fnv1a16: SYSINFO_INSERT(query_gpu.vendor()); break; } }