Skip to content

Commit

Permalink
config: add sep-reset-after
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Sep 3, 2024
1 parent 36de78b commit 05f45e1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 6 additions & 0 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Config
std::uint16_t logo_padding_top = 0;
std::uint16_t layout_padding_top = 0;
bool gui = false;
bool sep_reset_after = false;

// modules specific config
std::string uptime_d_fmt;
Expand Down Expand Up @@ -183,6 +184,11 @@ sep-title = "-"
# Make it empty for disabling
sep-reset = ":"
# Should we reset color after or before the separetor?
# true = after ("test:${0} ")
# false = before ("test${0}: ")
sep-reset-after = false
# Offset between the ascii art and the layout
offset = 5
Expand Down
1 change: 1 addition & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void Config::loadConfigFile(const std::string_view filename, colors_t& colors)
// Idk but with `this->` looks more readable
this->layout = this->getValueArrayStr("config.layout", {});
this->gui = this->getValue<bool>("gui.enable", false);
this->sep_reset_after = this->getValue<bool>("config.sep-reset-after", false);
this->ascii_logo_type = this->getValue<std::string>("config.ascii-logo-type", "");
this->source_path = this->getValue<std::string>("config.source-path", "os");
this->data_dir = this->getValue<std::string>("config.data-dir", "/usr/share/customfetch");
Expand Down
25 changes: 18 additions & 7 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,22 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
// theres at first either ${1} or ${0}
// and that's a problem with pango markup
bool firstrun_noclr = true;


static std::vector<std::string> auto_colors;

if (!config.sep_reset.empty() && parsingLaoyut)
{
replace_str(output, config.sep_reset, "${0}" + config.sep_reset);
replace_str(pureOutput, config.sep_reset, "${0}" + config.sep_reset);
if (config.sep_reset_after)
{
replace_str(output, config.sep_reset, config.sep_reset + "${0}");
replace_str(pureOutput, config.sep_reset, config.sep_reset + "${0}");
}
else
{
replace_str(output, config.sep_reset, "${0}" + config.sep_reset);
replace_str(pureOutput, config.sep_reset, "${0}" + config.sep_reset);
}
}

while (true)
Expand Down Expand Up @@ -183,6 +193,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
if (type == ' ')
continue;

// 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] != '\\')
Expand Down Expand Up @@ -221,8 +232,8 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
if (dot_pos == std::string::npos)
die("module name '{}' doesn't have a dot '.' for separiting module name and submodule", command);

const std::string& moduleName(command.substr(0, dot_pos));
const std::string& moduleValueName(command.substr(dot_pos + 1));
const std::string& moduleName = command.substr(0, dot_pos);
const std::string& moduleValueName = command.substr(dot_pos + 1);
addValueFromModule(systemInfo, moduleName, moduleValueName, config);

output = output.replace(dollarSignIndex, (endBracketIndex + 1) - dollarSignIndex,
Expand All @@ -235,15 +246,15 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s

case ']':
{
const size_t condition_comma = command.find(',');
const size_t& condition_comma = command.find(',');
if (condition_comma == command.npos)
die("condition component {} doesn't have a comma for separiting the condition", command);

const size_t equalto_comma = command.find(',', condition_comma + 1);
const size_t& equalto_comma = command.find(',', condition_comma + 1);
if (equalto_comma == command.npos)
die("condition component {} doesn't have a comma for separiting the equalto", command);

const size_t true_comma = command.find(',', equalto_comma + 1);
const size_t& true_comma = command.find(',', equalto_comma + 1);
if (true_comma == command.npos)
die("condition component {} doesn't have a comma for separiting the true statment", command);

Expand Down

0 comments on commit 05f45e1

Please sign in to comment.