From fd9fa700ee73185daa68d6a1388c758e214541d0 Mon Sep 17 00:00:00 2001 From: Toni500git Date: Fri, 30 Aug 2024 12:32:00 +0200 Subject: [PATCH] misc: update configs + some code renames --- assets/config-examples/config_cool.toml | 33 ++++++++++-- assets/config-examples/config_modified.toml | 51 ++++++++++++++----- assets/config-examples/config_simple.toml | 31 +++++++++-- assets/config-examples/nitch_like_config.toml | 19 +++++-- include/config.hpp | 24 ++++----- src/config.cpp | 2 +- src/display.cpp | 24 ++++----- src/gui.cpp | 14 ++--- src/main.cpp | 7 +-- 9 files changed, 147 insertions(+), 58 deletions(-) diff --git a/assets/config-examples/config_cool.toml b/assets/config-examples/config_cool.toml index a8a62bc..0867175 100644 --- a/assets/config-examples/config_cool.toml +++ b/assets/config-examples/config_cool.toml @@ -74,17 +74,32 @@ source-path = "os" # note: it MUST contain an "ascii" subdirectory data-dir = "/usr/share/customfetch" -# A separetor (string) that when ecountered, will automatically +# The type of ASCII art to apply ("small", "old"). +# Basically will add "_" to the logo filename. +# It will return the regular linux ascii art if it doesn't exist. +# Leave empty it for regular. +ascii-logo-type = "" + +# A char (or string) to use in $ +sep-title = "-" + +# A separetor (or string) that when ecountered, will automatically # reset color, aka. automatically add ${0} (only in layout) # Make it empty for disabling sep-reset = ":" -# Offset between the ascii art and the system infos +# Offset between the ascii art and the layout offset = 5 -# Padding of the logo from the top +# Padding between the start and the ascii art +logo-padding-left = 0 + +# Padding of the ascii art from the top logo-padding-top = 0 +# Padding of the layout from the top +layout-padding-top = 0 + # Colors can be with: hexcodes (#55ff88) and for bold put '!' (!#55ff88) # OR ANSI escape code colors like "\e[1;34m" # remember to add ${0} where you want to reset color @@ -110,13 +125,23 @@ secs = " seconds" [os.pkgs] # Ordered list of which packages installed count should be displayed in $ # remember to not enter the same name twice, else the world will finish -# Choices: pacman, flatpak, dpkg +# Choices: pacman, flatpak, dpkg, apk # # Pro-tip: if your package manager isnt listed here, yet, # use the bash command component in the layout # e.g "Packages: $(pacman -Q | wc -l) (pacman)" pkg-managers = ["pacman", "dpkg", "flatpak"] +# Distros and package manager specific +# package manager paths for getting the packages count from path. +# They are arrayies so you can add multiple paths. +# +# If you don't know what these ares, leave them by default settings +pacman-dirs = ["/var/lib/pacman/local/"] +dpkg-files = ["/var/lib/dpkg/status"] +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") [gui] diff --git a/assets/config-examples/config_modified.toml b/assets/config-examples/config_modified.toml index 55b3d35..334695b 100644 --- a/assets/config-examples/config_modified.toml +++ b/assets/config-examples/config_modified.toml @@ -61,37 +61,52 @@ source-path = "os" # note: it MUST contain an "ascii" subdirectory data-dir = "/usr/share/customfetch" -# A separetor (string) that when ecountered, will automatically +# The type of ASCII art to apply ("small", "old"). +# Basically will add "_" to the logo filename. +# It will return the regular linux ascii art if it doesn't exist. +# Leave empty it for regular. +ascii-logo-type = "" + +# A char (or string) to use in $ +sep-title = "-" + +# A separetor (or string) that when ecountered, will automatically # reset color, aka. automatically add ${0} (only in layout) # Make it empty for disabling sep-reset = ":" -# Offset between the ascii art and the system infos +# Offset between the ascii art and the layout offset = 5 -# Padding of the logo from the top +# Padding between the start and the ascii art +logo-padding-left = 0 + +# Padding of the ascii art from the top logo-padding-top = 0 +# Padding of the layout from the top +layout-padding-top = 0 + # Colors can be with: hexcodes (#55ff88) and for bold put '!' (!#55ff88) # OR ANSI escape code colors like "\e[1;34m" # remember to add ${0} where you want to reset color -black = "\e[1;30m" -red = "\e[1;31m" -green = "\e[1;32m" -yellow = "\e[1;33m" -blue = "\e[1;34m" +black = "\e[1;30m" +red = "\e[1;31m" +green = "\e[1;32m" +yellow = "\e[1;33m" +blue = "\e[1;34m" magenta = "\e[1;35m" -cyan = "\e[1;36m" -white = "\e[1;37m" +cyan = "\e[1;36m" +white = "\e[1;37m" # $ config [os.uptime] # how to display the name of the uptime # e.g: hours = "hrs" -> "Uptime: 3hrs" -days = " days" +days = " days" hours = " hours" -mins = " mins" -secs = " seconds" +mins = " mins" +secs = " seconds" # $ config [os.pkgs] @@ -104,6 +119,16 @@ secs = " seconds" # e.g "Packages: $(pacman -Q | wc -l) (pacman)" pkg-managers = ["pacman", "dpkg", "flatpak"] +# Distros and package manager specific +# package manager paths for getting the packages count from path. +# They are arrayies so you can add multiple paths. +# +# If you don't know what these ares, leave them by default settings +pacman-dirs = ["/var/lib/pacman/local/"] +dpkg-files = ["/var/lib/dpkg/status"] +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 (which is enabled by default) [gui] diff --git a/assets/config-examples/config_simple.toml b/assets/config-examples/config_simple.toml index 0be396a..8a69181 100644 --- a/assets/config-examples/config_simple.toml +++ b/assets/config-examples/config_simple.toml @@ -52,17 +52,32 @@ source-path = "os" # note: it MUST contain an "ascii" subdirectory data-dir = "/usr/share/customfetch" -# A separetor (string) that when ecountered, will automatically +# The type of ASCII art to apply ("small", "old"). +# Basically will add "_" to the logo filename. +# It will return the regular linux ascii art if it doesn't exist. +# Leave empty it for regular. +ascii-logo-type = "" + +# A char (or string) to use in $ +sep-title = "-" + +# A separetor (or string) that when ecountered, will automatically # reset color, aka. automatically add ${0} (only in layout) # Make it empty for disabling sep-reset = ":" -# Offset between the ascii art and the system infos +# Offset between the ascii art and the layout offset = 5 -# Padding of the logo from the top +# Padding between the start and the ascii art +logo-padding-left = 0 + +# Padding of the ascii art from the top logo-padding-top = 0 +# Padding of the layout from the top +layout-padding-top = 0 + # Colors can be with: hexcodes (#55ff88) and for bold put '!' (!#55ff88) # OR ANSI escape code colors like "\e[1;34m" # remember to add ${0} where you want to reset color @@ -95,6 +110,16 @@ secs = " seconds" # e.g "Packages: $(pacman -Q | wc -l) (pacman)" pkg-managers = ["pacman", "dpkg", "flatpak"] +# Distros and package manager specific +# package manager paths for getting the packages count from path. +# They are arrayies so you can add multiple paths. +# +# If you don't know what these ares, leave them by default settings +pacman-dirs = ["/var/lib/pacman/local/"] +dpkg-files = ["/var/lib/dpkg/status"] +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 (which is enabled by default) [gui] diff --git a/assets/config-examples/nitch_like_config.toml b/assets/config-examples/nitch_like_config.toml index cfab75a..ec61317 100644 --- a/assets/config-examples/nitch_like_config.toml +++ b/assets/config-examples/nitch_like_config.toml @@ -71,12 +71,15 @@ sep-reset = ":" # Offset between the ascii art and the system infos offset = 3 -# Offset between the start and the ascii art -pre-logo-offset = 3 +# Padding between the start and the ascii art +logo-padding-left = 3 -# Padding of the logo from the top +# Padding of the ascii art from the top logo-padding-top = 3 +# Padding of the layout from the top +layout-padding-top = 0 + # Colors can be with: hexcodes (#55ff88) and for bold put '!' (!#55ff88) # OR ANSI escape code colors like "\e[1;34m" # remember to add ${0} where you want to reset color @@ -109,6 +112,16 @@ secs = " seconds" # e.g "Packages: $(pacman -Q | wc -l) (pacman)" pkg-managers = ["pacman", "dpkg", "flatpak"] +# Distros and package manager specific +# package manager paths for getting the packages count from path. +# They are arrayies so you can add multiple paths. +# +# If you don't know what these ares, leave them by default settings +pacman-dirs = ["/var/lib/pacman/local/"] +dpkg-files = ["/var/lib/dpkg/status"] +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") [gui] diff --git a/include/config.hpp b/include/config.hpp index e0a9792..b7abc7e 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -35,7 +35,7 @@ class Config Config(const std::string_view configFile, const std::string_view configDir, colors_t& colors); // config file - std::vector layouts; + std::vector layout; std::string source_path; std::string font; std::string data_dir; @@ -182,23 +182,23 @@ layout-padding-top = 0 # Colors can be with: hexcodes (#55ff88) and for bold put '!' (!#55ff88) # OR ANSI escape code colors like "\e[1;34m" # remember to add ${0} where you want to reset color -black = "\e[1;30m" -red = "\e[1;31m" -green = "\e[1;32m" -yellow = "\e[1;33m" -blue = "\e[1;34m" +black = "\e[1;30m" +red = "\e[1;31m" +green = "\e[1;32m" +yellow = "\e[1;33m" +blue = "\e[1;34m" magenta = "\e[1;35m" -cyan = "\e[1;36m" -white = "\e[1;37m" +cyan = "\e[1;36m" +white = "\e[1;37m" # $ config [os.uptime] # how to display the name of the uptime # e.g: hours = "hrs" -> "Uptime: 3hrs" -days = " days" +days = " days" hours = " hours" -mins = " mins" -secs = " seconds" +mins = " mins" +secs = " seconds" # $ config [os.pkgs] @@ -214,7 +214,7 @@ pkg-managers = ["pacman", "dpkg", "flatpak"] # Distros and package manager specific # package manager paths for getting the packages count from path. # They are arrayies so you can add multiple paths. -# +# # If you don't know what these ares, leave them by default settings pacman-dirs = ["/var/lib/pacman/local/"] dpkg-files = ["/var/lib/dpkg/status"] diff --git a/src/config.cpp b/src/config.cpp index 9cc4b58..eb9387d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -38,7 +38,7 @@ void Config::loadConfigFile(const std::string_view filename, colors_t& colors) // clang-format off // Idk but with `this->` looks more readable - this->layouts = this->getValueArrayStr("config.layout", {}); + this->layout = this->getValueArrayStr("config.layout", {}); this->gui = this->getValue("gui.enable", false); this->ascii_logo_type = this->getValue("config.ascii-logo-type", ""); this->source_path = this->getValue("config.source-path", "os"); diff --git a/src/display.cpp b/src/display.cpp index 38bc12f..d112a13 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -44,7 +44,7 @@ std::vector Display::render(const Config& config, const colors_t& c const std::string_view path) { systemInfo_t systemInfo{}; - std::vector asciiArt{}, layouts{ config.layouts }; + std::vector asciiArt{}, layout{ config.layout }; if (!config.m_display_distro && !config.m_disable_source && !config.source_path.empty()) { @@ -89,7 +89,7 @@ std::vector Display::render(const Config& config, const colors_t& c for (int i = 0; i < config.layout_padding_top; i++) { - layouts.insert(layouts.begin(), ""); + layout.insert(layout.begin(), ""); } while (std::getline(file, line)) @@ -140,26 +140,26 @@ std::vector Display::render(const Config& config, const colors_t& c return asciiArt; std::string _; - for (std::string& layout : layouts) + for (std::string& layout : layout) layout = parse(layout, systemInfo, _, config, colors, true); // erase each element for each instance of MAGIC_LINE - layouts.erase(std::remove_if(layouts.begin(), layouts.end(), + layout.erase(std::remove_if(layout.begin(), layout.end(), [](const std::string_view str) { return str.find(MAGIC_LINE) != std::string::npos; }), - layouts.end()); + layout.end()); size_t i; - for (i = 0; i < layouts.size(); i++) + for (i = 0; i < layout.size(); i++) { size_t origin = config.logo_padding_left; // The user-specified offset to be put before the logo for (size_t j = 0; j < config.logo_padding_left; j++) - layouts.at(i).insert(0, " "); + layout.at(i).insert(0, " "); if (i < asciiArt.size()) { - layouts.at(i).insert(origin, asciiArt.at(i)); + layout.at(i).insert(origin, asciiArt.at(i)); origin += asciiArt.at(i).length(); } @@ -169,9 +169,9 @@ std::vector Display::render(const Config& config, const colors_t& c debug("spaces: {}", spaces); for (size_t j = 0; j < spaces; j++) - layouts.at(i).insert(origin, " "); + layout.at(i).insert(origin, " "); - layouts.at(i) += config.gui ? "" : NOCOLOR; + layout.at(i) += config.gui ? "" : NOCOLOR; } for (; i < asciiArt.size(); i++) @@ -183,10 +183,10 @@ std::vector Display::render(const Config& config, const colors_t& c line += asciiArt[i]; - layouts.push_back(line); + layout.push_back(line); } - return layouts; + return layout; } void Display::display(const std::vector& renderResult) diff --git a/src/gui.cpp b/src/gui.cpp index e667e22..658a02c 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -34,7 +34,7 @@ using namespace GUI; static std::vector render_with_image(const Config& config, const colors_t& colors) { systemInfo_t systemInfo{}; - std::vector layouts{ config.layouts }; + std::vector layout{ config.layout }; int image_width, image_height, channels; @@ -47,21 +47,21 @@ static std::vector render_with_image(const Config& config, const co die("Unable to load image '{}'", config.source_path); std::string _; - for (std::string& layout : layouts) + for (std::string& layout : layout) layout = parse(layout, systemInfo, _, config, colors, true, true); // erase each element for each instance of MAGIC_LINE - layouts.erase(std::remove_if(layouts.begin(), layouts.end(), + layout.erase(std::remove_if(layout.begin(), layout.end(), [](const std::string_view str) { return str.find(MAGIC_LINE) != std::string::npos; }), - layouts.end()); + layout.end()); - for (size_t i = 0; i < layouts.size(); i++) + for (size_t i = 0; i < layout.size(); i++) { for (size_t _ = 0; _ < config.offset; _++) // I use _ because we don't need it - layouts.at(i).insert(0, " "); + layout.at(i).insert(0, " "); } - return layouts; + return layout; } Window::Window(const Config& config, const colors_t& colors, const std::string_view path) diff --git a/src/main.cpp b/src/main.cpp index 6c4820e..5aefab4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -429,9 +429,6 @@ int main (int argc, char *argv[]) { config.m_display_distro = (config.source_path == "os"); std::string path = config.m_display_distro ? Display::detect_distro(config) : config.source_path; - if (!std::filesystem::exists(path) && - !std::filesystem::exists((path = config.data_dir + "/ascii/linux.txt"))) - die("'{}' doesn't exist. Can't load image/text file", path); if (!config.ascii_logo_type.empty()) { @@ -442,6 +439,10 @@ int main (int argc, char *argv[]) { path += "_" + config.ascii_logo_type; } + if (!std::filesystem::exists(path) && + !std::filesystem::exists((path = config.data_dir + "/ascii/linux.txt"))) + die("'{}' doesn't exist. Can't load image/text file", path); + #ifdef GUI_MODE if (config.gui) {