From 24de72af57175b9650429a9791578ae16418b2ae Mon Sep 17 00:00:00 2001 From: Toni500git Date: Mon, 9 Sep 2024 11:53:14 +0200 Subject: [PATCH] parse: invert $%% tag with a ! before the last % --- Makefile | 14 +++++++------- README.md | 1 + cufetch.1 | 2 ++ include/config.hpp | 4 +++- src/display.cpp | 5 ++--- src/parse.cpp | 10 +++++----- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 785d1f5..6c4a8dd 100644 --- a/Makefile +++ b/Makefile @@ -37,13 +37,13 @@ ifeq ($(GUI_MODE), 1) CXXFLAGS += `pkg-config --cflags gtkmm-3.0` endif -NAME = customfetch -TARGET = cufetch -OLDVERSION = 0.8.8 -VERSION = 0.9.0 -BRANCH = $(shell git rev-parse --abbrev-ref HEAD) -SRC = $(wildcard src/*.cpp src/query/unix/*.cpp src/query/unix/utils/*.cpp) -OBJ = $(SRC:.cpp=.o) +NAME = customfetch +TARGET = cufetch +OLDVERSION = 0.8.8 +VERSION = 0.9.0 +BRANCH = $(shell git rev-parse --abbrev-ref HEAD) +SRC = $(wildcard src/*.cpp src/query/unix/*.cpp src/query/unix/utils/*.cpp) +OBJ = $(SRC:.cpp=.o) LDFLAGS += -L./$(BUILDDIR)/fmt -lfmt -ldl CXXFLAGS ?= -mtune=generic -march=native CXXFLAGS += -fvisibility=hidden -Iinclude -std=c++20 $(VARS) -DVERSION=\"$(VERSION)\" -DBRANCH=\"$(BRANCH)\" diff --git a/README.md b/README.md index 91c7ccd..555f903 100644 --- a/README.md +++ b/README.md @@ -295,6 +295,7 @@ They can be used in the ascii art text file and layout, but how to use them? * **The Percentage tag (`$%%`)** is used for displaying the percentage between 2 numbers.\ It **Must** contain a comma for separating the 2. They can be either be taken from a tag or it put yourself.\ For example: $%10,5% + For inverting colors of bad and great (red and green), before the last '%' a put '!' without quotes Any `$` or brackets can be escaped with a backslash `\` diff --git a/cufetch.1 b/cufetch.1 index 5b97b6c..e85b807 100644 --- a/cufetch.1 +++ b/cufetch.1 @@ -81,6 +81,8 @@ The \fBPercentage tag $%%\fR is used for displaying the percentage between 2 num It \fBMust\fR contain a comma for separating the 2. They can be either be taken from a tag or it put yourself. .br For example: $%10,5% +.br +For inverting colors of bad and great (red and green), before the last '%' a put '!' without quotes .PP To escape any $ or bracket, just use \\ .SH OPTIONS diff --git a/include/config.hpp b/include/config.hpp index 9916e98..1800aec 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -94,7 +94,7 @@ inline constexpr std::string_view AUTOCONFIG = R"#([config] # here is how it works: # the variable "layout" is used for showing the infos # as like as the user want, no limitation. -# inside here there are 4 "tags": $<> $() ${} $[] +# inside here there are 5 "tags": $<> $() ${} $[] $%% # The Info tag $<> lets you print the value of a member of a module. # e.g $ will print the username, $ will print the kernel version and so on. @@ -134,6 +134,8 @@ inline constexpr std::string_view AUTOCONFIG = R"#([config] # The Percentage tag $%% is used for displaying the percentage between 2 numbers.\ # It **Must** contain a comma for separating the 2. They can be either be taken from a tag or it put yourself.\ # For example: $%10,5% +# For inverting colors of bad and great (red and green), before the last '%' a put '!' +# without quotes # Little FAQ # Q: "Why when I use something like "$ <- Kernel" it won't work on GUI mode?" diff --git a/src/display.cpp b/src/display.cpp index 203e302..da72881 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -11,7 +11,6 @@ #include "config.hpp" #include "fmt/core.h" -#include "fmt/ranges.h" #include "parse.hpp" #include "query.hpp" #include "util.hpp" @@ -194,6 +193,6 @@ std::vector Display::render(const Config& config, const colors_t& c void Display::display(const std::vector& renderResult) { - // for loops hell nah - fmt::println("{}", fmt::join(renderResult, "\n")); + for (const std::string_view str : renderResult) + fmt::println("{}", str); } diff --git a/src/parse.cpp b/src/parse.cpp index fa21e0f..68522c3 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -94,7 +94,7 @@ static std::string get_and_color_percentage(const float& n1, const float& n2, sy { if (result <= 35) color = "${green}"; - else if (result <= 50) + else if (result <= 80) color = "${yellow}"; else color = "${red}"; @@ -103,7 +103,7 @@ static std::string get_and_color_percentage(const float& n1, const float& n2, sy { if (result <= 35) color = "${red}"; - else if (result <= 50) + else if (result <= 80) color = "${yellow}"; else color = "${green}"; @@ -227,7 +227,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s // let's get what's inside the brackets for (size_t i = dollarSignIndex + 2; i < output.size(); i++) { - if (output.at(i) == type && output[i - 1] != '\\') + if (output[i] == type && output[i - 1] != '\\') { endBracketIndex = i; break; @@ -284,8 +284,8 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s std::string _; const float& n1 = std::stof(parse(command.substr(0, comma_pos), systemInfo, _, config, colors, parsingLayout)); const float& n2 = std::stof(parse(command.substr(comma_pos + 1), systemInfo, _, config, colors, parsingLayout)); - - output.replace(dollarSignIndex, taglen, get_and_color_percentage(n1, n2, systemInfo, config, colors, parsingLayout)); + + output.replace(dollarSignIndex, taglen, get_and_color_percentage(n1, n2, systemInfo, config, colors, parsingLayout, (command.back() == '!'))); break; }