Merge pull request #438 from stefanos82/main

Further cleanup
This commit is contained in:
Jakob P. Liljenberg 2022-10-05 12:28:55 +02:00 committed by GitHub
commit d58a17afb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 158 additions and 107 deletions

View File

@ -604,7 +604,7 @@ namespace Runner {
//? ------------------------------------------ Secondary thread end -----------------------------------------------
//* Runs collect and draw in a secondary thread, unlocks and locks config to update cached values
void run(const string& box, const bool no_update, const bool force_redraw) {
void run(const string& box, bool no_update, bool force_redraw) {
atomic_wait_for(active, true, 5000);
if (active) {
Logger::error("Stall in Runner thread, restarting!");

View File

@ -228,10 +228,13 @@ namespace Draw {
}
string createBox(const int x, const int y, const int width,
const int height, string line_color, const bool fill,
const int height, string line_color, bool fill,
const string title, const string title2, const int num) {
string out;
if (line_color.empty()) line_color = Theme::c("div_line");
if (line_color.empty())
line_color = Theme::c("div_line");
auto tty_mode = Config::getB("tty_mode");
auto rounded = Config::getB("rounded_corners");
const string numbering = (num == 0) ? "" : Theme::c("hi_fg") + (tty_mode ? std::to_string(num) : Symbols::superscript.at(clamp(num, 0, 9)));
@ -243,12 +246,12 @@ namespace Draw {
out = Fx::reset + line_color;
//? Draw horizontal lines
for (const int& hpos : {y, y + height - 1}) {
for (const int& hpos : {y, y + height - 1}) {
out += Mv::to(hpos, x) + Symbols::h_line * (width - 1);
}
//? Draw vertical lines and fill if enabled
for (const int& hpos : iota(y + 1, y + height - 1)) {
for (const int& hpos : iota(y + 1, y + height - 1)) {
out += Mv::to(hpos, x) + Symbols::v_line
+ ((fill) ? string(width - 2, ' ') : Mv::r(width - 2))
+ Symbols::v_line;
@ -340,7 +343,7 @@ namespace Draw {
//* Meter class ------------------------------------------------------------------------------------------------------------>
Meter::Meter() {}
Meter::Meter(const int width, const string& color_gradient, const bool invert)
Meter::Meter(const int width, const string& color_gradient, bool invert)
: width(width), color_gradient(color_gradient), invert(invert) {}
string Meter::operator()(int value) {
@ -363,7 +366,7 @@ namespace Draw {
//* Graph class ------------------------------------------------------------------------------------------------------------>
void Graph::_create(const deque<long long>& data, int data_offset) {
const bool mult = (data.size() - data_offset > 1);
bool mult = (data.size() - data_offset > 1);
const auto& graph_symbol = Symbols::graph_symbols.at(symbol + '_' + (invert ? "down" : "up"));
array<int, 2> result;
const float mod = (height == 1) ? 0.3 : 0.1;
@ -461,7 +464,7 @@ namespace Draw {
this->_create(data, data_offset);
}
string& Graph::operator()(const deque<long long>& data, const bool data_same) {
string& Graph::operator()(const deque<long long>& data, bool data_same) {
if (data_same) return out;
//? Make room for new characters on graph
@ -500,7 +503,7 @@ namespace Cpu {
vector<Draw::Graph> core_graphs;
vector<Draw::Graph> temp_graphs;
string draw(const cpu_info& cpu, const bool force_redraw, const bool data_same) {
string draw(const cpu_info& cpu, bool force_redraw, bool data_same) {
if (Runner::stopping) return "";
if (force_redraw) redraw = true;
bool show_temps = (Config::getB("check_temp") and got_sensors);
@ -722,7 +725,7 @@ namespace Mem {
unordered_flat_map<string, Draw::Meter> disk_meters_free;
unordered_flat_map<string, Draw::Graph> io_graphs;
string draw(const mem_info& mem, const bool force_redraw, const bool data_same) {
string draw(const mem_info& mem, bool force_redraw, bool data_same) {
if (Runner::stopping) return "";
if (force_redraw) redraw = true;
auto show_swap = Config::getB("show_swap");
@ -881,7 +884,7 @@ namespace Mem {
if (show_disks) {
const auto& disks = mem.disks;
cx = mem_width; cy = 0;
const bool big_disk = disks_width >= 25;
bool big_disk = disks_width >= 25;
divider = Mv::l(1) + Theme::c("div_line") + Symbols::div_left + Symbols::h_line * disks_width + Theme::c("mem_box") + Fx::ub + Symbols::div_right + Mv::l(disks_width);
const string hu_div = Theme::c("div_line") + Symbols::h_line + Theme::c("main_fg");
if (io_mode) {
@ -976,7 +979,7 @@ namespace Net {
unordered_flat_map<string, Draw::Graph> graphs;
string box;
string draw(const net_info& net, const bool force_redraw, const bool data_same) {
string draw(const net_info& net, bool force_redraw, bool data_same) {
if (Runner::stopping) return "";
if (force_redraw) redraw = true;
auto net_sync = Config::getB("net_sync");
@ -1145,11 +1148,11 @@ namespace Proc {
return (not changed ? -1 : selected);
}
string draw(const vector<proc_info>& plist, const bool force_redraw, const bool data_same) {
string draw(const vector<proc_info>& plist, bool force_redraw, bool data_same) {
if (Runner::stopping) return "";
auto proc_tree = Config::getB("proc_tree");
const bool show_detailed = (Config::getB("show_detailed") and cmp_equal(Proc::detailed.last_pid, Config::getI("detailed_pid")));
const bool proc_gradient = (Config::getB("proc_gradient") and not Config::getB("lowcolor") and Theme::gradients.contains("proc"));
bool show_detailed = (Config::getB("show_detailed") and cmp_equal(Proc::detailed.last_pid, Config::getI("detailed_pid")));
bool proc_gradient = (Config::getB("proc_gradient") and not Config::getB("lowcolor") and Theme::gradients.contains("proc"));
auto proc_colors = Config::getB("proc_colors");
auto tty_mode = Config::getB("tty_mode");
auto& graph_symbol = (tty_mode ? "tty" : Config::getS("graph_symbol_proc"));
@ -1191,7 +1194,7 @@ namespace Proc {
//? Detailed box
if (show_detailed) {
const bool alive = detailed.status != "Dead";
bool alive = detailed.status != "Dead";
dgraph_x = x;
dgraph_width = max(width / 3, width - 121);
d_width = width - dgraph_width - 1;
@ -1344,7 +1347,7 @@ namespace Proc {
//? Draw details box if shown
if (show_detailed) {
const bool alive = detailed.status != "Dead";
bool alive = detailed.status != "Dead";
const int item_fit = floor((double)(d_width - 2) / 10);
const int item_width = floor((double)(d_width - 2) / min(item_fit, 8));
@ -1403,7 +1406,7 @@ namespace Proc {
}
//? Update graphs for processes with above 0.0% cpu usage, delete if below 0.1% 10x times
const bool has_graph = show_graphs ? p_counters.contains(p.pid) : false;
bool has_graph = show_graphs ? p_counters.contains(p.pid) : false;
if (show_graphs and ((p.cpu_p > 0 and not has_graph) or (not data_same and has_graph))) {
if (not has_graph) {
p_graphs[p.pid] = Draw::Graph{5, 1, "", {}, graph_symbol};

View File

@ -80,10 +80,10 @@ namespace Draw {
//* Create a box and return as a string
string createBox(const int x, const int y, const int width,
const int height, string line_color="", const bool fill=false,
const string title="", const string title2="", const int num=0);
const int height, string line_color = "", bool fill = false,
const string title = "", const string title2 = "", const int num = 0);
bool update_clock(bool force=false);
bool update_clock(bool force = false);
//* Class holding a percentage meter
class Meter {
@ -93,7 +93,7 @@ namespace Draw {
array<string, 101> cache;
public:
Meter();
Meter(const int width, const string& color_gradient, const bool invert = false);
Meter(const int width, const string& color_gradient, bool invert = false);
//* Return a string representation of the meter with given value
string operator()(int value);
@ -123,7 +123,7 @@ namespace Draw {
long long max_value=0, long long offset=0);
//* Add last value from back of <data> and return string representation of graph
string& operator()(const deque<long long>& data, const bool data_same=false);
string& operator()(const deque<long long>& data, bool data_same=false);
//* Return string representation of graph
string& operator()();

View File

@ -26,7 +26,7 @@ using namespace Tools;
namespace Proc {
void proc_sorter(vector<proc_info>& proc_vec, const string& sorting, const bool reverse, const bool tree) {
void proc_sorter(vector<proc_info>& proc_vec, const string& sorting, bool reverse, bool tree) {
if (reverse) {
switch (v_index(sort_vector, sorting)) {
case 0: rng::stable_sort(proc_vec, rng::less{}, &proc_info::pid); break;
@ -70,7 +70,7 @@ namespace Proc {
}
}
void tree_sort(vector<tree_proc>& proc_vec, const string& sorting, const bool reverse, int& c_index, const int index_max, const bool collapsed) {
void tree_sort(vector<tree_proc>& proc_vec, const string& sorting, bool reverse, int& c_index, const int index_max, bool collapsed) {
if (proc_vec.size() > 1) {
if (reverse) {
switch (v_index(sort_vector, sorting)) {
@ -99,7 +99,7 @@ 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) {
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;

View File

@ -67,7 +67,7 @@ namespace Runner {
extern bool pause_output;
extern string debug_bg;
void run(const string& box="", const bool no_update=false, const bool force_redraw=false);
void run(const string& box="", bool no_update = false, bool force_redraw = false);
void stop();
}
@ -115,10 +115,10 @@ namespace Cpu {
};
//* Collect cpu stats and temperatures
auto collect(const bool no_update=false) -> cpu_info&;
auto collect(bool no_update = false) -> cpu_info&;
//* Draw contents of cpu box using <cpu> as source
string draw(const cpu_info& cpu, const bool force_redraw=false, const bool data_same=false);
string draw(const cpu_info& cpu, bool force_redraw = false, bool data_same = false);
//* Parse /proc/cpu info for mapping of core ids
auto get_core_mapping() -> unordered_flat_map<int, int>;
@ -168,10 +168,10 @@ namespace Mem {
uint64_t get_totalMem();
//* Collect mem & disks stats
auto collect(const bool no_update=false) -> mem_info&;
auto collect(bool no_update = false) -> mem_info&;
//* Draw contents of mem box using <mem> as source
string draw(const mem_info& mem, const bool force_redraw=false, const bool data_same=false);
string draw(const mem_info& mem, bool force_redraw = false, bool data_same = false);
}
@ -204,10 +204,10 @@ namespace Net {
extern unordered_flat_map<string, net_info> current_net;
//* Collect net upload/download stats
auto collect(const bool no_update=false) -> net_info&;
auto collect(bool no_update=false) -> net_info&;
//* Draw contents of net box using <net> as source
string draw(const net_info& net, const bool force_redraw=false, const bool data_same=false);
string draw(const net_info& net, bool force_redraw = false, bool data_same = false);
}
namespace Proc {
@ -287,13 +287,13 @@ namespace Proc {
extern detail_container detailed;
//* Collect and sort process information from /proc
auto collect(const bool no_update=false) -> vector<proc_info>&;
auto collect(bool no_update = false) -> vector<proc_info>&;
//* Update current selection and view, returns -1 if no change otherwise the current selection
int selection(const string& cmd_key);
//* Draw contents of proc box using <plist> as data source
string draw(const vector<proc_info>& plist, const bool force_redraw=false, const bool data_same=false);
string draw(const vector<proc_info>& plist, bool force_redraw = false, bool data_same = false);
struct tree_proc {
std::reference_wrapper<proc_info> entry;
@ -301,15 +301,14 @@ 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, bool reverse, 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);
bool reverse, int& c_index, const int index_max, 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);
int cur_depth, bool collapsed, const string& filter,
bool found = false, bool no_update = false, bool should_filter = false);
}

View File

@ -98,10 +98,10 @@ namespace Term {
}
auto get_min_size(const string& boxes) -> array<int, 2> {
const bool cpu = boxes.find("cpu") != string::npos;
const bool mem = boxes.find("mem") != string::npos;
const bool net = boxes.find("net") != string::npos;
const bool proc = boxes.find("proc") != string::npos;
bool cpu = boxes.find("cpu") != string::npos;
bool mem = boxes.find("mem") != string::npos;
bool net = boxes.find("net") != string::npos;
bool proc = boxes.find("proc") != string::npos;
int width = 0;
if (mem) width = Mem::min_width;
else if (net) width = Mem::min_width;
@ -205,8 +205,10 @@ namespace Tools {
return chars;
}
string uresize(string str, const size_t len, const bool wide) {
if (len < 1 or str.empty()) return "";
string uresize(string str, const size_t len, bool wide) {
if (len < 1 or str.empty())
return "";
if (wide) {
try {
std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
@ -233,8 +235,10 @@ namespace Tools {
return str;
}
string luresize(string str, const size_t len, const bool wide) {
if (len < 1 or str.empty()) return "";
string luresize(string str, const size_t len, bool wide) {
if (len < 1 or str.empty())
return "";
for (size_t x = 0, last_pos = 0, i = str.size() - 1; i > 0 ; i--) {
if (wide and static_cast<unsigned char>(str.at(i)) > 0xef) {
x += 2;
@ -262,7 +266,7 @@ namespace Tools {
}
string ltrim(const string& str, const string& t_str) {
string_view str_v = str;
string_view str_v{str};
while (str_v.starts_with(t_str))
str_v.remove_prefix(t_str.size());
@ -270,7 +274,7 @@ namespace Tools {
}
string rtrim(const string& str, const string& t_str) {
string_view str_v = str;
string_view str_v{str};
while (str_v.ends_with(t_str))
str_v.remove_suffix(t_str.size());
@ -288,41 +292,56 @@ namespace Tools {
return out;
}
string ljust(string str, const size_t x, const bool utf, const bool wide, const bool limit) {
string ljust(string str, const size_t x, bool utf, bool wide, bool limit) {
if (utf) {
if (limit and ulen(str, wide) > x) return uresize(str, x, wide);
if (limit and ulen(str, wide) > x)
return uresize(str, x, wide);
return str + string(max((int)(x - ulen(str)), 0), ' ');
}
else {
if (limit and str.size() > x) { str.resize(x); return str; }
if (limit and str.size() > x) {
str.resize(x);
return str;
}
return str + string(max((int)(x - str.size()), 0), ' ');
}
}
string rjust(string str, const size_t x, const bool utf, const bool wide, const bool limit) {
string rjust(string str, const size_t x, bool utf, bool wide, bool limit) {
if (utf) {
if (limit and ulen(str, wide) > x) return uresize(str, x, wide);
if (limit and ulen(str, wide) > x)
return uresize(str, x, wide);
return string(max((int)(x - ulen(str)), 0), ' ') + str;
}
else {
if (limit and str.size() > x) { str.resize(x); return str; };
if (limit and str.size() > x) {
str.resize(x);
return str;
};
return string(max((int)(x - str.size()), 0), ' ') + str;
}
}
string cjust(string str, const size_t x, const bool utf, const bool wide, const bool limit) {
string cjust(string str, const size_t x, bool utf, bool wide, bool limit) {
if (utf) {
if (limit and ulen(str, wide) > x) return uresize(str, x, wide);
if (limit and ulen(str, wide) > x)
return uresize(str, x, wide);
return string(max((int)ceil((double)(x - ulen(str)) / 2), 0), ' ') + str + string(max((int)floor((double)(x - ulen(str)) / 2), 0), ' ');
}
else {
if (limit and str.size() > x) { str.resize(x); return str; }
if (limit and str.size() > x) {
str.resize(x);
return str;
}
return string(max((int)ceil((double)(x - str.size()) / 2), 0), ' ') + str + string(max((int)floor((double)(x - str.size()) / 2), 0), ' ');
}
}
string trans(const string& str) {
string_view oldstr = str;
string_view oldstr{str};
string newstr;
newstr.reserve(str.size());
for (size_t pos; (pos = oldstr.find(' ')) != string::npos;) {
@ -346,7 +365,7 @@ namespace Tools {
return out;
}
string floating_humanizer(uint64_t value, const bool shorten, size_t start, const bool bit, const bool per_second) {
string floating_humanizer(uint64_t value, bool shorten, size_t start, bool bit, bool per_second) {
string out;
const size_t mult = (bit) ? 8 : 1;
bool mega = Config::getB("base_10_sizes");
@ -403,15 +422,29 @@ namespace Tools {
}
if (out.empty()) {
out = to_string(value);
if (not mega and out.size() == 4 and start > 0) { out.pop_back(); out.insert(2, ".");}
else if (out.size() == 3 and start > 0) out.insert(1, ".");
else if (out.size() >= 2) out.resize(out.size() - 2);
if (not mega and out.size() == 4 and start > 0) {
out.pop_back();
out.insert(2, ".");
}
else if (out.size() == 3 and start > 0) {
out.insert(1, ".");
}
else if (out.size() >= 2) {
out.resize(out.size() - 2);
}
}
if (shorten) {
auto f_pos = out.find('.');
if (f_pos == 1 and out.size() > 3) out = to_string(round(stof(out) * 10) / 10).substr(0,3);
else if (f_pos != string::npos) out = to_string((int)round(stof(out)));
if (out.size() > 3) { out = to_string((int)(out[0] - '0') + 1); start++;}
if (f_pos == 1 and out.size() > 3) {
out = to_string(round(stof(out) * 10) / 10).substr(0,3);
}
else if (f_pos != string::npos) {
out = to_string((int)round(stof(out)));
}
if (out.size() > 3) {
out = to_string((int)(out[0] - '0') + 1);
start++;
}
out.push_back(units[start][0]);
}
else out += " " + units[start];
@ -421,11 +454,19 @@ namespace Tools {
}
std::string operator*(const string& str, int64_t n) {
if (n < 1 or str.empty()) return "";
else if(n == 1) return str;
if (n < 1 or str.empty()) {
return "";
}
else if (n == 1) {
return str;
}
string new_str;
new_str.reserve(str.size() * n);
for (; n > 0; n--) new_str.append(str);
for (; n > 0; n--)
new_str.append(str);
return new_str;
}
@ -437,17 +478,17 @@ namespace Tools {
return ss.str();
}
void atomic_wait(const atomic<bool>& atom, const bool old) noexcept {
void atomic_wait(const atomic<bool>& atom, bool old) noexcept {
while (atom.load(std::memory_order_relaxed) == old ) busy_wait();
}
void atomic_wait_for(const atomic<bool>& atom, const bool old, const uint64_t wait_ms) noexcept {
void atomic_wait_for(const atomic<bool>& atom, bool old, const uint64_t wait_ms) noexcept {
const uint64_t start_time = time_ms();
while (atom.load(std::memory_order_relaxed) == old and (time_ms() - start_time < wait_ms)) sleep_ms(1);
}
atomic_lock::atomic_lock(atomic<bool>& atom, bool wait) : atom(atom) {
if (wait) while (not this->atom.compare_exchange_strong(this->not_true, true));
if (wait) while (not this->atom.compare_exchange_strong(this->not_true, true));
else this->atom.store(true);
}
@ -463,7 +504,7 @@ namespace Tools {
for (string readstr; getline(file, readstr); out += readstr);
}
catch (const std::exception& e) {
Logger::error("readfile() : Exception when reading " + (string)path + " : " + e.what());
Logger::error("readfile() : Exception when reading " + string{path} + " : " + e.what());
return fallback;
}
return (out.empty() ? fallback : out);
@ -509,10 +550,14 @@ namespace Logger {
int status = -1;
public:
lose_priv() {
if (geteuid() != Global::real_uid) this->status = seteuid(Global::real_uid);
if (geteuid() != Global::real_uid) {
this->status = seteuid(Global::real_uid);
}
}
~lose_priv() {
if (status == 0) status = seteuid(Global::set_uid);
if (status == 0) {
status = seteuid(Global::set_uid);
}
}
};
@ -529,8 +574,12 @@ namespace Logger {
if (fs::exists(logfile) and fs::file_size(logfile, ec) > 1024 << 10 and not ec) {
auto old_log = logfile;
old_log += ".1";
if (fs::exists(old_log)) fs::remove(old_log, ec);
if (not ec) fs::rename(logfile, old_log, ec);
if (fs::exists(old_log))
fs::remove(old_log, ec);
if (not ec)
fs::rename(logfile, old_log, ec);
}
if (not ec) {
std::ofstream lwrite(logfile, std::ios::app);

View File

@ -150,15 +150,15 @@ namespace Tools {
size_t wide_ulen(const std::wstring& w_str);
//* Return number of UTF8 characters in a string (wide=true for column size needed on terminal)
inline size_t ulen(const string& str, const bool wide=false) {
inline size_t ulen(const string& str, bool wide = false) {
return (wide ? wide_ulen(str) : std::ranges::count_if(str, [](char c) { return (static_cast<unsigned char>(c) & 0xC0) != 0x80; }));
}
//* Resize a string consisting of UTF8 characters (only reduces size)
string uresize(const string str, const size_t len, const bool wide=false);
string uresize(const string str, const size_t len, bool wide = false);
//* Resize a string consisting of UTF8 characters from left (only reduces size)
string luresize(const string str, const size_t len, const bool wide=false);
string luresize(const string str, const size_t len, bool wide = false);
//* Replace <from> in <str> with <to> and return new string
string s_replace(const string& str, const string& from, const string& to);
@ -270,25 +270,25 @@ namespace Tools {
}
//* Left justify string <str> if <x> is greater than <str> length, limit return size to <x> by default
string ljust(string str, const size_t x, const bool utf=false, const bool wide=false, const bool limit=true);
string ljust(string str, const size_t x, bool utf = false, bool wide = false, bool limit = true);
//* Right justify string <str> if <x> is greater than <str> length, limit return size to <x> by default
string rjust(string str, const size_t x, const bool utf=false, const bool wide=false, const bool limit=true);
string rjust(string str, const size_t x, bool utf = false, bool wide = false, bool limit = true);
//* Center justify string <str> if <x> is greater than <str> length, limit return size to <x> by default
string cjust(string str, const size_t x, const bool utf=false, const bool wide=false, const bool limit=true);
string cjust(string str, const size_t x, bool utf = false, bool wide = false, bool limit = true);
//* Replace whitespaces " " with escape code for move right
string trans(const string& str);
//* Convert seconds to format "<days>d <hours>:<minutes>:<seconds>" and return string
string sec_to_dhms(size_t seconds, bool no_days=false, bool no_seconds=false);
string sec_to_dhms(size_t seconds, bool no_days = false, bool no_seconds = false);
//* Scales up in steps of 1024 to highest positive value unit and returns string with unit suffixed
//* bit=True or defaults to bytes
//* start=int to set 1024 multiplier starting unit
//* short=True always returns 0 decimals and shortens unit to 1 character
string floating_humanizer(uint64_t value, const bool shorten=false, size_t start=0, const bool bit=false, const bool per_second=false);
string floating_humanizer(uint64_t value, bool shorten = false, size_t start = 0, bool bit = false, bool per_second = false);
//* Add std::string operator * : Repeat string <str> <n> number of times
std::string operator*(const string& str, int64_t n);
@ -311,21 +311,21 @@ namespace Tools {
#endif
}
void atomic_wait(const atomic<bool>& atom, const bool old=true) noexcept;
void atomic_wait(const atomic<bool>& atom, bool old = true) noexcept;
void atomic_wait_for(const atomic<bool>& atom, const bool old=true, const uint64_t wait_ms=0) noexcept;
void atomic_wait_for(const atomic<bool>& atom, bool old = true, const uint64_t wait_ms = 0) noexcept;
//* Sets atomic<bool> to true on construct, sets to false on destruct
class atomic_lock {
atomic<bool>& atom;
bool not_true{}; // defaults to false
public:
atomic_lock(atomic<bool>& atom, bool wait=false);
atomic_lock(atomic<bool>& atom, bool wait = false);
~atomic_lock();
};
//* Read a complete file and return as a string
string readfile(const std::filesystem::path& path, const string& fallback="");
string readfile(const std::filesystem::path& path, const string& fallback = "");
//* Convert a celsius value to celsius, fahrenheit, kelvin or rankin and return tuple with new value and unit.
auto celsius_to(const long long& celsius, const string& scale) -> tuple<long long, string>;

View File

@ -385,7 +385,7 @@ namespace Cpu {
return {percent, seconds, status};
}
auto collect(const bool no_update) -> cpu_info & {
auto collect(bool no_update) -> cpu_info & {
if (Runner::stopping or (no_update and not current_cpu.cpu_percent.at("total").empty()))
return current_cpu;
auto &cpu = current_cpu;
@ -610,7 +610,7 @@ namespace Mem {
}
auto collect(const bool no_update) -> mem_info & {
auto collect(bool no_update) -> mem_info & {
if (Runner::stopping or (no_update and not current_mem.percent.at("used").empty()))
return current_mem;
@ -618,7 +618,7 @@ namespace Mem {
auto show_disks = Config::getB("show_disks");
auto swap_disk = Config::getB("swap_disk");
auto &mem = current_mem;
static const bool snapped = (getenv("BTOP_SNAPPED") != NULL);
static bool snapped = (getenv("BTOP_SNAPPED") != NULL);
int mib[4];
u_int memActive, memWire, cachedMem, freeMem;
@ -803,7 +803,7 @@ namespace Net {
auto operator()() -> struct ifaddrs * { return ifaddr; }
};
auto collect(const bool no_update) -> net_info & {
auto collect(bool no_update) -> net_info & {
auto &net = current_net;
auto &config_iface = Config::getS("net_iface");
auto net_sync = Config::getB("net_sync");
@ -1078,7 +1078,7 @@ namespace Proc {
};
//* Collects and sorts process information from /proc
auto collect(const bool no_update) -> vector<proc_info> & {
auto collect(bool no_update) -> vector<proc_info> & {
const auto &sorting = Config::getS("proc_sorting");
auto reverse = Config::getB("proc_reversed");
const auto &filter = Config::getS("proc_filter");
@ -1088,7 +1088,7 @@ namespace Proc {
const size_t detailed_pid = Config::getI("detailed_pid");
bool should_filter = current_filter != filter;
if (should_filter) current_filter = filter;
const bool sorted_change = (sorting != current_sort or reverse != current_rev or should_filter);
bool sorted_change = (sorting != current_sort or reverse != current_rev or should_filter);
if (sorted_change) {
current_sort = sorting;
current_rev = reverse;

View File

@ -659,7 +659,7 @@ namespace Cpu {
return {percent, seconds, status};
}
auto collect(const bool no_update) -> cpu_info& {
auto collect(bool no_update) -> cpu_info& {
if (Runner::stopping or (no_update and not current_cpu.cpu_percent.at("total").empty())) return current_cpu;
auto& cpu = current_cpu;
@ -806,7 +806,7 @@ namespace Mem {
return totalMem;
}
auto collect(const bool no_update) -> mem_info& {
auto collect(bool no_update) -> mem_info& {
if (Runner::stopping or (no_update and not current_mem.percent.at("used").empty())) return current_mem;
auto show_swap = Config::getB("show_swap");
auto swap_disk = Config::getB("swap_disk");
@ -1324,7 +1324,7 @@ namespace Net {
auto operator()() -> struct ifaddrs* { return ifaddr; }
};
auto collect(const bool no_update) -> net_info& {
auto collect(bool no_update) -> net_info& {
auto& net = current_net;
auto& config_iface = Config::getS("net_iface");
auto net_sync = Config::getB("net_sync");
@ -1612,7 +1612,7 @@ namespace Proc {
}
//* Collects and sorts process information from /proc
auto collect(const bool no_update) -> vector<proc_info>& {
auto collect(bool no_update) -> vector<proc_info>& {
const auto& sorting = Config::getS("proc_sorting");
auto reverse = Config::getB("proc_reversed");
const auto& filter = Config::getS("proc_filter");
@ -1623,7 +1623,7 @@ namespace Proc {
const size_t detailed_pid = Config::getI("detailed_pid");
bool should_filter = current_filter != filter;
if (should_filter) current_filter = filter;
const bool sorted_change = (sorting != current_sort or reverse != current_rev or should_filter);
bool sorted_change = (sorting != current_sort or reverse != current_rev or should_filter);
if (sorted_change) {
current_sort = sorting;
current_rev = reverse;

View File

@ -437,7 +437,7 @@ namespace Cpu {
return {percent, seconds, status};
}
auto collect(const bool no_update) -> cpu_info & {
auto collect(bool no_update) -> cpu_info & {
if (Runner::stopping or (no_update and not current_cpu.cpu_percent.at("total").empty()))
return current_cpu;
auto &cpu = current_cpu;
@ -662,7 +662,7 @@ namespace Mem {
}
}
auto collect(const bool no_update) -> mem_info & {
auto collect(bool no_update) -> mem_info & {
if (Runner::stopping or (no_update and not current_mem.percent.at("used").empty()))
return current_mem;
@ -670,7 +670,7 @@ namespace Mem {
auto show_disks = Config::getB("show_disks");
auto swap_disk = Config::getB("swap_disk");
auto &mem = current_mem;
static const bool snapped = (getenv("BTOP_SNAPPED") != NULL);
static bool snapped = (getenv("BTOP_SNAPPED") != NULL);
vm_statistics64 p;
mach_msg_type_number_t info_size = HOST_VM_INFO64_COUNT;
@ -842,7 +842,7 @@ namespace Net {
auto operator()() -> struct ifaddrs * { return ifaddr; }
};
auto collect(const bool no_update) -> net_info & {
auto collect(bool no_update) -> net_info & {
auto &net = current_net;
auto &config_iface = Config::getS("net_iface");
auto net_sync = Config::getB("net_sync");
@ -1106,7 +1106,7 @@ namespace Proc {
}
//* Collects and sorts process information from /proc
auto collect(const bool no_update) -> vector<proc_info> & {
auto collect(bool no_update) -> vector<proc_info> & {
const auto &sorting = Config::getS("proc_sorting");
auto reverse = Config::getB("proc_reversed");
const auto &filter = Config::getS("proc_filter");
@ -1116,7 +1116,7 @@ namespace Proc {
const size_t detailed_pid = Config::getI("detailed_pid");
bool should_filter = current_filter != filter;
if (should_filter) current_filter = filter;
const bool sorted_change = (sorting != current_sort or reverse != current_rev or should_filter);
bool sorted_change = (sorting != current_sort or reverse != current_rev or should_filter);
if (sorted_change) {
current_sort = sorting;
current_rev = reverse;