Changed: Small graphs now show colors for each character

This commit is contained in:
Aristocratos 2022-07-26 21:34:14 +02:00
parent 7dc398f0c0
commit edbafa9060

View file

@ -388,15 +388,22 @@ namespace Draw {
} }
} }
//? Generate graph symbol from 5x5 2D vector //? Generate graph symbol from 5x5 2D vector
graphs.at(current).at(horizon) += (height == 1 and result.at(0) + result.at(1) == 0) ? Mv::r(1) : graph_symbol.at((result.at(0) * 5 + result.at(1))); if (height == 1) {
if (result.at(0) + result.at(1) == 0) graphs.at(current).at(horizon) += Mv::r(1);
else {
if (not color_gradient.empty()) graphs.at(current).at(horizon) += Theme::g(color_gradient).at(clamp(max(last, data_value), 0ll, 100ll));
graphs.at(current).at(horizon) += graph_symbol.at((result.at(0) * 5 + result.at(1)));
}
}
else graphs.at(current).at(horizon) += graph_symbol.at((result.at(0) * 5 + result.at(1)));
} }
if (mult and i >= 0) last = data_value; if (mult and i >= 0) last = data_value;
} }
last = data_value; last = data_value;
out.clear(); out.clear();
if (height == 1) { if (height == 1) {
if (not color_gradient.empty()) //if (not color_gradient.empty())
out += (last < 1 and not color_gradient.empty() ? Theme::c("inactive_fg") : Theme::g(color_gradient).at(clamp(last, 0ll, 100ll))); // out += (last < 1 ? Theme::c("inactive_fg") : Theme::g(color_gradient).at(clamp(last, 0ll, 100ll)));
out += graphs.at(current).at(0); out += graphs.at(current).at(0);
} }
else { else {
@ -443,7 +450,10 @@ namespace Draw {
//? Make room for new characters on graph //? Make room for new characters on graph
if (not tty_mode) current = not current; if (not tty_mode) current = not current;
for (const int& i : iota(0, height)) { for (const int& i : iota(0, height)) {
if (graphs.at(current).at(i).at(1) == '[') graphs.at(current).at(i).erase(0, 4); if (height == 1 and graphs.at(current).at(i).at(1) == '[') {
if (graphs.at(current).at(i).at(3) == 'C') graphs.at(current).at(i).erase(0, 4);
else graphs.at(current).at(i).erase(0, graphs.at(current).at(i).find_first_of('m') + 4);
}
else if (graphs.at(current).at(i).at(0) == ' ') graphs.at(current).at(i).erase(0, 1); else if (graphs.at(current).at(i).at(0) == ' ') graphs.at(current).at(i).erase(0, 1);
else graphs.at(current).at(i).erase(0, 3); else graphs.at(current).at(i).erase(0, 3);
} }
@ -528,15 +538,15 @@ namespace Cpu {
if (b_column_size > 0 or extra_width > 0) { if (b_column_size > 0 or extra_width > 0) {
core_graphs.clear(); core_graphs.clear();
for (const auto& core_data : cpu.core_percent) { for (const auto& core_data : cpu.core_percent) {
core_graphs.emplace_back(5 * b_column_size + extra_width, 1, "", core_data, graph_symbol); core_graphs.emplace_back(5 * b_column_size + extra_width, 1, "cpu", core_data, graph_symbol);
} }
} }
if (show_temps) { if (show_temps) {
temp_graphs.clear(); temp_graphs.clear();
temp_graphs.emplace_back(5, 1, "", cpu.temp.at(0), graph_symbol, false, false, cpu.temp_max, -23); temp_graphs.emplace_back(5, 1, "temp", cpu.temp.at(0), graph_symbol, false, false, cpu.temp_max, -23);
if (not hide_cores and b_column_size > 1) { if (not hide_cores and b_column_size > 1) {
for (const auto& i : iota((size_t)1, cpu.temp.size())) { for (const auto& i : iota((size_t)1, cpu.temp.size())) {
temp_graphs.emplace_back(5, 1, "", cpu.temp.at(i), graph_symbol, false, false, cpu.temp_max, -23); temp_graphs.emplace_back(5, 1, "temp", cpu.temp.at(i), graph_symbol, false, false, cpu.temp_max, -23);
} }
} }
} }
@ -626,16 +636,16 @@ namespace Cpu {
+ ljust(to_string(n), core_width); + ljust(to_string(n), core_width);
if (b_column_size > 0 or extra_width > 0) if (b_column_size > 0 or extra_width > 0)
out += Theme::c("inactive_fg") + graph_bg * (5 * b_column_size + extra_width) + Mv::l(5 * b_column_size + extra_width) out += Theme::c("inactive_fg") + graph_bg * (5 * b_column_size + extra_width) + Mv::l(5 * b_column_size + extra_width)
+ Theme::g("cpu").at(clamp(cpu.core_percent.at(n).back(), 0ll, 100ll)) + core_graphs.at(n)(cpu.core_percent.at(n), data_same or redraw); + core_graphs.at(n)(cpu.core_percent.at(n), data_same or redraw);
else
out += Theme::g("cpu").at(clamp(cpu.core_percent.at(n).back(), 0ll, 100ll)); out += Theme::g("cpu").at(clamp(cpu.core_percent.at(n).back(), 0ll, 100ll));
out += rjust(to_string(cpu.core_percent.at(n).back()), (b_column_size < 2 ? 3 : 4)) + Theme::c("main_fg") + '%'; out += rjust(to_string(cpu.core_percent.at(n).back()), (b_column_size < 2 ? 3 : 4)) + Theme::c("main_fg") + '%';
if (show_temps and not hide_cores) { if (show_temps and not hide_cores) {
const auto [temp, unit] = celsius_to(cpu.temp.at(n+1).back(), temp_scale); const auto [temp, unit] = celsius_to(cpu.temp.at(n+1).back(), temp_scale);
const auto& temp_color = Theme::g("temp").at(clamp(cpu.temp.at(n+1).back() * 100 / cpu.temp_max, 0ll, 100ll)); const auto& temp_color = Theme::g("temp").at(clamp(cpu.temp.at(n+1).back() * 100 / cpu.temp_max, 0ll, 100ll));
if (b_column_size > 1) if (b_column_size > 1)
out += ' ' + Theme::c("inactive_fg") + graph_bg * 5 + Mv::l(5) + temp_color out += ' ' + Theme::c("inactive_fg") + graph_bg * 5 + Mv::l(5)
+ temp_graphs.at(n+1)(cpu.temp.at(n+1), data_same or redraw); + temp_graphs.at(n+1)(cpu.temp.at(n+1), data_same or redraw);
out += temp_color + rjust(to_string(temp), 4) + Theme::c("main_fg") + unit; out += temp_color + rjust(to_string(temp), 4) + Theme::c("main_fg") + unit;
} }
@ -753,7 +763,7 @@ namespace Mem {
for (const auto& [name, disk] : mem.disks) { for (const auto& [name, disk] : mem.disks) {
if (disk.io_read.empty()) continue; if (disk.io_read.empty()) continue;
io_graphs[name + "_activity"] = Draw::Graph{disks_width - 6, 1, "", disk.io_activity, graph_symbol}; io_graphs[name + "_activity"] = Draw::Graph{disks_width - 6, 1, "available", disk.io_activity, graph_symbol};
if (io_mode) { if (io_mode) {
//? Create one combined graph for IO read/write if enabled //? Create one combined graph for IO read/write if enabled
@ -850,7 +860,7 @@ namespace Mem {
const string used_percent = to_string(disk.used_percent); const string used_percent = to_string(disk.used_percent);
out += Mv::to(y+1+cy, x+1+cx + round((double)disks_width / 2) - round((double)used_percent.size() / 2) - 1) + hu_div + used_percent + '%' + hu_div; out += Mv::to(y+1+cy, x+1+cx + round((double)disks_width / 2) - round((double)used_percent.size() / 2) - 1) + hu_div + used_percent + '%' + hu_div;
} }
out += Mv::to(y+2+cy++, x+1+cx) + (big_disk ? " IO% " : " IO " + Mv::l(2)) + Theme::c("inactive_fg") + graph_bg * (disks_width - 6) + Theme::g("available").at(clamp(disk.io_activity.back(), 50ll, 100ll)) out += Mv::to(y+2+cy++, x+1+cx) + (big_disk ? " IO% " : " IO " + Mv::l(2)) + Theme::c("inactive_fg") + graph_bg * (disks_width - 6)
+ Mv::l(disks_width - 6) + io_graphs.at(mount + "_activity")(disk.io_activity, redraw or data_same) + Theme::c("main_fg"); + Mv::l(disks_width - 6) + io_graphs.at(mount + "_activity")(disk.io_activity, redraw or data_same) + Theme::c("main_fg");
if (++cy > height - 3) break; if (++cy > height - 3) break;
if (io_graph_combined) { if (io_graph_combined) {