Skip to content

Commit

Permalink
parse: invert $%% tag with a ! before the last %
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Sep 9, 2024
1 parent 9690706 commit 24de72a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)\"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `\`

Expand Down
2 changes: 2 additions & 0 deletions cufetch.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<user.name> will print the username, $<os.kernel_version> will print the kernel version and so on.
Expand Down Expand Up @@ -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 "$<os.kernel> <- Kernel" it won't work on GUI mode?"
Expand Down
5 changes: 2 additions & 3 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "config.hpp"
#include "fmt/core.h"
#include "fmt/ranges.h"
#include "parse.hpp"
#include "query.hpp"
#include "util.hpp"
Expand Down Expand Up @@ -194,6 +193,6 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c

void Display::display(const std::vector<std::string>& renderResult)
{
// for loops hell nah
fmt::println("{}", fmt::join(renderResult, "\n"));
for (const std::string_view str : renderResult)
fmt::println("{}", str);
}
10 changes: 5 additions & 5 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand All @@ -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}";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 24de72a

Please sign in to comment.