diff --git a/cufetch.1 b/cufetch.1 index e708b8d..d36ae1c 100644 --- a/cufetch.1 +++ b/cufetch.1 @@ -96,7 +96,10 @@ To escape any $ or bracket, just use \\ .SH OPTIONS .TP \fB\-n\fR, \fB\-\-no\-display\fR -Do not display the ascii art +Do not display the logo +.TP +\fB\-N\fR, \fB\-\-no\-color\fR +Do not output and parse colors. Useful for stdout or pipe operations .TP \fB\-s\fR, \fB\-\-source\-path\fR Path to the ascii art file to display @@ -129,6 +132,13 @@ An example: "[Liberation Mono] [Normal] [12]", which can be "Liberation Mono Nor .br It's recommended to use GUI mode for the moment if something doesn't work .TP +\fB\-m\fR, \fB\-\-layout\-line\fR +Will replace the config layout, with a layout you specify in the arguments +.br +Example: "cufetch -m "${auto}OS: $" -m "${auto}CPU: $" " +.br +Will only print the logo (if not disabled), along side the parsed OS and CPU +.TP \fB\-g\fR, \fB\-\-gui\fR Use GUI mode instead of priting in the terminal (use \fB\-V\fR to check if it's enabled) .TP diff --git a/include/config.hpp b/include/config.hpp index 2103472..46fac6f 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -66,9 +66,11 @@ class Config std::vector apk_files; // inner management / argument configs + std::vector m_args_layout; std::string m_custom_distro; std::string m_image_backend; bool m_disable_source = false; + bool m_disable_colors = false; bool m_display_distro = true; bool m_print_logo_only = false; diff --git a/src/display.cpp b/src/display.cpp index c4f4042..b6d82f7 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -147,7 +147,7 @@ std::vector Display::render(const Config& config, const colors_t& c const std::string_view path) { systemInfo_t systemInfo{}; - std::vector asciiArt{}, layout{ config.layout }; + std::vector asciiArt{}, layout{ config.m_args_layout.empty() ? config.layout : config.m_args_layout }; debug("Display::render path = {}", path); @@ -231,7 +231,8 @@ std::vector Display::render(const Config& config, const colors_t& c { std::string pureOutput; std::string asciiArt_s = parse(line, systemInfo, pureOutput, config, colors, false); - asciiArt_s += config.gui ? "" : NOCOLOR; + if (!config.m_disable_colors) + asciiArt_s += config.gui ? "" : NOCOLOR; if (config.gui) { @@ -306,15 +307,17 @@ std::vector Display::render(const Config& config, const colors_t& c for (size_t j = 0; j < spaces; j++) layout.at(i).insert(origin, " "); - layout.at(i) += config.gui ? "" : NOCOLOR; + if (!config.m_disable_colors) + layout.at(i) += config.gui ? "" : NOCOLOR; } for (; i < asciiArt.size(); i++) { std::string line; + line.reserve(config.logo_padding_left + asciiArt.at(i).length()); for (size_t j = 0; j < config.logo_padding_left; j++) - line += " "; + line += ' '; line += asciiArt.at(i); diff --git a/src/gui.cpp b/src/gui.cpp index e5fdfe1..3f140fa 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -36,7 +36,7 @@ static std::vector render_with_image(const Config& config, const co { std::string path{ Display::detect_distro(config) }; systemInfo_t systemInfo{}; - std::vector layout{ config.layout }; + std::vector layout{ config.m_args_layout.empty() ? config.layout : config.m_args_layout }; int image_width, image_height, channels; diff --git a/src/main.cpp b/src/main.cpp index 860d6e9..0a4f07b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,8 +44,9 @@ static void help(bool invalid_opt = false) fmt::println(R"( A command-line system information tool (or neofetch like program), which its focus point is customizability and perfomance - -n, --no-display Do not display the ascii art - -s, --source-path Path to the ascii art file to display + -n, --no-display Do not display the logo + -N, --no-color Do not output and parse colors. Useful for stdout or pipe operations + -s, --source-path Path to the ascii art or image file to display -C, --config Path to the config file to use -a, --ascii-logo-type [] The type of ASCII art to apply ("small" or "old"). @@ -62,6 +63,10 @@ A command-line system information tool (or neofetch like program), which its foc Right now only 'kitty' and 'viu' are supported It's recommended to use GUI mode for the moment if something doesn't work + -m, --layout-line Will replace the config layout, with a layout you specify in the arguments + Example: "cufetch -m "${{auto}}OS: $" -m "${{auto}}CPU: $" " + Will only print the logo (if not disabled), along side the parsed OS and CPU + -g, --gui Use GUI mode instead of priting in the terminal (use -V to check if it was enabled) -o, --offset Offset between the ascii art and the layout -l. --list-modules Print the list of the modules and its members @@ -266,11 +271,12 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_ int opt = 0; int option_index = 0; opterr = 1; // re-enable since before we disabled for "invalid option" error - const char *optstring = "-VhnLlga::f:o:C:i:d:D:s:"; + const char *optstring = "-VhnNLlga::f:o:C:i:d:D:s:m:"; static const struct option opts[] = { {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {"no-display", no_argument, 0, 'n'}, + {"no-color", no_argument, 0, 'N'}, {"list-modules", no_argument, 0, 'l'}, {"logo-only", no_argument, 0, 'L'}, {"gui", no_argument, 0, 'g'}, @@ -278,6 +284,7 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_ {"offset", required_argument, 0, 'o'}, {"font", required_argument, 0, 'f'}, {"config", required_argument, 0, 'C'}, + {"layout-line", required_argument, 0, 'm'}, {"data-dir", required_argument, 0, 'D'}, {"distro", required_argument, 0, 'd'}, {"source-path", required_argument, 0, 's'}, @@ -329,10 +336,14 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_ config.data_dir = optarg; break; case 'd': config.m_custom_distro = str_tolower(optarg); break; + case 'm': + config.m_args_layout.push_back(optarg); break; case 's': config.source_path = optarg; break; case 'i': config.m_image_backend = optarg; break; + case 'N': + config.m_disable_colors = true; break; case 'a': if (OPTIONAL_ARGUMENT_IS_PRESENT) config.ascii_logo_type = optarg; diff --git a/src/parse.cpp b/src/parse.cpp index 0f21745..c4ec85a 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -237,7 +237,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s if (dollarSignIndex == std::string::npos) break; - else if (dollarSignIndex <= oldDollarSignIndex && start) + else if (dollarSignIndex <= oldDollarSignIndex && start && !config.m_disable_colors) { dollarSignIndex = output.find('$', dollarSignIndex + 1); // oh nooo.. whatever @@ -408,6 +408,14 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s case '}': // please pay close attention when reading this really long code + if (config.m_disable_colors) + { + output.erase(dollarSignIndex, taglen); + if (tagpos != std::string::npos) + pureOutput.erase(tagpos, tagToReplace.length()); + break; + } + // if at end there a '$', it will make the end output "$" and so it will confuse // addValueFromModule() and so let's make it "$ ". this is geniunenly stupid if (config.gui && output.back() == '$') @@ -426,7 +434,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s // I don't care, it does the work and well if (command == *it_name) command = config.colors_value.at(it_value); - goto jump; + goto jumpauto; } if (command == *it_name) @@ -446,7 +454,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s command = auto_colors.at(ver); } - jump: + jumpauto: if (command == "1") { if (firstrun_noclr)