mirror of https://github.com/aristocratos/btop.git
Further 'cleanup'
This commit is contained in:
parent
dfa2a9b920
commit
eda6873071
|
@ -21,7 +21,6 @@ tab-size = 4
|
|||
#include <btop_shared.hpp>
|
||||
#include <btop_tools.hpp>
|
||||
|
||||
using std::string_literals::operator""s;
|
||||
namespace rng = std::ranges;
|
||||
using namespace Tools;
|
||||
|
||||
|
@ -99,7 +98,8 @@ namespace Proc {
|
|||
}
|
||||
}
|
||||
|
||||
void _tree_gen(proc_info& cur_proc, vector<proc_info>& in_procs, vector<tree_proc>& out_procs, int cur_depth, const bool collapsed, const string& filter, bool found, const bool no_update, const bool should_filter) {
|
||||
void _tree_gen(proc_info& cur_proc, vector<proc_info>& in_procs, vector<tree_proc>& out_procs,
|
||||
int cur_depth, const bool collapsed, const string& filter, bool found, const bool no_update, const bool should_filter) {
|
||||
auto cur_pos = out_procs.size();
|
||||
bool filtering = false;
|
||||
|
||||
|
@ -132,7 +132,7 @@ namespace Proc {
|
|||
std::string_view cmd_view = cur_proc.cmd;
|
||||
cmd_view = cmd_view.substr((size_t)0, std::min(cmd_view.find(' '), cmd_view.size()));
|
||||
cmd_view = cmd_view.substr(std::min(cmd_view.find_last_of('/') + 1, cmd_view.size()));
|
||||
cur_proc.short_cmd = (string)cmd_view;
|
||||
cur_proc.short_cmd = string{cmd_view};
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -170,4 +170,4 @@ namespace Proc {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,18 +18,26 @@ tab-size = 4
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <deque>
|
||||
#include <robin_hood.h>
|
||||
#include <array>
|
||||
#include <ifaddrs.h>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <ifaddrs.h>
|
||||
#include <robin_hood.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using std::string, std::vector, std::deque, robin_hood::unordered_flat_map, std::atomic, std::array, std::tuple;
|
||||
using robin_hood::unordered_flat_map;
|
||||
using std::array;
|
||||
using std::atomic;
|
||||
using std::deque;
|
||||
using std::string;
|
||||
using std::tuple;
|
||||
using std::vector;
|
||||
|
||||
using namespace std::literals; // for operator""s
|
||||
|
||||
void term_resize(bool force=false);
|
||||
void banner_gen();
|
||||
|
@ -124,17 +132,21 @@ namespace Mem {
|
|||
extern string box;
|
||||
extern int x, y, width, height, min_width, min_height;
|
||||
extern bool has_swap, shown, redraw;
|
||||
const array<string, 4> mem_names = {"used", "available", "cached", "free"};
|
||||
const array<string, 2> swap_names = {"swap_used", "swap_free"};
|
||||
const array mem_names { "used"s, "available"s, "cached"s, "free"s };
|
||||
const array swap_names { "swap_used"s, "swap_free"s };
|
||||
extern int disk_ios;
|
||||
|
||||
struct disk_info {
|
||||
std::filesystem::path dev;
|
||||
string name;
|
||||
string fstype = "";
|
||||
std::filesystem::path stat = "";
|
||||
int64_t total = 0, used = 0, free = 0;
|
||||
int used_percent = 0, free_percent = 0;
|
||||
string fstype{}; // defaults to ""
|
||||
std::filesystem::path stat{}; // defaults to ""
|
||||
int64_t total{}; // defaults to 0
|
||||
int64_t used{}; // defaults to 0
|
||||
int64_t free{}; // defaults to 0
|
||||
int used_percent{}; // defaults to 0
|
||||
int free_percent{}; // defaults to 0
|
||||
|
||||
array<int64_t, 3> old_io = {0, 0, 0};
|
||||
deque<long long> io_read = {};
|
||||
deque<long long> io_write = {};
|
||||
|
@ -173,14 +185,20 @@ namespace Net {
|
|||
extern unordered_flat_map<string, uint64_t> graph_max;
|
||||
|
||||
struct net_stat {
|
||||
uint64_t speed = 0, top = 0, total = 0, last = 0, offset = 0, rollover = 0;
|
||||
uint64_t speed{}; // defaults to 0
|
||||
uint64_t top{}; // defaults to 0
|
||||
uint64_t total{}; // defaults to 0
|
||||
uint64_t last{}; // defaults to 0
|
||||
uint64_t offset{}; // defaults to 0
|
||||
uint64_t rollover{}; // defaults to 0
|
||||
};
|
||||
|
||||
struct net_info {
|
||||
unordered_flat_map<string, deque<long long>> bandwidth = { {"download", {}}, {"upload", {}} };
|
||||
unordered_flat_map<string, net_stat> stat = { {"download", {}}, {"upload", {}} };
|
||||
string ipv4 = "", ipv6 = "";
|
||||
bool connected = false;
|
||||
string ipv4{}; // defaults to ""
|
||||
string ipv6{}; // defaults to ""
|
||||
bool connected{}; // defaults to false
|
||||
};
|
||||
|
||||
extern unordered_flat_map<string, net_info> current_net;
|
||||
|
@ -232,25 +250,32 @@ namespace Proc {
|
|||
|
||||
//* Container for process information
|
||||
struct proc_info {
|
||||
size_t pid = 0;
|
||||
string name = "", cmd = "";
|
||||
string short_cmd = "";
|
||||
size_t threads = 0;
|
||||
int name_offset = 0;
|
||||
string user = "";
|
||||
uint64_t mem = 0;
|
||||
double cpu_p = 0.0, cpu_c = 0.0;
|
||||
size_t pid{}; // defaults to 0
|
||||
string name{}; // defaults to ""
|
||||
string cmd{}; // defaults to ""
|
||||
string short_cmd{}; // defaults to ""
|
||||
size_t threads{}; // defaults to 0
|
||||
int name_offset{}; // defaults to 0
|
||||
string user{}; // defaults to ""
|
||||
uint64_t mem{}; // defaults to 0
|
||||
double cpu_p{}; // defaults to = 0.0
|
||||
double cpu_c{}; // defaults to = 0.0
|
||||
char state = '0';
|
||||
uint64_t p_nice = 0, ppid = 0, cpu_s = 0, cpu_t = 0;
|
||||
string prefix = "";
|
||||
size_t depth = 0, tree_index = 0;
|
||||
bool collapsed = false, filtered = false;
|
||||
uint64_t p_nice{}; // defaults to 0
|
||||
uint64_t ppid{}; // defaults to 0
|
||||
uint64_t cpu_s{}; // defaults to 0
|
||||
uint64_t cpu_t{}; // defaults to 0
|
||||
string prefix{}; // defaults to ""
|
||||
size_t depth{}; // defaults to 0
|
||||
size_t tree_index{}; // defaults to 0
|
||||
bool collapsed{}; // defaults to false
|
||||
bool filtered{}; // defaults to false
|
||||
};
|
||||
|
||||
//* Container for process info box
|
||||
struct detail_container {
|
||||
size_t last_pid = 0;
|
||||
bool skip_smaps = false;
|
||||
size_t last_pid{}; // defaults to 0
|
||||
bool skip_smaps{}; // defaults to false
|
||||
proc_info entry;
|
||||
string elapsed, parent, status, io_read, io_write, memory;
|
||||
long long first_mem = -1;
|
||||
|
@ -276,11 +301,15 @@ namespace Proc {
|
|||
};
|
||||
|
||||
//* Sort vector of proc_info's
|
||||
void proc_sorter(vector<proc_info>& proc_vec, const string& sorting, const bool reverse, const bool tree = false);
|
||||
void proc_sorter(vector<proc_info>& proc_vec, const string& sorting,
|
||||
const bool reverse, const bool tree = false);
|
||||
|
||||
//* Recursive sort of process tree
|
||||
void tree_sort(vector<tree_proc>& proc_vec, const string& sorting, const bool reverse, int& c_index, const int index_max, const bool collapsed = false);
|
||||
void tree_sort(vector<tree_proc>& proc_vec, const string& sorting,
|
||||
const bool reverse, int& c_index, const int index_max, const bool collapsed = false);
|
||||
|
||||
//* Generate process tree list
|
||||
void _tree_gen(proc_info& cur_proc, vector<proc_info>& in_procs, vector<tree_proc>& out_procs, int cur_depth, const bool collapsed, const string& filter, bool found=false, const bool no_update=false, const bool should_filter=false);
|
||||
void _tree_gen(proc_info& cur_proc, vector<proc_info>& in_procs, vector<tree_proc>& out_procs,
|
||||
int cur_depth, const bool collapsed, const string& filter,
|
||||
bool found=false, const bool no_update=false, const bool should_filter=false);
|
||||
}
|
||||
|
|
|
@ -17,9 +17,7 @@ tab-size = 4
|
|||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <ranges>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -27,9 +25,19 @@ tab-size = 4
|
|||
#include <btop_config.hpp>
|
||||
#include <btop_theme.hpp>
|
||||
|
||||
using std::round, std::vector, std::stoi, std::views::iota,
|
||||
std::clamp, std::max, std::min, std::ceil, std::to_string;
|
||||
using std::ceil;
|
||||
using std::clamp;
|
||||
using std::max;
|
||||
using std::min;
|
||||
using std::quoted;
|
||||
using std::round;
|
||||
using std::stoi;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
using std::views::iota;
|
||||
|
||||
using namespace Tools;
|
||||
|
||||
namespace rng = std::ranges;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
@ -152,10 +160,12 @@ namespace Theme {
|
|||
string hex_to_color(string hexa, const bool& t_to_256, const string& depth) {
|
||||
if (hexa.size() > 1) {
|
||||
hexa.erase(0, 1);
|
||||
for (auto& c : hexa) if (not isxdigit(c)) {
|
||||
Logger::error("Invalid hex value: " + hexa);
|
||||
return "";
|
||||
}
|
||||
for (auto& c : hexa) {
|
||||
if (not isxdigit(c)) {
|
||||
Logger::error("Invalid hex value: " + hexa);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
string pre = Fx::e + (depth == "fg" ? "38" : "48") + ";" + (t_to_256 ? "5;" : "2;");
|
||||
|
||||
if (hexa.size() == 2) {
|
||||
|
@ -200,14 +210,17 @@ namespace Theme {
|
|||
array<int, 3> hex_to_dec(string hexa) {
|
||||
if (hexa.size() > 1) {
|
||||
hexa.erase(0, 1);
|
||||
for (auto& c : hexa) if (not isxdigit(c)) return array<int, 3>{-1, -1, -1};
|
||||
for (auto& c : hexa) {
|
||||
if (not isxdigit(c))
|
||||
return array{-1, -1, -1};
|
||||
}
|
||||
|
||||
if (hexa.size() == 2) {
|
||||
int h_int = stoi(hexa, nullptr, 16);
|
||||
return array<int, 3>{h_int, h_int, h_int};
|
||||
return array{h_int, h_int, h_int};
|
||||
}
|
||||
else if (hexa.size() == 6) {
|
||||
return array<int, 3>{
|
||||
return array{
|
||||
stoi(hexa.substr(0, 2), nullptr, 16),
|
||||
stoi(hexa.substr(2, 2), nullptr, 16),
|
||||
stoi(hexa.substr(4, 2), nullptr, 16)
|
||||
|
@ -247,11 +260,11 @@ namespace Theme {
|
|||
}
|
||||
else if (not source.at(name).empty()) {
|
||||
t_rgb = ssplit(source.at(name));
|
||||
if (t_rgb.size() != 3)
|
||||
Logger::error("Invalid RGB decimal value: \"" + source.at(name) + "\"");
|
||||
else {
|
||||
if (t_rgb.size() != 3) {
|
||||
Logger::error("Invalid RGB decimal value: \"" + source.at(name) + "\"");
|
||||
} else {
|
||||
colors[name] = dec_to_color(stoi(t_rgb[0]), stoi(t_rgb[1]), stoi(t_rgb[2]), t_to_256, depth);
|
||||
rgbs[name] = array<int, 3>{stoi(t_rgb[0]), stoi(t_rgb[1]), stoi(t_rgb[2])};
|
||||
rgbs[name] = array{stoi(t_rgb[0]), stoi(t_rgb[1]), stoi(t_rgb[2])};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -287,12 +300,13 @@ namespace Theme {
|
|||
const bool& t_to_256 = Config::getB("lowcolor");
|
||||
|
||||
//? Insert values for processes greyscale gradient and processes color gradient
|
||||
rgbs.insert({ { "proc_start", rgbs["main_fg"] },
|
||||
{ "proc_mid", {-1, -1, -1} },
|
||||
{ "proc_end", rgbs["inactive_fg"] },
|
||||
{ "proc_color_start", rgbs["inactive_fg"] },
|
||||
{ "proc_color_mid", {-1, -1, -1} },
|
||||
{ "proc_color_end", rgbs["process_start"] },
|
||||
rgbs.insert({
|
||||
{ "proc_start", rgbs["main_fg"] },
|
||||
{ "proc_mid", {-1, -1, -1} },
|
||||
{ "proc_end", rgbs["inactive_fg"] },
|
||||
{ "proc_color_start", rgbs["inactive_fg"] },
|
||||
{ "proc_color_mid", {-1, -1, -1} },
|
||||
{ "proc_color_end", rgbs["process_start"] },
|
||||
});
|
||||
|
||||
for (const auto& [name, source_arr] : rgbs) {
|
||||
|
@ -315,10 +329,10 @@ namespace Theme {
|
|||
|
||||
//? Split iteration in two passes of 50 + 51 instead of one pass of 101 if gradient has start, mid and end values defined
|
||||
int current_range = (input_colors[1][0] >= 0) ? 50 : 100;
|
||||
for (const int& rgb : iota(0, 3)) {
|
||||
for (int rgb : iota(0, 3)) {
|
||||
int start = 0, offset = 0;
|
||||
int end = (current_range == 50) ? 1 : 2;
|
||||
for (const int& i : iota(0, 101)) {
|
||||
for (int i : iota(0, 101)) {
|
||||
output_colors[i][rgb] = input_colors[start][rgb] + (i - offset) * (input_colors[end][rgb] - input_colors[start][rgb]) / current_range;
|
||||
|
||||
//? Switch source arrays from start->mid to mid->end at 50 passes if mid is defined
|
||||
|
@ -353,7 +367,7 @@ namespace Theme {
|
|||
const string base_name = rtrim(c.first, "_start");
|
||||
string section = "_start";
|
||||
int split = colors.at(base_name + "_mid").empty() ? 50 : 33;
|
||||
for (const int& i : iota(0, 101)) {
|
||||
for (int i : iota(0, 101)) {
|
||||
gradients[base_name][i] = colors.at(base_name + section);
|
||||
if (i == split) {
|
||||
section = (split == 33) ? "_mid" : "_end";
|
||||
|
|
|
@ -18,12 +18,16 @@ tab-size = 4
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <robin_hood.h>
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <robin_hood.h>
|
||||
|
||||
using std::string, robin_hood::unordered_flat_map, std::array;
|
||||
using std::array;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using robin_hood::unordered_flat_map;
|
||||
|
||||
namespace Theme {
|
||||
extern std::filesystem::path theme_dir;
|
||||
|
@ -63,4 +67,4 @@ namespace Theme {
|
|||
//* Return array of red, green and blue in decimal for color <name>
|
||||
inline const std::array<int, 3>& dec(string name) { return rgbs.at(name); }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue