Skip to content

Commit c2426d9

Browse files
committed
parse: fix reset colors in ram, disk and swap
1 parent 9bdf67e commit c2426d9

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

assets/config-examples/config_cool.toml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@
5353
# A: replace "<-" with "\\<-". It won't affect the printing in terminal
5454

5555
# Old pipelines screensavers inspired layout
56-
# This is really system depedent
56+
# This is really system depedent and really meassy
57+
# but proves how customizable you can be
5758
layout = [
5859
"$<builtin.title>",
59-
"$<builtin.tile_sep>",
60+
"$<builtin.title_sep>",
6061
"${red}$<os.name> ${cyan} $<system.arch>${cyan} \\<- Arch ",
6162
"${red} ^ ${green} $<os.kernel> \\<━━━┓",
6263
"${red} | ${green}┃",
@@ -75,14 +76,14 @@ layout = [
7576
#"${white}Packages -> $<os.pkgs>",
7677
#"${!#fff1ba}WM -> $<user.wm_name>",
7778
#"${!#ffff2a}DE -> $<user.de_name> $<user.de_version>",
78-
" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓",
79-
" ┃ ┃",
80-
" ┃ ${!#448aa4}Disk (/) -> $<disk(/).disk> ",
81-
"System Infos ━━━━━━━━━━━━━━━━┫ ${magenta}CPU -> $<cpu.cpu> ┃",
82-
" ┃ ${blue}GPU -> $<gpu.name> ┃",
83-
" ┃ ${!#03ff93}RAM usage -> $<ram.ram> ",
84-
" ┃ ┃",
85-
" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛",
79+
" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
80+
" ",
81+
" ┃ ${!#448aa4}Disk (/) -> $<disk(/).disk> ┃",
82+
"System Infos ━━━━━━━━━━━━━━━━┫ ${magenta}CPU -> $<cpu.cpu> ",
83+
" ┃ ${blue}GPU -> $<gpu.name> ",
84+
" ┃ ${!#03ff93}RAM usage -> $<ram.ram> ┃",
85+
" ",
86+
" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
8687
"",
8788
"$<builtin.colors_bg>", # normal colors
8889
"$<builtin.colors_light_bg>" # light colors
@@ -110,7 +111,7 @@ title-sep = "-"
110111
# A separator (or string) that when ecountered, will automatically
111112
# reset color, aka. automatically add ${0} (only in layout)
112113
# Make it empty for disabling
113-
sep-reset = ":"
114+
sep-reset = "->"
114115

115116
# Should we reset color after or before the separator?
116117
# true = after ("test ->${0} ")

src/parse.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static std::string get_and_color_percentage(const float& n1, const float& n2, sy
108108
else
109109
color = "${green}";
110110
}
111-
111+
112112
std::string _;
113113
return parse(fmt::format("{}{:.2f}%${{0}}", color, result), systemInfo, _, config, colors, parsingLayout);
114114
}
@@ -256,7 +256,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
256256
pureOutput.replace(start_pos, taglen, shell_cmd);
257257

258258
} break;
259-
259+
260260
case '>':
261261
{
262262
const size_t& dot_pos = command.find('.');
@@ -307,7 +307,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
307307
const std::string& equalto = command.substr(conditional_comma + 1, equalto_comma - conditional_comma - 1);
308308
const std::string& true_statment = command.substr(equalto_comma + 1, true_comma - equalto_comma - 1);
309309
const std::string& false_statment = command.substr(true_comma + 1);
310-
310+
311311
std::string _;
312312
const std::string& parsed_conditional = parse(conditional, systemInfo, _, config, colors, parsingLayout);
313313
const std::string& parsed_equalto = parse(equalto, systemInfo, _, config, colors, parsingLayout);
@@ -326,7 +326,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
326326
} break;
327327

328328
case '}': // please pay very attention when reading this unreadable and godawful code
329-
329+
330330
// if at end there a '$', it will make the end output "$</span>" and so it will confuse addValueFromModule()
331331
// and so let's make it "$ </span>".
332332
// this geniunenly stupid
@@ -497,7 +497,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
497497
if (opt_clr.find('i') != std::string::npos)
498498
append_styles(style, fmt::emphasis::italic);
499499

500-
formatted_replacement_string =
500+
formatted_replacement_string =
501501
fmt::format(style, "{}", output.substr(endBracketIndex + 1));
502502
}
503503

@@ -755,7 +755,7 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
755755
Query::User query_user;
756756
Query::System query_system;
757757
const size_t& title_len = fmt::format("{}@{}", query_user.name(), query_system.hostname()).length();
758-
758+
759759
std::string str;
760760
str.reserve(config.builtin_title_sep.length() * title_len);
761761
for (size_t i = 0; i < title_len; i++)
@@ -979,7 +979,7 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
979979

980980
else if (hasStart(moduleName, "disk"))
981981
{
982-
if (moduleName.length() < 7)
982+
if (moduleName.length() < "disk()"_len)
983983
die("invalid disk module name '{}', must be disk(/path/to/fs) e.g: disk(/)", moduleName);
984984

985985
enum
@@ -1017,10 +1017,12 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
10171017
const std::string& perc = get_and_color_percentage(query_disk.used_amount(), query_disk.total_amount(),
10181018
sysInfo, config, colors, parsingLayout);
10191019

1020-
SYSINFO_INSERT(fmt::format("{:.2f} {} / {:.2f} {} ({}) - {}",
1020+
std::string _;
1021+
SYSINFO_INSERT(fmt::format("{:.2f} {} / {:.2f} {} {} - {}",
10211022
byte_units.at(USED).num_bytes, byte_units.at(USED).unit,
10221023
byte_units.at(TOTAL).num_bytes,byte_units.at(TOTAL).unit,
1023-
perc, query_disk.typefs()));
1024+
parse("${0}(" + perc + ")", sysInfo, _, config, colors, parsingLayout),
1025+
query_disk.typefs()));
10241026
} break;
10251027
// clang-format on
10261028

@@ -1091,11 +1093,12 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
10911093
{
10921094
const std::string& perc = get_and_color_percentage(query_ram.swap_used_amount(), query_ram.swap_total_amount(),
10931095
sysInfo, config, colors, parsingLayout);
1094-
1095-
SYSINFO_INSERT(fmt::format("{:.2f} {} / {:.2f} {} ({})",
1096-
byte_units.at(USED).num_bytes, byte_units.at(USED).unit,
1096+
1097+
std::string _;
1098+
SYSINFO_INSERT(fmt::format("{:.2f} {} / {:.2f} {} {}",
1099+
byte_units.at(USED).num_bytes, byte_units.at(USED).unit,
10971100
byte_units.at(TOTAL).num_bytes,byte_units.at(TOTAL).unit,
1098-
perc));
1101+
parse("${0}(" + perc + ")", sysInfo, _, config, colors, parsingLayout)));
10991102
}
11001103
break;
11011104
// clang-format on
@@ -1164,14 +1167,15 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
11641167
{
11651168
case "ram"_fnv1a16:
11661169
{
1167-
const std::string& perc = get_and_color_percentage(query_ram.used_amount(), query_ram.total_amount(),
1170+
const std::string& perc = get_and_color_percentage(query_ram.used_amount(), query_ram.total_amount(),
11681171
sysInfo, config, colors, parsingLayout);
1169-
1172+
1173+
std::string _;
11701174
// clang-format off
1171-
SYSINFO_INSERT(fmt::format("{:.2f} {} / {:.2f} {} ({})",
1172-
byte_units.at(USED).num_bytes, byte_units.at(USED).unit,
1175+
SYSINFO_INSERT(fmt::format("{:.2f} {} / {:.2f} {} {}",
1176+
byte_units.at(USED).num_bytes, byte_units.at(USED).unit,
11731177
byte_units.at(TOTAL).num_bytes,byte_units.at(TOTAL).unit,
1174-
perc));
1178+
parse("${0}(" + perc + ")", sysInfo, _, config, colors, parsingLayout)));
11751179
break;
11761180
// clang-format on
11771181
}
@@ -1188,12 +1192,12 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
11881192
break;
11891193

11901194
case "free_perc"_fnv1a16:
1191-
SYSINFO_INSERT(get_and_color_percentage(query_ram.free_amount(), query_ram.total_amount(),
1195+
SYSINFO_INSERT(get_and_color_percentage(query_ram.free_amount(), query_ram.total_amount(),
11921196
sysInfo, config, colors, parsingLayout, true));
11931197
break;
11941198

11951199
case "used_perc"_fnv1a16:
1196-
SYSINFO_INSERT(get_and_color_percentage(query_ram.used_amount(), query_ram.total_amount(),
1200+
SYSINFO_INSERT(get_and_color_percentage(query_ram.used_amount(), query_ram.total_amount(),
11971201
sysInfo, config, colors, parsingLayout));
11981202
break;
11991203

0 commit comments

Comments
 (0)