mirror of https://github.com/aristocratos/btop.git
Fixed: Color gradient array out of bounds, added clamp 0-100 for cpu percent values
This commit is contained in:
parent
feaf2cd14f
commit
85f945ada0
|
@ -396,7 +396,7 @@ namespace Draw {
|
|||
out.clear();
|
||||
if (height == 1) {
|
||||
if (not color_gradient.empty())
|
||||
out += (last < 1 and not color_gradient.empty() ? Theme::c("inactive_fg") : Theme::g(color_gradient).at(last));
|
||||
out += (last < 1 and not color_gradient.empty() ? Theme::c("inactive_fg") : Theme::g(color_gradient).at(clamp(last, 0ll, 100ll)));
|
||||
out += graphs.at(current).at(0);
|
||||
}
|
||||
else {
|
||||
|
@ -618,7 +618,7 @@ namespace Cpu {
|
|||
+ Symbols::title_left + Fx::b + Theme::c("title") + cpuHz + Fx::ub + Theme::c("div_line") + Symbols::title_right;
|
||||
|
||||
out += Mv::to(b_y + 1, b_x + 1) + Theme::c("main_fg") + Fx::b + "CPU " + cpu_meter(cpu.cpu_percent.at("total").back())
|
||||
+ Theme::g("cpu").at(cpu.cpu_percent.at("total").back()) + rjust(to_string(cpu.cpu_percent.at("total").back()), 4) + Theme::c("main_fg") + '%';
|
||||
+ Theme::g("cpu").at(clamp(cpu.cpu_percent.at("total").back(), 0ll, 100ll)) + rjust(to_string(cpu.cpu_percent.at("total").back()), 4) + Theme::c("main_fg") + '%';
|
||||
if (show_temps) {
|
||||
const auto [temp, unit] = celsius_to(cpu.temp.at(0).back(), temp_scale);
|
||||
const auto& temp_color = Theme::g("temp").at(clamp(cpu.temp.at(0).back() * 100 / cpu.temp_max, 0ll, 100ll));
|
||||
|
@ -638,9 +638,9 @@ namespace Cpu {
|
|||
+ ljust(to_string(n), (b_column_size == 0 ? 2 : 3));
|
||||
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)
|
||||
+ Theme::g("cpu").at(cpu.core_percent.at(n).back()) + core_graphs.at(n)(cpu.core_percent.at(n), data_same or redraw);
|
||||
+ 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);
|
||||
else
|
||||
out += Theme::g("cpu").at(cpu.core_percent.at(n).back());
|
||||
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") + '%';
|
||||
|
||||
if (show_temps and not hide_cores) {
|
||||
|
@ -860,7 +860,7 @@ namespace Mem {
|
|||
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)) + Theme::c("main_fg") + used_percent + '%';
|
||||
}
|
||||
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(max(50ll, disk.io_activity.back()))
|
||||
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))
|
||||
+ 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 (io_graph_combined) {
|
||||
|
@ -901,7 +901,7 @@ namespace Mem {
|
|||
out += Mv::to(y+1+cy, x+1+cx + round((double)disks_width / 2) - round((double)human_io.size() / 2)) + Theme::c("main_fg") + human_io;
|
||||
if (++cy > height - 3) break;
|
||||
if (show_io_stat and io_graphs.contains(mount + "_activity")) {
|
||||
out += Mv::to(y+1+cy, x+1+cx) + (big_disk ? " IO% " : " IO " + Mv::l(2)) + Theme::c("inactive_fg") + graph_bg * (disks_width - 6) + Theme::g("available").at(max(50ll, disk.io_activity.back()))
|
||||
out += Mv::to(y+1+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))
|
||||
+ Mv::l(disks_width - 6) + io_graphs.at(mount + "_activity")(disk.io_activity, redraw or data_same) + Theme::c("main_fg");
|
||||
if (not big_disk) out += Mv::to(y+1+cy, x+cx) + Theme::c("main_fg") + human_io;
|
||||
if (++cy > height - 3) break;
|
||||
|
|
|
@ -1201,7 +1201,7 @@ namespace Proc {
|
|||
|
||||
//? Update cpu percent deque for process cpu graph
|
||||
if (not Config::getB("proc_per_core")) detailed.entry.cpu_p *= Shared::coreCount;
|
||||
detailed.cpu_percent.push_back(round(detailed.entry.cpu_p));
|
||||
detailed.cpu_percent.push_back(clamp((long long)round(detailed.entry.cpu_p), 0ll, 100ll));
|
||||
while (cmp_greater(detailed.cpu_percent.size(), width)) detailed.cpu_percent.pop_front();
|
||||
|
||||
//? Process runtime
|
||||
|
|
Loading…
Reference in New Issue