mirror of https://github.com/aristocratos/btop.git
Switched from map to unordered_map where possible
This commit is contained in:
parent
9b837535bd
commit
806045c0a6
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
DOCDIR ?= $(PREFIX)/share/btop/doc
|
DOCDIR ?= $(PREFIX)/share/btop/doc
|
||||||
CXX = g++
|
CXX = g++
|
||||||
override CXXFLAGS += -std=c++20 -pthread -Wall -Wextra
|
override CXXFLAGS += -std=c++20 -O3 -pthread -Wall -Wextra -pedantic
|
||||||
INCLUDES = -I./src
|
INCLUDES = -I./src
|
||||||
|
|
||||||
btop: btop.cpp
|
btop: btop.cpp
|
||||||
|
|
53
btop.cpp
53
btop.cpp
|
@ -18,6 +18,7 @@ tab-size = 4
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <future>
|
#include <future>
|
||||||
|
@ -45,14 +46,14 @@ tab-size = 4
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using std::string, std::vector, std::map, std::atomic, std::endl, std::cout, std::views::iota;
|
using std::string, std::vector, std::array, std::map, std::atomic, std::endl, std::cout, std::views::iota;
|
||||||
using namespace Tools;
|
using namespace Tools;
|
||||||
|
|
||||||
|
|
||||||
//? ------------------------------------------------- GLOBALS ---------------------------------------------------------
|
//? ------------------------------------------------- GLOBALS ---------------------------------------------------------
|
||||||
|
|
||||||
namespace Global {
|
namespace Global {
|
||||||
const vector<vector<string>> Banner_src = {
|
const vector<array<string, 2>> Banner_src = {
|
||||||
{"#E62525", "██████╗ ████████╗ ██████╗ ██████╗"},
|
{"#E62525", "██████╗ ████████╗ ██████╗ ██████╗"},
|
||||||
{"#CD2121", "██╔══██╗╚══██╔══╝██╔═══██╗██╔══██╗ ██╗ ██╗"},
|
{"#CD2121", "██╔══██╗╚══██╔══╝██╔═══██╗██╔══██╗ ██╗ ██╗"},
|
||||||
{"#B31D1D", "██████╔╝ ██║ ██║ ██║██████╔╝ ██████╗██████╗"},
|
{"#B31D1D", "██████╔╝ ██║ ██║ ██║██████╔╝ ██████╗██████╗"},
|
||||||
|
@ -64,7 +65,7 @@ namespace Global {
|
||||||
const string Version = "0.0.1";
|
const string Version = "0.0.1";
|
||||||
|
|
||||||
string banner;
|
string banner;
|
||||||
uint banner_width;
|
const uint banner_width = 49;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,22 +91,16 @@ void argumentParser(int argc, char **argv){
|
||||||
}
|
}
|
||||||
|
|
||||||
//* Generate the btop++ banner
|
//* Generate the btop++ banner
|
||||||
auto createBanner(){
|
string createBanner(){
|
||||||
struct out_vals {
|
|
||||||
uint w;
|
|
||||||
string s;
|
|
||||||
};
|
|
||||||
size_t z = 0;
|
size_t z = 0;
|
||||||
uint width=0, new_len=0;
|
|
||||||
string b_color, bg, fg, out, oc, letter;
|
string b_color, bg, fg, out, oc, letter;
|
||||||
bool truecolor = Config::getB("truecolor");
|
bool truecolor = Config::getB("truecolor");
|
||||||
int bg_i;
|
int bg_i;
|
||||||
for (auto line: Global::Banner_src) {
|
for (auto line: Global::Banner_src) {
|
||||||
if ((new_len = ulen(line[1])) > width) width = new_len;
|
|
||||||
fg = Theme::hex_to_color(line[0], !truecolor);
|
fg = Theme::hex_to_color(line[0], !truecolor);
|
||||||
bg_i = 120-z*12;
|
bg_i = 120-z*12;
|
||||||
bg = Theme::dec_to_color(bg_i, bg_i, bg_i, !truecolor);
|
bg = Theme::dec_to_color(bg_i, bg_i, bg_i, !truecolor);
|
||||||
for (uint i = 0; i < line[1].size(); i += 3) {
|
for (size_t i = 0; i < line[1].size(); i += 3) {
|
||||||
if (line[1][i] == ' '){
|
if (line[1][i] == ' '){
|
||||||
letter = ' ';
|
letter = ' ';
|
||||||
i -= 2;
|
i -= 2;
|
||||||
|
@ -117,12 +112,11 @@ auto createBanner(){
|
||||||
out += letter;
|
out += letter;
|
||||||
oc = b_color;
|
oc = b_color;
|
||||||
}
|
}
|
||||||
z++;
|
if (++z < Global::Banner_src.size()) out += Mv::l(ulen(line[1])) + Mv::d(1);
|
||||||
if (z < Global::Banner_src.size()) out += Mv::l(new_len) + Mv::d(1);
|
|
||||||
}
|
}
|
||||||
out += Mv::r(18 - Global::Version.size()) + Fx::i + Theme::dec_to_color(0,0,0, !truecolor, "bg") +
|
out += Mv::r(18 - Global::Version.size()) + Fx::i + Theme::dec_to_color(0,0,0, !truecolor, "bg") +
|
||||||
Theme::dec_to_color(150, 150, 150, !truecolor) + "v" + Global::Version + Fx::reset;
|
Theme::dec_to_color(150, 150, 150, !truecolor) + "v" + Global::Version + Fx::ui;
|
||||||
return out_vals {width, out};
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -171,9 +165,7 @@ int main(int argc, char **argv){
|
||||||
Theme::set(Global::Default_theme);
|
Theme::set(Global::Default_theme);
|
||||||
|
|
||||||
//? Create the btop++ banner
|
//? Create the btop++ banner
|
||||||
auto [banner_width, banner] = createBanner();
|
Global::banner = createBanner();
|
||||||
Global::banner_width = move(banner_width);
|
|
||||||
Global::banner = move(banner);
|
|
||||||
|
|
||||||
|
|
||||||
//* ------------------------------------------------ TESTING ------------------------------------------------------
|
//* ------------------------------------------------ TESTING ------------------------------------------------------
|
||||||
|
@ -190,7 +182,7 @@ int main(int argc, char **argv){
|
||||||
|
|
||||||
cout << Mv::r(Term::width / 2 - Global::banner_width / 2) << Global::banner << endl;
|
cout << Mv::r(Term::width / 2 - Global::banner_width / 2) << Global::banner << endl;
|
||||||
// cout << string(Term::width - 1, '-') << endl;
|
// cout << string(Term::width - 1, '-') << endl;
|
||||||
int ill;
|
int ill = 0;
|
||||||
for (int i : iota(0, (int)Term::width)){
|
for (int i : iota(0, (int)Term::width)){
|
||||||
ill = (i <= (int)Term::width / 2) ? i : ill - 1;
|
ill = (i <= (int)Term::width / 2) ? i : ill - 1;
|
||||||
cout << Theme::g("used")[ill] << "-";
|
cout << Theme::g("used")[ill] << "-";
|
||||||
|
@ -198,8 +190,7 @@ int main(int argc, char **argv){
|
||||||
cout << Fx::reset << endl;
|
cout << Fx::reset << endl;
|
||||||
|
|
||||||
//* Test theme
|
//* Test theme
|
||||||
|
if (false) {
|
||||||
if (true) {
|
|
||||||
cout << "Theme generation took " << time_ms() - thts << "ms" << endl;
|
cout << "Theme generation took " << time_ms() - thts << "ms" << endl;
|
||||||
|
|
||||||
cout << "Colors:" << endl;
|
cout << "Colors:" << endl;
|
||||||
|
@ -282,7 +273,6 @@ int main(int argc, char **argv){
|
||||||
uint64_t tsl, timestamp2;
|
uint64_t tsl, timestamp2;
|
||||||
uint timer = 2000;
|
uint timer = 2000;
|
||||||
bool filtering = false;
|
bool filtering = false;
|
||||||
vector<string> sorting;
|
|
||||||
bool reversing = false;
|
bool reversing = false;
|
||||||
int sortint = Proc::sort_map["cpu lazy"];
|
int sortint = Proc::sort_map["cpu lazy"];
|
||||||
vector<string> greyscale;
|
vector<string> greyscale;
|
||||||
|
@ -303,19 +293,19 @@ int main(int argc, char **argv){
|
||||||
while (key != "q") {
|
while (key != "q") {
|
||||||
timestamp = time_ms();
|
timestamp = time_ms();
|
||||||
tsl = timestamp + timer;
|
tsl = timestamp + timer;
|
||||||
auto plist = Proc::collect(Proc::sort_vector[sortint], reversing, filter);
|
auto plist = Proc::collect(Proc::sort_array[sortint], reversing, filter);
|
||||||
timestamp2 = time_ms();
|
timestamp2 = time_ms();
|
||||||
timestamp = timestamp2 - timestamp;
|
timestamp = timestamp2 - timestamp;
|
||||||
ostring.clear();
|
ostring.clear();
|
||||||
lc = 0;
|
lc = 0;
|
||||||
filter_cur = (filtering) ? Fx::bl + "█" + Fx::reset : "";
|
filter_cur = (filtering) ? Fx::bl + "█" + Fx::reset : "";
|
||||||
ostring = Mv::save + Mv::u(2) + Mv::r(20) + trans(rjust("Filter: " + filter + filter_cur + string(Term::width / 3, ' ') +
|
ostring = Mv::save + Mv::u(2) + Mv::r(20) + trans(rjust("Filter: " + filter + filter_cur + string(Term::width / 3, ' ') +
|
||||||
"Sorting: " + string(Proc::sort_vector[sortint]), Term::width - 25, true, filtering)) + Mv::restore;
|
"Sorting: " + string(Proc::sort_array[sortint]), Term::width - 25, true, filtering)) + Mv::restore;
|
||||||
|
|
||||||
for (Proc::proc_info& procs : plist){
|
for (auto& p : plist){
|
||||||
ostring += Mv::r(1) + greyscale[lc] + rjust(to_string(procs.pid), 8) + " " + ljust(procs.name, 16) + " " + ljust(procs.cmd, Term::width - 66, true) + " " +
|
ostring += Mv::r(1) + greyscale[lc] + rjust(to_string(p.pid), 8) + " " + ljust(p.name, 16) + " " + ljust(p.cmd, Term::width - 66, true) + " " +
|
||||||
rjust(to_string(procs.threads), 5) + " " + ljust(procs.user, 10) + " " + rjust(floating_humanizer(procs.mem, true), 5) + string(11, ' ');
|
rjust(to_string(p.threads), 5) + " " + ljust(p.user, 10) + " " + rjust(floating_humanizer(p.mem, true), 5) + string(11, ' ');
|
||||||
ostring += (procs.cpu_p > 100) ? rjust(to_string(procs.cpu_p), 3) + " " : rjust(to_string(procs.cpu_p), 4);
|
ostring += (p.cpu_p > 100) ? rjust(to_string(p.cpu_p), 3) + " " : rjust(to_string(p.cpu_p), 4);
|
||||||
ostring += "\n";
|
ostring += "\n";
|
||||||
if (lc++ > Term::height - 21) break;
|
if (lc++ > Term::height - 21) break;
|
||||||
}
|
}
|
||||||
|
@ -326,18 +316,17 @@ int main(int argc, char **argv){
|
||||||
while (time_ms() < tsl) {
|
while (time_ms() < tsl) {
|
||||||
if (Input::poll(tsl - time_ms())) key = Input::get();
|
if (Input::poll(tsl - time_ms())) key = Input::get();
|
||||||
else { key.clear() ; continue; }
|
else { key.clear() ; continue; }
|
||||||
// if (key != "") continue;
|
|
||||||
if (filtering) {
|
if (filtering) {
|
||||||
if (key == "enter") filtering = false;
|
if (key == "enter") filtering = false;
|
||||||
else if (key == "backspace") {if (!filter.empty()) filter = uresize(filter, ulen(filter) - 1);}
|
else if (key == "backspace") {if (!filter.empty()) filter = uresize(filter, ulen(filter) - 1);}
|
||||||
else if (key == "space") filter.push_back(' ');
|
else if (key == "space") filter.push_back(' ');
|
||||||
else if (ulen(key) == 1 ) filter.append(key);
|
else if (ulen(key) == 1 ) filter.append(key);
|
||||||
else { key.clear() ; continue; }
|
else { key.clear(); continue; }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (key == "q") break;
|
else if (key == "q") break;
|
||||||
else if (key == "left") { if (--sortint < 0) sortint = (int)Proc::sort_vector.size() - 1; }
|
else if (key == "left") { if (--sortint < 0) sortint = (int)Proc::sort_array.size() - 1; }
|
||||||
else if (key == "right") { if (++sortint > (int)Proc::sort_vector.size() - 1) sortint = 0; }
|
else if (key == "right") { if (++sortint > (int)Proc::sort_array.size() - 1) sortint = 0; }
|
||||||
else if (key == "f") filtering = true;
|
else if (key == "f") filtering = true;
|
||||||
else if (key == "r") reversing = !reversing;
|
else if (key == "r") reversing = !reversing;
|
||||||
else if (key == "delete") filter.clear();
|
else if (key == "delete") filter.clear();
|
||||||
|
|
|
@ -21,11 +21,11 @@ tab-size = 4
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include <btop_tools.h>
|
#include <btop_tools.h>
|
||||||
|
|
||||||
using std::string, std::vector, std::map;
|
using std::string, std::vector, std::unordered_map;
|
||||||
using namespace Tools;
|
using namespace Tools;
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ namespace Config {
|
||||||
|
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
map<string, string> strings = {
|
unordered_map<string, string> strings = {
|
||||||
{"color_theme", "Default"},
|
{"color_theme", "Default"},
|
||||||
{"shown_boxes", "cpu mem net proc"},
|
{"shown_boxes", "cpu mem net proc"},
|
||||||
{"proc_sorting", "cpu lazy"},
|
{"proc_sorting", "cpu lazy"},
|
||||||
|
@ -52,7 +52,7 @@ namespace Config {
|
||||||
{"net_iface", ""},
|
{"net_iface", ""},
|
||||||
{"log_level", "WARNING"}
|
{"log_level", "WARNING"}
|
||||||
};
|
};
|
||||||
map<string, bool> bools = {
|
unordered_map<string, bool> bools = {
|
||||||
{"theme_background", true},
|
{"theme_background", true},
|
||||||
{"truecolor", true},
|
{"truecolor", true},
|
||||||
{"proc_reversed", false},
|
{"proc_reversed", false},
|
||||||
|
@ -84,12 +84,12 @@ namespace Config {
|
||||||
{"show_battery", true},
|
{"show_battery", true},
|
||||||
{"show_init", false}
|
{"show_init", false}
|
||||||
};
|
};
|
||||||
map<string, int> ints = {
|
unordered_map<string, int> ints = {
|
||||||
{"update_ms", 2000},
|
{"update_ms", 2000},
|
||||||
{"proc_update_mult", 2},
|
{"proc_update_mult", 2},
|
||||||
{"tree_depth", 3}
|
{"tree_depth", 3}
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
//* Return config value <name> as a bool
|
//* Return config value <name> as a bool
|
||||||
bool& getB(string name){
|
bool& getB(string name){
|
||||||
|
@ -128,6 +128,6 @@ namespace Config {
|
||||||
(void)source;
|
(void)source;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -20,17 +20,18 @@ tab-size = 4
|
||||||
#define _btop_globs_included_ 1
|
#define _btop_globs_included_ 1
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
using std::string, std::vector, std::map, std::atomic;
|
using std::string, std::vector, std::unordered_map, std::array, std::atomic;
|
||||||
|
|
||||||
namespace Global {
|
namespace Global {
|
||||||
|
|
||||||
atomic<bool> stop_all(false);
|
atomic<bool> stop_all(false);
|
||||||
|
|
||||||
const map<string, string> Default_theme = {
|
const unordered_map<string, string> Default_theme = {
|
||||||
{ "main_bg", "#00" },
|
{ "main_bg", "#00" },
|
||||||
{ "main_fg", "#cc" },
|
{ "main_fg", "#cc" },
|
||||||
{ "title", "#ee" },
|
{ "title", "#ee" },
|
||||||
|
@ -75,7 +76,7 @@ namespace Global {
|
||||||
{ "process_end", "#d45454" }
|
{ "process_end", "#d45454" }
|
||||||
};
|
};
|
||||||
|
|
||||||
const map<string, map<string, vector<string>>> Menus = {
|
const unordered_map<string, unordered_map<string, vector<string>>> Menus = {
|
||||||
{ "options", {
|
{ "options", {
|
||||||
{ "normal", {
|
{ "normal", {
|
||||||
"┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐",
|
"┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐",
|
||||||
|
@ -115,8 +116,8 @@ namespace Global {
|
||||||
};
|
};
|
||||||
|
|
||||||
//? Units for floating_humanizer function
|
//? Units for floating_humanizer function
|
||||||
const vector<string> Units_bit = {"bit", "Kib", "Mib", "Gib", "Tib", "Pib", "Eib", "Zib", "Yib", "Bib", "GEb"};
|
const array<string, 11> Units_bit = {"bit", "Kib", "Mib", "Gib", "Tib", "Pib", "Eib", "Zib", "Yib", "Bib", "GEb"};
|
||||||
const vector<string> Units_byte = {"Byte", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", "BiB", "GEB"};
|
const array<string, 11> Units_byte = {"Byte", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", "BiB", "GEB"};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@ namespace Symbols {
|
||||||
const string div_up = "┬";
|
const string div_up = "┬";
|
||||||
const string div_down = "┴";
|
const string div_down = "┴";
|
||||||
|
|
||||||
const vector<string> superscript = { "⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹" };
|
const array<string, 10> superscript = { "⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹" };
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,13 +20,13 @@ tab-size = 4
|
||||||
#define _btop_input_included_ 1
|
#define _btop_input_included_ 1
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <unordered_map>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <btop_globs.h>
|
#include <btop_globs.h>
|
||||||
#include <btop_tools.h>
|
#include <btop_tools.h>
|
||||||
|
|
||||||
using std::string, std::map, std::cin;
|
using std::string, std::unordered_map, std::cin;
|
||||||
using namespace Tools;
|
using namespace Tools;
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ using namespace Tools;
|
||||||
namespace Input {
|
namespace Input {
|
||||||
namespace {
|
namespace {
|
||||||
//* Map for translating key codes to readable values
|
//* Map for translating key codes to readable values
|
||||||
const map<string, string> Key_escapes = {
|
const unordered_map<string, string> Key_escapes = {
|
||||||
{"\033", "escape"},
|
{"\033", "escape"},
|
||||||
{"\n", "enter"},
|
{"\n", "enter"},
|
||||||
{" ", "space"},
|
{" ", "space"},
|
||||||
|
@ -69,7 +69,7 @@ namespace Input {
|
||||||
{"[23~", "f11"},
|
{"[23~", "f11"},
|
||||||
{"[24~", "f12"}
|
{"[24~", "f12"}
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
//* Last entered key
|
//* Last entered key
|
||||||
string last = "";
|
string last = "";
|
||||||
|
@ -108,6 +108,6 @@ namespace Input {
|
||||||
last.clear();
|
last.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -21,7 +21,8 @@ tab-size = 4
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <array>
|
||||||
|
#include <unordered_map>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
@ -34,7 +35,7 @@ tab-size = 4
|
||||||
#include <btop_tools.h>
|
#include <btop_tools.h>
|
||||||
|
|
||||||
|
|
||||||
using std::string, std::vector, std::map, std::ifstream, std::atomic, std::numeric_limits, std::streamsize;
|
using std::string, std::vector, std::array, std::ifstream, std::atomic, std::numeric_limits, std::streamsize, std::unordered_map;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using namespace Tools;
|
using namespace Tools;
|
||||||
|
|
||||||
|
@ -65,8 +66,8 @@ namespace Proc {
|
||||||
string name, cmd, user;
|
string name, cmd, user;
|
||||||
uint64_t cpu_t = 0, cpu_s = 0;
|
uint64_t cpu_t = 0, cpu_s = 0;
|
||||||
};
|
};
|
||||||
map<uint, p_cache> cache;
|
unordered_map<uint, p_cache> cache;
|
||||||
map<string, string> uid_user;
|
unordered_map<string, string> uid_user;
|
||||||
fs::path passwd_path;
|
fs::path passwd_path;
|
||||||
fs::file_time_type passwd_time;
|
fs::file_time_type passwd_time;
|
||||||
uint counter = 0;
|
uint counter = 0;
|
||||||
|
@ -76,7 +77,7 @@ namespace Proc {
|
||||||
|
|
||||||
atomic<bool> stop (false);
|
atomic<bool> stop (false);
|
||||||
atomic<bool> running (false);
|
atomic<bool> running (false);
|
||||||
vector<string> sort_vector = {
|
array<string, 8> sort_array = {
|
||||||
"pid",
|
"pid",
|
||||||
"name",
|
"name",
|
||||||
"command",
|
"command",
|
||||||
|
@ -86,7 +87,7 @@ namespace Proc {
|
||||||
"cpu direct",
|
"cpu direct",
|
||||||
"cpu lazy",
|
"cpu lazy",
|
||||||
};
|
};
|
||||||
map<string, uint> sort_map;
|
unordered_map<string, uint> sort_map;
|
||||||
|
|
||||||
//* proc_info: pid, name, cmd, threads, user, mem, cpu_p, cpu_c
|
//* proc_info: pid, name, cmd, threads, user, mem, cpu_p, cpu_c
|
||||||
struct proc_info {
|
struct proc_info {
|
||||||
|
@ -146,8 +147,8 @@ namespace Proc {
|
||||||
return procs;
|
return procs;
|
||||||
}
|
}
|
||||||
pid_str = fs::path(d.path()).filename();
|
pid_str = fs::path(d.path()).filename();
|
||||||
cpu = 0.0;
|
cpu = 0.0; cpu_s = 0.0; cpu_t = 0;
|
||||||
rss_mem = 0;
|
rss_mem = 0; threads = 0;
|
||||||
new_cache = false;
|
new_cache = false;
|
||||||
if (d.is_directory() && isdigit(pid_str[0])) {
|
if (d.is_directory() && isdigit(pid_str[0])) {
|
||||||
pid = stoul(pid_str);
|
pid = stoul(pid_str);
|
||||||
|
@ -284,7 +285,7 @@ namespace Proc {
|
||||||
|
|
||||||
//* Clear dead processes from cache at a regular interval
|
//* Clear dead processes from cache at a regular interval
|
||||||
if (++counter >= 10000 || (filter.empty() && cache.size() > procs.size() + 100)) {
|
if (++counter >= 10000 || (filter.empty() && cache.size() > procs.size() + 100)) {
|
||||||
map<uint, p_cache> r_cache;
|
unordered_map<uint, p_cache> r_cache;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
for (auto& p : c_pids) r_cache[p] = cache[p];
|
for (auto& p : c_pids) r_cache[p] = cache[p];
|
||||||
cache = move(r_cache);
|
cache = move(r_cache);
|
||||||
|
@ -301,9 +302,9 @@ namespace Proc {
|
||||||
tstamp = time_ms();
|
tstamp = time_ms();
|
||||||
passwd_path = (fs::exists(fs::path("/etc/passwd"))) ? fs::path("/etc/passwd") : passwd_path;
|
passwd_path = (fs::exists(fs::path("/etc/passwd"))) ? fs::path("/etc/passwd") : passwd_path;
|
||||||
uint i = 0;
|
uint i = 0;
|
||||||
for (auto& item : sort_vector) sort_map[item] = i++;
|
for (auto& item : sort_array) sort_map[item] = i++;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,14 @@ tab-size = 4
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <unordered_map>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
|
|
||||||
#include <btop_globs.h>
|
#include <btop_globs.h>
|
||||||
#include <btop_tools.h>
|
#include <btop_tools.h>
|
||||||
#include <btop_config.h>
|
#include <btop_config.h>
|
||||||
|
|
||||||
using std::string, std::round, std::vector, std::map, std::stoi, std::views::iota, std::array;
|
using std::string, std::round, std::vector, std::map, std::stoi, std::views::iota, std::array, std::unordered_map;
|
||||||
using namespace Tools;
|
using namespace Tools;
|
||||||
|
|
||||||
namespace Theme {
|
namespace Theme {
|
||||||
|
@ -98,16 +99,16 @@ namespace Theme {
|
||||||
else return pre + to_string(r) + ";" + to_string(g) + ";" + to_string(b) + "m";
|
else return pre + to_string(r) + ";" + to_string(g) + ";" + to_string(b) + "m";
|
||||||
}
|
}
|
||||||
|
|
||||||
//* Return a map of "r", "g", "b", 0-255 values for a 24-bit color escape string
|
//* Return an array of red, green and blue, 0-255 values for a 24-bit color escape string
|
||||||
map<string, int> esc_to_rgb(string c_string){
|
auto esc_to_rgb(string c_string){
|
||||||
map<string, int> rgb = {{"r", 0}, {"g", 0}, {"b", 0}};
|
array<int, 3> rgb = {-1, -1, -1};
|
||||||
if (c_string.size() >= 14){
|
if (c_string.size() >= 14){
|
||||||
c_string.erase(0, 7);
|
c_string.erase(0, 7);
|
||||||
auto c_split = ssplit(c_string, ";");
|
auto c_split = ssplit(c_string, ";");
|
||||||
if (c_split.size() == 3){
|
if (c_split.size() == 3){
|
||||||
rgb["r"] = stoi(c_split[0]);
|
rgb[0] = stoi(c_split[0]);
|
||||||
rgb["g"] = stoi(c_split[1]);
|
rgb[1] = stoi(c_split[1]);
|
||||||
rgb["b"] = stoi(c_split[2].erase(c_split[2].size()));
|
rgb[2] = stoi(c_split[2].erase(c_split[2].size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rgb;
|
return rgb;
|
||||||
|
@ -115,9 +116,9 @@ namespace Theme {
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
map<string, string> colors;
|
unordered_map<string, string> colors;
|
||||||
map<string, array<int, 3>> rgbs;
|
unordered_map<string, array<int, 3>> rgbs;
|
||||||
map<string, array<string, 101>> gradients;
|
unordered_map<string, array<string, 101>> gradients;
|
||||||
|
|
||||||
//* Convert hex color to a array of decimals
|
//* Convert hex color to a array of decimals
|
||||||
array<int, 3> hex_to_dec(string hexa){
|
array<int, 3> hex_to_dec(string hexa){
|
||||||
|
@ -141,7 +142,7 @@ namespace Theme {
|
||||||
}
|
}
|
||||||
|
|
||||||
//* Generate colors and rgb decimal vectors for the theme
|
//* Generate colors and rgb decimal vectors for the theme
|
||||||
void generateColors(map<string, string>& source){
|
void generateColors(unordered_map<string, string>& source){
|
||||||
vector<string> t_rgb;
|
vector<string> t_rgb;
|
||||||
string depth;
|
string depth;
|
||||||
colors.clear(); rgbs.clear();
|
colors.clear(); rgbs.clear();
|
||||||
|
@ -209,7 +210,7 @@ namespace Theme {
|
||||||
|
|
||||||
|
|
||||||
//* Set current theme using <source> map
|
//* Set current theme using <source> map
|
||||||
void set(map<string, string> source){
|
void set(unordered_map<string, string> source){
|
||||||
generateColors(source);
|
generateColors(source);
|
||||||
generateGradients();
|
generateGradients();
|
||||||
Term::fg = colors.at("main_fg");
|
Term::fg = colors.at("main_fg");
|
||||||
|
@ -222,16 +223,16 @@ namespace Theme {
|
||||||
return colors.at(name);
|
return colors.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//* Return vector of escape codes for color gradient <name>
|
//* Return array of escape codes for color gradient <name>
|
||||||
auto g(string name){
|
auto g(string name){
|
||||||
return gradients.at(name);
|
return gradients.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//* Return vector of red, green and blue in decimal for color <name>
|
//* Return array of red, green and blue in decimal for color <name>
|
||||||
auto dec(string name){
|
auto dec(string name){
|
||||||
return rgbs.at(name);
|
return rgbs.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -33,7 +33,7 @@ tab-size = 4
|
||||||
|
|
||||||
#include <btop_globs.h>
|
#include <btop_globs.h>
|
||||||
|
|
||||||
using std::string, std::vector, std::map, std::regex, std::max, std::to_string, std::cin;
|
using std::string, std::vector, std::regex, std::max, std::to_string, std::cin;
|
||||||
|
|
||||||
//? ------------------------------------------------- NAMESPACES ------------------------------------------------------
|
//? ------------------------------------------------- NAMESPACES ------------------------------------------------------
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ namespace Fx {
|
||||||
string uncolor(string& s){
|
string uncolor(string& s){
|
||||||
return regex_replace(s, color_regex, "");
|
return regex_replace(s, color_regex, "");
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
//* Collection of escape codes and functions for cursor manipulation
|
//* Collection of escape codes and functions for cursor manipulation
|
||||||
namespace Mv {
|
namespace Mv {
|
||||||
|
@ -106,7 +106,7 @@ namespace Mv {
|
||||||
|
|
||||||
//* Restore saved cursor postion
|
//* Restore saved cursor postion
|
||||||
const string restore = Fx::e + "u";
|
const string restore = Fx::e + "u";
|
||||||
};
|
}
|
||||||
|
|
||||||
//* Collection of escape codes and functions for terminal manipulation
|
//* Collection of escape codes and functions for terminal manipulation
|
||||||
namespace Term {
|
namespace Term {
|
||||||
|
@ -138,7 +138,7 @@ namespace Term {
|
||||||
height = w.ws_row;
|
height = w.ws_row;
|
||||||
return resized;
|
return resized;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
//* Hide terminal cursor
|
//* Hide terminal cursor
|
||||||
|
@ -214,7 +214,7 @@ namespace Term {
|
||||||
initialized = false;
|
initialized = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
//? --------------------------------------------------- FUNCTIONS -----------------------------------------------------
|
//? --------------------------------------------------- FUNCTIONS -----------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue