Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/btop_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,24 +817,24 @@ namespace Cpu {
out += Mv::to(b_y, b_x + b_width - 10) + Fx::ub + Theme::c("div_line") + Symbols::h_line * (7 - cpuHz.size())
+ 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(safeVal(cpu.cpu_percent, "total"s).back())
+ Theme::g("cpu").at(clamp(safeVal(cpu.cpu_percent, "total"s).back(), 0ll, 100ll)) + rjust(to_string(safeVal(cpu.cpu_percent, "total"s).back()), 4) + Theme::c("main_fg") + '%';
if (show_temps) {
const auto [temp, unit] = celsius_to(safeVal(cpu.temp, 0).back(), temp_scale);
const auto temp_color = Theme::g("temp").at(clamp(safeVal(cpu.temp, 0).back() * 100 / cpu.temp_max, 0ll, 100ll));
if ((b_column_size > 1 or b_columns > 1) and temp_graphs.size() >= 1ll)
out += ' ' + Theme::c("inactive_fg") + graph_bg * 5 + Mv::l(5) + temp_color
+ temp_graphs.at(0)(safeVal(cpu.temp, 0), data_same or redraw);
out += rjust(to_string(temp), 4) + Theme::c("main_fg") + unit;
}

if (show_watts) {
string cwatts = fmt::format(" {:>4.{}f}", cpu.usage_watts, cpu.usage_watts < 10.0f ? 2 : cpu.usage_watts < 100.0f ? 1 : 0);
string cwatts_post = "W";
out += Mv::to(b_y + 1, b_x + 1) + Theme::c("main_fg") + Fx::b + "CPU " + cpu_meter(safeVal(cpu.cpu_percent, "total"s).back())
+ Theme::g("cpu").at(clamp(safeVal(cpu.cpu_percent, "total"s).back(), 0ll, 100ll)) + rjust(to_string(safeVal(cpu.cpu_percent, "total"s).back()), 4) + Theme::c("main_fg") + '%';
if (show_temps) {
const auto [temp, unit] = celsius_to(safeVal(cpu.temp, 0).back(), temp_scale);
const auto temp_color = Theme::g("temp").at(clamp(safeVal(cpu.temp, 0).back() * 100 / cpu.temp_max, 0ll, 100ll));
if ((b_column_size > 1 or b_columns > 1) and temp_graphs.size() >= 1ll)
out += ' ' + Theme::c("inactive_fg") + graph_bg * 5 + Mv::l(5) + temp_color
+ temp_graphs.at(0)(safeVal(cpu.temp, 0), data_same or redraw);
out += rjust(to_string(temp), 4) + Theme::c("main_fg") + unit;
}

max_observed_pwr = max(max_observed_pwr, cpu.usage_watts);
out += Theme::g("cached").at(clamp(cpu.usage_watts / max_observed_pwr * 100.0f, 0.0f, 100.0f)) + cwatts + Theme::c("main_fg") + cwatts_post;
}
if (show_watts) {
string cwatts = fmt::format(" {:>4.{}f}", cpu.usage_watts, cpu.usage_watts < 10.0f ? 2 : cpu.usage_watts < 100.0f ? 1 : 0);
string cwatts_post = "W";

max_observed_pwr = max(max_observed_pwr, cpu.usage_watts);
out += Theme::g("cached").at(clamp(cpu.usage_watts / max_observed_pwr * 100.0f, 0.0f, 100.0f)) + cwatts + Theme::c("main_fg") + cwatts_post;
}

out += Theme::c("div_line") + Symbols::v_line;
} catch (const std::exception& e) {
Expand Down
20 changes: 10 additions & 10 deletions src/btop_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ namespace Proc {

void _tree_gen(proc_info& cur_proc, vector<proc_info>& in_procs, vector<tree_proc>& out_procs,
int cur_depth, bool collapsed, const string& filter, bool found, bool no_update, bool should_filter) {
auto cur_pos = out_procs.size();
bool filtering = false;

//? If filtering, include children of matching processes
Expand Down Expand Up @@ -241,17 +240,18 @@ namespace Proc {
cur_proc.threads += p.threads;
}
}
if (collapsed or filtering) {
return;
}
Comment thread
Denizantip marked this conversation as resolved.
}

//? Add tree terminator symbol if it's the last child in a sub-tree
if (out_procs.back().children.size() > 0 and out_procs.back().children.back().entry.get().prefix.size() >= 8 and not out_procs.back().children.back().entry.get().prefix.ends_with("]─"))
out_procs.back().children.back().entry.get().prefix.replace(out_procs.back().children.back().entry.get().prefix.size() - 8, 8, " └─ ");
void _collect_prefixes(tree_proc &t, const bool is_last, const string &header) {
const bool is_filtered = t.entry.get().filtered;
if (is_filtered) t.entry.get().depth = 0;
Comment thread
Denizantip marked this conversation as resolved.

//? Add collapse/expand symbols if process have any children
out_procs.at(cur_pos).entry.get().prefix = " │ "s * cur_depth + (out_procs.at(cur_pos).children.size() > 0 ? (cur_proc.collapsed ? "[+]─" : "[-]─") : " ├─ ");
if (!t.children.empty()) t.entry.get().prefix = header + (t.entry.get().collapsed ? "[+]─": "[-]─");
Comment thread
deckstose marked this conversation as resolved.
else t.entry.get().prefix = header + (is_last ? " └─": " ├─");

for (auto child = t.children.begin(); child != t.children.end(); ++child) {
_collect_prefixes(*child, child == (t.children.end() - 1),
is_filtered ? "": header + (is_last ? " ": " │ "));
}
}

}
3 changes: 3 additions & 0 deletions src/btop_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,7 @@ namespace Proc {
void _tree_gen(proc_info& cur_proc, vector<proc_info>& in_procs, vector<tree_proc>& out_procs,
int cur_depth, bool collapsed, const string& filter,
bool found = false, bool no_update = false, bool should_filter = false);

//* Build prefixes for tree view
void _collect_prefixes(tree_proc& t, bool is_last, const string &header = "");
}
11 changes: 4 additions & 7 deletions src/freebsd/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,13 +1266,10 @@ namespace Proc {
int index = 0;
tree_sort(tree_procs, sorting, reverse, index, current_procs.size());

//? Add tree begin symbol to first item if childless
if (tree_procs.front().children.empty())
tree_procs.front().entry.get().prefix.replace(tree_procs.front().entry.get().prefix.size() - 8, 8, " ┌─ ");

//? Add tree terminator symbol to last item if childless
if (tree_procs.back().children.empty())
tree_procs.back().entry.get().prefix.replace(tree_procs.back().entry.get().prefix.size() - 8, 8, " └─ ");
//? Recursive construction of ASCII tree prefixes.
for (auto t = tree_procs.begin(); t != tree_procs.end(); ++t) {
_collect_prefixes(*t, t == tree_procs.end() - 1);
}

//? Final sort based on tree index
rng::sort(current_procs, rng::less{}, & proc_info::tree_index);
Expand Down
11 changes: 4 additions & 7 deletions src/linux/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3115,13 +3115,10 @@ namespace Proc {
int index = 0;
tree_sort(tree_procs, sorting, reverse, index, current_procs.size());

//? Add tree begin symbol to first item if childless
if (tree_procs.size() > 0 and tree_procs.front().children.empty() and tree_procs.front().entry.get().prefix.size() >= 8)
tree_procs.front().entry.get().prefix.replace(tree_procs.front().entry.get().prefix.size() - 8, 8, " ┌─ ");

//? Add tree terminator symbol to last item if childless
if (tree_procs.size() > 0 and tree_procs.back().children.empty() and tree_procs.back().entry.get().prefix.size() >= 8)
tree_procs.back().entry.get().prefix.replace(tree_procs.back().entry.get().prefix.size() - 8, 8, " └─ ");
//? Recursive construction of ASCII tree prefixes.
for (auto t = tree_procs.begin(); t != tree_procs.end(); ++t) {
_collect_prefixes(*t, t == tree_procs.end() - 1);
}

//? Final sort based on tree index
rng::sort(current_procs, rng::less{}, & proc_info::tree_index);
Expand Down
11 changes: 4 additions & 7 deletions src/netbsd/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,13 +1346,10 @@ namespace Proc {
int index = 0;
tree_sort(tree_procs, sorting, reverse, index, current_procs.size());

//? Add tree begin symbol to first item if childless
if (tree_procs.front().children.empty())
tree_procs.front().entry.get().prefix.replace(tree_procs.front().entry.get().prefix.size() - 8, 8, " ┌─ ");

//? Add tree terminator symbol to last item if childless
if (tree_procs.back().children.empty())
tree_procs.back().entry.get().prefix.replace(tree_procs.back().entry.get().prefix.size() - 8, 8, " └─ ");
//? Recursive construction of ASCII tree prefixes.
for (auto t = tree_procs.begin(); t != tree_procs.end(); ++t) {
_collect_prefixes(*t, t == tree_procs.end() - 1);
}

//? Final sort based on tree index
rng::sort(current_procs, rng::less{}, & proc_info::tree_index);
Expand Down
11 changes: 4 additions & 7 deletions src/openbsd/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,13 +1198,10 @@ namespace Proc {
int index = 0;
tree_sort(tree_procs, sorting, reverse, index, current_procs.size());

//? Add tree begin symbol to first item if childless
if (tree_procs.front().children.empty())
tree_procs.front().entry.get().prefix.replace(tree_procs.front().entry.get().prefix.size() - 8, 8, " ┌─ ");

//? Add tree terminator symbol to last item if childless
if (tree_procs.back().children.empty())
tree_procs.back().entry.get().prefix.replace(tree_procs.back().entry.get().prefix.size() - 8, 8, " └─ ");
//? Recursive construction of ASCII tree prefixes.
for (auto t = tree_procs.begin(); t != tree_procs.end(); ++t) {
_collect_prefixes(*t, t == tree_procs.end() - 1);
}

//? Final sort based on tree index
rng::sort(current_procs, rng::less{}, & proc_info::tree_index);
Expand Down
11 changes: 4 additions & 7 deletions src/osx/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,13 +1337,10 @@ namespace Proc {
int index = 0;
tree_sort(tree_procs, sorting, reverse, index, current_procs.size());

//? Add tree begin symbol to first item if childless
if (tree_procs.front().children.empty())
tree_procs.front().entry.get().prefix.replace(tree_procs.front().entry.get().prefix.size() - 8, 8, " ┌─ ");

//? Add tree terminator symbol to last item if childless
if (tree_procs.back().children.empty())
tree_procs.back().entry.get().prefix.replace(tree_procs.back().entry.get().prefix.size() - 8, 8, " └─ ");
//? Recursive construction of ASCII tree prefixes.
for (auto t = tree_procs.begin(); t != tree_procs.end(); ++t) {
_collect_prefixes(*t, t == tree_procs.end() - 1);
}

//? Final sort based on tree index
rng::sort(current_procs, rng::less{}, & proc_info::tree_index);
Expand Down
Loading