summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/btop.cpp99
-rw-r--r--src/btop_config.cpp44
-rw-r--r--src/btop_config.hpp39
-rw-r--r--src/btop_draw.cpp219
-rw-r--r--src/btop_draw.hpp28
-rw-r--r--src/btop_input.cpp36
-rw-r--r--src/btop_input.hpp4
-rw-r--r--src/btop_menu.cpp90
-rw-r--r--src/btop_menu.hpp14
-rw-r--r--src/btop_shared.cpp14
-rw-r--r--src/btop_shared.hpp106
-rw-r--r--src/btop_theme.cpp75
-rw-r--r--src/btop_theme.hpp6
-rw-r--r--src/btop_tools.cpp252
-rw-r--r--src/btop_tools.hpp67
-rw-r--r--src/freebsd/btop_collect.cpp160
-rw-r--r--src/linux/btop_collect.cpp147
-rw-r--r--src/osx/btop_collect.cpp103
-rw-r--r--src/osx/sensors.cpp6
-rw-r--r--src/osx/sensors.hpp2
-rw-r--r--src/osx/smc.cpp38
-rw-r--r--src/osx/smc.hpp4
22 files changed, 781 insertions, 772 deletions
diff --git a/src/btop.cpp b/src/btop.cpp
index 02e6af2..5b58a10 100644
--- a/src/btop.cpp
+++ b/src/btop.cpp
@@ -4,7 +4,7 @@
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@@ -43,18 +43,16 @@ tab-size = 4
#include <semaphore>
#endif
-#include <btop_shared.hpp>
-#include <btop_tools.hpp>
-#include <btop_config.hpp>
-#include <btop_input.hpp>
-#include <btop_theme.hpp>
-#include <btop_draw.hpp>
-#include <btop_menu.hpp>
+#include "btop_shared.hpp"
+#include "btop_tools.hpp"
+#include "btop_config.hpp"
+#include "btop_input.hpp"
+#include "btop_theme.hpp"
+#include "btop_draw.hpp"
+#include "btop_menu.hpp"
using std::atomic;
using std::cout;
-using std::endl;
-using std::endl;
using std::flush;
using std::min;
using std::string;
@@ -63,7 +61,6 @@ using std::to_string;
using std::vector;
namespace fs = std::filesystem;
-namespace rng = std::ranges;
using namespace Tools;
using namespace std::chrono_literals;
@@ -96,9 +93,9 @@ namespace Global {
string exit_error_msg;
atomic<bool> thread_exception (false);
- bool debuginit{}; // defaults to false
- bool debug{}; // defaults to false
- bool utf_force{}; // defaults to false
+ bool debuginit{}; // defaults to false
+ bool debug{}; // defaults to false
+ bool utf_force{}; // defaults to false
uint64_t start_time;
@@ -108,8 +105,8 @@ namespace Global {
atomic<bool> should_sleep (false);
atomic<bool> _runner_started (false);
- bool arg_tty{}; // defaults to false
- bool arg_low_color{}; // defaults to false
+ bool arg_tty{}; // defaults to false
+ bool arg_low_color{}; // defaults to false
int arg_preset = -1;
}
@@ -249,14 +246,14 @@ void clean_quit(int sig) {
Runner::stop();
if (Global::_runner_started) {
#ifdef __APPLE__
- if (pthread_join(Runner::runner_id, NULL) != 0) {
+ if (pthread_join(Runner::runner_id, nullptr) != 0) {
Logger::warning("Failed to join _runner thread on exit!");
pthread_cancel(Runner::runner_id);
}
#else
struct timespec ts;
ts.tv_sec = 5;
- if (pthread_timedjoin_np(Runner::runner_id, NULL, &ts) != 0) {
+ if (pthread_timedjoin_np(Runner::runner_id, nullptr, &ts) != 0) {
Logger::warning("Failed to join _runner thread on exit!");
pthread_cancel(Runner::runner_id);
}
@@ -363,14 +360,14 @@ namespace Runner {
pthread_mutex_t& pt_mutex;
public:
int status;
- thread_lock(pthread_mutex_t& mtx) : pt_mutex(mtx) {
- pthread_mutex_init(&pt_mutex, NULL);
- status = pthread_mutex_lock(&pt_mutex);
- }
- ~thread_lock() {
- if (status == 0)
- pthread_mutex_unlock(&pt_mutex);
- }
+ thread_lock(pthread_mutex_t& mtx) : pt_mutex(mtx) {
+ pthread_mutex_init(&pt_mutex, nullptr);
+ status = pthread_mutex_lock(&pt_mutex);
+ }
+ ~thread_lock() {
+ if (status == 0)
+ pthread_mutex_unlock(&pt_mutex);
+ }
};
//* Wrapper for raising priviliges when using SUID bit
@@ -378,18 +375,18 @@ namespace Runner {
int status = -1;
public:
gain_priv() {
- if (Global::real_uid != Global::set_uid)
- this->status = seteuid(Global::set_uid);
+ if (Global::real_uid != Global::set_uid)
+ this->status = seteuid(Global::set_uid);
}
~gain_priv() {
- if (status == 0)
- status = seteuid(Global::real_uid);
+ if (status == 0)
+ status = seteuid(Global::real_uid);
}
};
string output;
string empty_bg;
- bool pause_output{}; // defaults to false
+ bool pause_output{}; // defaults to false
sigset_t mask;
pthread_t runner_id;
pthread_mutex_t mtx;
@@ -454,14 +451,14 @@ namespace Runner {
}
//? ------------------------------- Secondary thread: async launcher and drawing ----------------------------------
- void * _runner(void *) {
+ void * _runner(void *) {
//? Block some signals in this thread to avoid deadlock from any signal handlers trying to stop this thread
sigemptyset(&mask);
// sigaddset(&mask, SIGINT);
// sigaddset(&mask, SIGTSTP);
sigaddset(&mask, SIGWINCH);
sigaddset(&mask, SIGTERM);
- pthread_sigmask(SIG_BLOCK, &mask, NULL);
+ pthread_sigmask(SIG_BLOCK, &mask, nullptr);
//? pthread_mutex_lock to lock thread and monitor health from main thread
thread_lock pt_lck(mtx);
@@ -549,7 +546,7 @@ namespace Runner {
if (Global::debug) debug_timer("cpu", draw_done);
}
catch (const std::exception& e) {
- throw std::runtime_error("Cpu:: -> " + string{e.what()});
+ throw std::runtime_error("Cpu:: -> " + string{e.what()});
}
}
@@ -586,7 +583,7 @@ namespace Runner {
if (Global::debug) debug_timer("mem", draw_done);
}
catch (const std::exception& e) {
- throw std::runtime_error("Mem:: -> " + string{e.what()});
+ throw std::runtime_error("Mem:: -> " + string{e.what()});
}
}
@@ -606,7 +603,7 @@ namespace Runner {
if (Global::debug) debug_timer("net", draw_done);
}
catch (const std::exception& e) {
- throw std::runtime_error("Net:: -> " + string{e.what()});
+ throw std::runtime_error("Net:: -> " + string{e.what()});
}
}
@@ -626,13 +623,13 @@ namespace Runner {
if (Global::debug) debug_timer("proc", draw_done);
}
catch (const std::exception& e) {
- throw std::runtime_error("Proc:: -> " + string{e.what()});
+ throw std::runtime_error("Proc:: -> " + string{e.what()});
}
}
}
catch (const std::exception& e) {
- Global::exit_error_msg = "Exception in runner thread -> " + string{e.what()};
+ Global::exit_error_msg = "Exception in runner thread -> " + string{e.what()};
Global::thread_exception = true;
Input::interrupt = true;
stopping = true;
@@ -711,14 +708,14 @@ 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, bool no_update, 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!");
active = false;
// exit(1);
pthread_cancel(Runner::runner_id);
- if (pthread_create(&Runner::runner_id, NULL, &Runner::_runner, NULL) != 0) {
+ if (pthread_create(&Runner::runner_id, nullptr, &Runner::_runner, nullptr) != 0) {
Global::exit_error_msg = "Failed to re-create _runner thread!";
clean_quit(1);
}
@@ -806,7 +803,7 @@ int main(int argc, char **argv) {
//? Setup paths for config, log and user themes
for (const auto& env : {"XDG_CONFIG_HOME", "HOME"}) {
- if (std::getenv(env) != NULL and access(std::getenv(env), W_OK) != -1) {
+ if (std::getenv(env) != nullptr and access(std::getenv(env), W_OK) != -1) {
Config::conf_dir = fs::path(std::getenv(env)) / (((string)env == "HOME") ? ".config/btop" : "btop");
break;
}
@@ -873,17 +870,17 @@ int main(int argc, char **argv) {
}
//? Try to find and set a UTF-8 locale
- if (std::setlocale(LC_ALL, "") != NULL and not s_contains((string)std::setlocale(LC_ALL, ""), ";")
+ if (std::setlocale(LC_ALL, "") != nullptr and not s_contains((string)std::setlocale(LC_ALL, ""), ";")
and str_to_upper(s_replace((string)std::setlocale(LC_ALL, ""), "-", "")).ends_with("UTF8")) {
Logger::debug("Using locale " + (string)std::setlocale(LC_ALL, ""));
}
else {
string found;
- bool set_failure{}; // defaults to false
+ bool set_failure{}; // defaults to false
for (const auto loc_env : array{"LANG", "LC_ALL"}) {
- if (std::getenv(loc_env) != NULL and str_to_upper(s_replace((string)std::getenv(loc_env), "-", "")).ends_with("UTF8")) {
+ if (std::getenv(loc_env) != nullptr and str_to_upper(s_replace((string)std::getenv(loc_env), "-", "")).ends_with("UTF8")) {
found = std::getenv(loc_env);
- if (std::setlocale(LC_ALL, found.c_str()) == NULL) {
+ if (std::setlocale(LC_ALL, found.c_str()) == nullptr) {
set_failure = true;
Logger::warning("Failed to set locale " + found + " continuing anyway.");
}
@@ -896,7 +893,7 @@ int main(int argc, char **argv) {
for (auto& l : ssplit(loc, ';')) {
if (str_to_upper(s_replace(l, "-", "")).ends_with("UTF8")) {
found = l.substr(l.find('=') + 1);
- if (std::setlocale(LC_ALL, found.c_str()) != NULL) {
+ if (std::setlocale(LC_ALL, found.c_str()) != nullptr) {
break;
}
}
@@ -917,10 +914,10 @@ int main(int argc, char **argv) {
if (cur_locale.empty()) {
Logger::warning("No UTF-8 locale detected! Some symbols might not display correctly.");
}
- else if (std::setlocale(LC_ALL, string(cur_locale + ".UTF-8").c_str()) != NULL) {
+ else if (std::setlocale(LC_ALL, string(cur_locale + ".UTF-8").c_str()) != nullptr) {
Logger::debug("Setting LC_ALL=" + cur_locale + ".UTF-8");
}
- else if(std::setlocale(LC_ALL, "en_US.UTF-8") != NULL) {
+ else if(std::setlocale(LC_ALL, "en_US.UTF-8") != nullptr) {
Logger::debug("Setting LC_ALL=en_US.UTF-8");
}
else {
@@ -975,7 +972,7 @@ int main(int argc, char **argv) {
Shared::init();
}
catch (const std::exception& e) {
- Global::exit_error_msg = "Exception in Shared::init() -> " + string{e.what()};
+ Global::exit_error_msg = "Exception in Shared::init() -> " + string{e.what()};
clean_quit(1);
}
@@ -992,7 +989,7 @@ int main(int argc, char **argv) {
//? Start runner thread
Runner::thread_sem_init();
- if (pthread_create(&Runner::runner_id, NULL, &Runner::_runner, NULL) != 0) {
+ if (pthread_create(&Runner::runner_id, nullptr, &Runner::_runner, nullptr) != 0) {
Global::exit_error_msg = "Failed to create _runner thread!";
clean_quit(1);
}
@@ -1087,7 +1084,7 @@ int main(int argc, char **argv) {
}
}
catch (const std::exception& e) {
- Global::exit_error_msg = "Exception in main loop -> " + string{e.what()};
+ Global::exit_error_msg = "Exception in main loop -> " + string{e.what()};
clean_quit(1);
}
diff --git a/src/btop_config.cpp b/src/btop_config.cpp
index 15e6adb..34ae1d5 100644
--- a/src/btop_config.cpp
+++ b/src/btop_config.cpp
@@ -4,7 +4,7 @@
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,14 +17,16 @@ tab-size = 4
*/
#include <array>
-#include <ranges>
#include <atomic>
#include <fstream>
+#include <ranges>
#include <string_view>
-#include <btop_config.hpp>
-#include <btop_shared.hpp>
-#include <btop_tools.hpp>
+#include <fmt/core.h>
+
+#include "btop_config.hpp"
+#include "btop_shared.hpp"
+#include "btop_tools.hpp"
using std::array;
using std::atomic;
@@ -105,7 +107,7 @@ namespace Config {
{"proc_left", "#* Show proc box on left side of screen instead of right."},
- {"proc_filter_kernel", "#* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop)."},
+ {"proc_filter_kernel", "#* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop)."},
{"cpu_graph_upper", "#* Sets the CPU stat shown in upper half of the CPU graph, \"total\" is always available.\n"
"#* Select from a list of detected attributes from the options menu."},
@@ -207,7 +209,7 @@ namespace Config {
{"custom_gpu_name5", "#* Custom gpu5 model name, empty string to disable."},
};
- unordered_flat_map<string, string> strings = {
+ unordered_flat_map<std::string_view, string> strings = {
{"color_theme", "Default"},
{"shown_boxes", "cpu mem net proc"},
{"graph_symbol", "braille"},
@@ -240,9 +242,9 @@ namespace Config {
{"custom_gpu_name4", ""},
{"custom_gpu_name5", ""},
};
- unordered_flat_map<string, string> stringsTmp;
+ unordered_flat_map<std::string_view, string> stringsTmp;
- unordered_flat_map<string, bool> bools = {
+ unordered_flat_map<std::string_view, bool> bools = {
{"theme_background", true},
{"truecolor", true},
{"rounded_corners", true},
@@ -255,7 +257,7 @@ namespace Config {
{"proc_cpu_graphs", true},
{"proc_info_smaps", false},
{"proc_left", false},
- {"proc_filter_kernel", false},
+ {"proc_filter_kernel", false},
{"cpu_invert_lower", true},
{"cpu_single_graph", false},
{"cpu_bottom", false},
@@ -290,9 +292,9 @@ namespace Config {
{"nvml_measure_pcie_speeds", true},
{"gpu_mirror_graph", true},
};
- unordered_flat_map<string, bool> boolsTmp;
+ unordered_flat_map<std::string_view, bool> boolsTmp;
- unordered_flat_map<string, int> ints = {
+ unordered_flat_map<std::string_view, int> ints = {
{"update_ms", 2000},
{"net_download", 100},
{"net_upload", 100},
@@ -303,9 +305,9 @@ namespace Config {
{"proc_selected", 0},
{"proc_last_selected", 0},
};
- unordered_flat_map<string, int> intsTmp;
+ unordered_flat_map<std::string_view, int> intsTmp;
- bool _locked(const string& name) {
+ bool _locked(const std::string_view name) {
atomic_wait(writelock, true);
if (not write_new and rng::find_if(descriptions, [&name](const auto& a) { return a.at(0) == name; }) != descriptions.end())
write_new = true;
@@ -392,7 +394,7 @@ namespace Config {
string validError;
- bool intValid(const string& name, const string& value) {
+ bool intValid(const std::string_view name, const string& value) {
int i_value;
try {
i_value = stoi(value);
@@ -406,7 +408,7 @@ namespace Config {
return false;
}
catch (const std::exception& e) {
- validError = string{e.what()};
+ validError = string{e.what()};
return false;
}
@@ -422,7 +424,7 @@ namespace Config {
return false;
}
- bool stringValid(const string& name, const string& value) {
+ bool stringValid(const std::string_view name, const string& value) {
if (name == "log_level" and not v_contains(Logger::log_levels, value))
validError = "Invalid log_level: " + value;
@@ -430,7 +432,7 @@ namespace Config {
validError = "Invalid graph symbol identifier: " + value;
else if (name.starts_with("graph_symbol_") and (value != "default" and not v_contains(valid_graph_symbols, value)))
- validError = "Invalid graph symbol identifier for" + name + ": " + value;
+ validError = fmt::format("Invalid graph symbol identifier for {}: {}", name, value);
else if (name == "shown_boxes" and not value.empty() and not check_boxes(value))
validError = "Invalid box name(s) in shown_boxes!";
@@ -479,7 +481,7 @@ namespace Config {
return false;
}
- string getAsString(const string& name) {
+ string getAsString(const std::string_view name) {
if (bools.contains(name))
return (bools.at(name) ? "True" : "False");
else if (ints.contains(name))
@@ -489,7 +491,7 @@ namespace Config {
return "";
}
- void flip(const string& name) {
+ void flip(const std::string_view name) {
if (_locked(name)) {
if (boolsTmp.contains(name)) boolsTmp.at(name) = not boolsTmp.at(name);
else boolsTmp.insert_or_assign(name, (not bools.at(name)));
@@ -526,7 +528,7 @@ namespace Config {
boolsTmp.clear();
}
catch (const std::exception& e) {
- Global::exit_error_msg = "Exception during Config::unlock() : " + string{e.what()};
+ Global::exit_error_msg = "Exception during Config::unlock() : " + string{e.what()};
clean_quit(1);
}
diff --git a/src/btop_config.hpp b/src/btop_config.hpp
index d9a9c3a..c7fc993 100644
--- a/src/btop_config.hpp
+++ b/src/btop_config.hpp
@@ -4,7 +4,7 @@
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,9 +20,10 @@ tab-size = 4
#include <string>
#include <vector>
-#include <robin_hood.h>
#include <filesystem>
+#include <robin_hood.h>
+
using std::string;
using std::vector;
using robin_hood::unordered_flat_map;
@@ -33,12 +34,12 @@ namespace Config {
extern std::filesystem::path conf_dir;
extern std::filesystem::path conf_file;
- extern unordered_flat_map<string, string> strings;
- extern unordered_flat_map<string, string> stringsTmp;
- extern unordered_flat_map<string, bool> bools;
- extern unordered_flat_map<string, bool> boolsTmp;
- extern unordered_flat_map<string, int> ints;
- extern unordered_flat_map<string, int> intsTmp;
+ extern unordered_flat_map<std::string_view, string> strings;
+ extern unordered_flat_map<std::string_view, string> stringsTmp;
+ extern unordered_flat_map<std::string_view, bool> bools;
+ extern unordered_flat_map<std::string_view, bool> boolsTmp;
+ extern unordered_flat_map<std::string_view, int> ints;
+ extern unordered_flat_map<std::string_view, int> intsTmp;
const vector<string> valid_graph_symbols = { "braille", "block", "tty" };
const vector<string> valid_graph_symbols_def = { "default", "braille", "block", "tty" };
@@ -62,44 +63,44 @@ namespace Config {
//* Apply selected preset
void apply_preset(const string& preset);
- bool _locked(const string& name);
+ bool _locked(const std::string_view name);
//* Return bool for config key <name>
- inline bool getB(const string& name) { return bools.at(name); }
+ inline bool getB(const std::string_view name) { return bools.at(name); }
//* Return integer for config key <name>
- inline const int& getI(const string& name) { return ints.at(name); }
+ inline const int& getI(const std::string_view name) { return ints.at(name); }
//* Return string for config key <name>
- inline const string& getS(const string& name) { return strings.at(name); }
+ inline const string& getS(const std::string_view name) { return strings.at(name); }
- string getAsString(const string& name);
+ string getAsString(const std::string_view name);
extern string validError;
- bool intValid(const string& name, const string& value);
- bool stringValid(const string& name, const string& value);
+ bool intValid(const std::string_view name, const string& value);
+ bool stringValid(const std::string_view name, const string& value);
//* Set config key <name> to bool <value>
- inline void set(const string& name, bool value) {
+ inline void set(const std::string_view name, bool value) {
if (_locked(name)) boolsTmp.insert_or_assign(name, value);
else bools.at(name) = value;
}
//* Set config key <name> to int <value>
- inline void set(const string& name, const int& value) {
+ inline void set(const std::string_view name, const int& value) {
if (_locked(name)) intsTmp.insert_or_assign(name, value);
else ints.at(name) = value;
}
//* Set config key <name> to string <value>
- inline void set(const string& name, const string& value) {
+ inline void set(const std::string_view name, const string& value) {
if (_locked(name)) stringsTmp.insert_or_assign(name, value);
else strings.at(name) = value;
}
//* Flip config key bool <name>
- void flip(const string& name);
+ void flip(const std::string_view name);
//* Lock config and cache changes until unlocked
void lock();
diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp
index 989c052..5aa5b28 100644
--- a/src/btop_draw.cpp
+++ b/src/btop_draw.cpp
@@ -20,17 +20,18 @@ tab-size = 4
#include <algorithm>
#include <cmath>
#include <ranges>
-
-#include <btop_draw.hpp>
-#include <btop_config.hpp>
-#include <btop_theme.hpp>
-#include <btop_shared.hpp>
-#include <btop_tools.hpp>
-#include <btop_input.hpp>
-#include <btop_menu.hpp>
#include <stdexcept>
#include <string>
+#include "btop_draw.hpp"
+#include "btop_config.hpp"
+#include "btop_theme.hpp"
+#include "btop_shared.hpp"
+#include "btop_tools.hpp"
+#include "btop_input.hpp"
+#include "btop_menu.hpp"
+
+
using std::array;
using std::clamp;
using std::cmp_equal;
@@ -108,8 +109,8 @@ namespace Draw {
if (redraw) banner.clear();
if (banner.empty()) {
string b_color, bg, fg, oc, letter;
- auto lowcolor = Config::getB("lowcolor");
- auto tty_mode = Config::getB("tty_mode");
+ auto lowcolor = Config::getB("lowcolor");
+ auto tty_mode = Config::getB("tty_mode");
for (size_t z = 0; const auto& line : Global::Banner_src) {
if (const auto w = ulen(line[1]); w > width) width = w;
if (tty_mode) {
@@ -158,10 +159,10 @@ namespace Draw {
upos++;
pos = uresize(text, upos).size();
}
- else if (key == "home" and pos > 0) {
+ else if (key == "home" and not text.empty() and pos > 0) {
pos = upos = 0;
}
- else if (key == "end" and pos < text.size()) {
+ else if (key == "end" and not text.empty() and pos < text.size()) {
pos = text.size();
upos = ulen(text);
}
@@ -204,6 +205,10 @@ namespace Draw {
}
string TextEdit::operator()(const size_t limit) {
+ string out;
+ size_t c_upos = upos;
+ if (text.empty())
+ return Fx::ul + " " + Fx::uul;
if (limit > 0 and ulen(text) + 1 > limit) {
try {
const size_t half = (size_t)round((double)limit / 2);
@@ -216,29 +221,39 @@ namespace Draw {
else
first = luresize(text.substr(0, pos), half);
- return first + Fx::bl + "█" + Fx::ubl + uresize(text.substr(pos), limit - ulen(first));
+ out = first + uresize(text.substr(pos), limit - ulen(first));
+ c_upos = ulen(first);
}
catch (const std::exception& e) {
- Logger::error("In TextEdit::operator() : " + string{e.what()});
+ Logger::error("In TextEdit::operator() : " + string{e.what()});
+ return "";
}
}
- return text.substr(0, pos) + Fx::bl + "█" + Fx::ubl + text.substr(pos);
+ else
+ out = text;
+
+ if (c_upos == 0)
+ return Fx::ul + uresize(out, 1) + Fx::uul + luresize(out, ulen(out) - 1);
+ else if (c_upos == ulen(out))
+ return out + Fx::ul + " " + Fx::uul;
+ else
+ return uresize(out, c_upos) + Fx::ul + luresize(uresize(out, c_upos + 1), 1) + Fx::uul + luresize(out, ulen(out) - c_upos - 1);
}
void TextEdit::clear() {
this->text.clear();
}
- string createBox(const int x, const int y, const int width,
- const int height, string line_color, bool fill,
- const string title, const string title2, const int num) {
+ string createBox(const int x, const int y, const int width,
+ 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");
+ 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)));
const auto& right_up = (tty_mode or not rounded ? Symbols::right_up : Symbols::round_right_up);
const auto& left_up = (tty_mode or not rounded ? Symbols::left_up : Symbols::round_left_up);
@@ -248,12 +263,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;
@@ -291,11 +306,11 @@ namespace Draw {
{"/uptime", ""}
};
- static time_t c_time{}; // defaults to 0
- static size_t clock_len{}; // defaults to 0
+ static time_t c_time{}; // defaults to 0
+ static size_t clock_len{}; // defaults to 0
static string clock_str;
- if (auto n_time = time(NULL); not force and n_time == c_time)
+ if (auto n_time = time(nullptr); not force and n_time == c_time)
return false;
else {
c_time = n_time;
@@ -305,7 +320,7 @@ namespace Draw {
}
auto& out = Global::clock;
- auto cpu_bottom = Config::getB("cpu_bottom");
+ auto cpu_bottom = Config::getB("cpu_bottom");
const auto& x = Cpu::x;
const auto y = (cpu_bottom ? Cpu::y + Cpu::height - 1 : Cpu::y);
const auto& width = Cpu::width;
@@ -345,8 +360,8 @@ namespace Draw {
//* Meter class ------------------------------------------------------------------------------------------------------------>
Meter::Meter() {}
- Meter::Meter(const int width, const string& color_gradient, bool invert)
- : width(width), color_gradient(color_gradient), invert(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) {
if (width < 1) return "";
@@ -368,7 +383,7 @@ namespace Draw {
//* Graph class ------------------------------------------------------------------------------------------------------------>
void Graph::_create(const deque<long long>& data, int data_offset) {
- 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;
@@ -438,11 +453,11 @@ namespace Draw {
Graph::Graph() {}
- Graph::Graph(int width, int height, const string& color_gradient,
- const deque<long long>& data, const string& symbol,
- bool invert, bool no_zero, long long max_value, long long offset)
- : width(width), height(height), color_gradient(color_gradient),
- invert(invert), no_zero(no_zero), offset(offset) {
+ Graph::Graph(int width, int height, const string& color_gradient,
+ const deque<long long>& data, const string& symbol,
+ bool invert, bool no_zero, long long max_value, long long offset)
+ : width(width), height(height), color_gradient(color_gradient),
+ invert(invert), no_zero(no_zero), offset(offset) {
if (Config::getB("tty_mode") or symbol == "tty") this->symbol = "tty";
else if (symbol != "default") this->symbol = symbol;
else this->symbol = Config::getS("graph_symbol");
@@ -466,7 +481,7 @@ namespace Draw {
this->_create(data, data_offset);
}
- string& Graph::operator()(const deque<long long>& data, 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
@@ -514,23 +529,23 @@ namespace Cpu {
string draw(const cpu_info& cpu, const vector<Gpu::gpu_info>& gpus, 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);
- auto single_graph = Config::getB("cpu_single_graph");
- bool hide_cores = show_temps and (cpu_temp_only or not Config::getB("show_coretemp"));
+ bool show_temps = (Config::getB("check_temp") and got_sensors);
+ auto single_graph = Config::getB("cpu_single_graph");
+ bool hide_cores = show_temps and (cpu_temp_only or not Config::getB("show_coretemp"));
const int extra_width = (hide_cores ? max(6, 6 * b_column_size) : 0);
auto& graph_up_field = Config::getS("cpu_graph_upper");
auto& graph_lo_field = Config::getS("cpu_graph_lower");
- auto tty_mode = Config::getB("tty_mode");
+ auto tty_mode = Config::getB("tty_mode");
auto& graph_symbol = (tty_mode ? "tty" : Config::getS("graph_symbol_cpu"));
auto& graph_bg = Symbols::graph_symbols.at((graph_symbol == "default" ? Config::getS("graph_symbol") + "_up" : graph_symbol + "_up")).at(6);
auto& temp_scale = Config::getS("temp_scale");
- auto cpu_bottom = Config::getB("cpu_bottom");
+ auto cpu_bottom = Config::getB("cpu_bottom");
const string& title_left = Theme::c("cpu_box") + (cpu_bottom ? Symbols::title_left_down : Symbols::title_left);
const string& title_right = Theme::c("cpu_box") + (cpu_bottom ? Symbols::title_right_down : Symbols::title_right);
static int bat_pos = 0, bat_len = 0;
- if (cpu.cpu_percent.at("total").empty()
- or cpu.core_percent.at(0).empty()
- or (show_temps and cpu.temp.at(0).empty())) return "";
+ if (cpu.cpu_percent.at("total").empty()
+ or cpu.core_percent.at(0).empty()
+ or (show_temps and cpu.temp.at(0).empty())) return "";
string out;
out.reserve(width * height);
@@ -664,8 +679,8 @@ namespace Cpu {
//? Draw battery if enabled and present
if (Config::getB("show_battery") and has_battery) {
- static int old_percent{}; // defaults to = 0
- static long old_seconds{}; // defaults to = 0
+ static int old_percent{}; // defaults to = 0
+ static long old_seconds{}; // defaults to = 0
static string old_status;
static Draw::Meter bat_meter {10, "cpu", true};
static const unordered_flat_map<string, string> bat_symbols = {
@@ -758,7 +773,7 @@ namespace Cpu {
}
out += Theme::c("div_line") + Symbols::v_line;
- } catch (const std::exception& e) { throw std::runtime_error("graphs, clock, meter : " + string{e.what()}); }
+ } catch (const std::exception& e) { throw std::runtime_error("graphs, clock, meter : " + string{e.what()}); }
//? Core text and graphs
int cx = 0, cy = 1, cc = 0, core_width = (b_column_size == 0 ? 2 : 3);
@@ -1048,17 +1063,17 @@ 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, bool force_redraw, 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");
- auto swap_disk = Config::getB("swap_disk");
- auto show_disks = Config::getB("show_disks");
- auto show_io_stat = Config::getB("show_io_stat");
- auto io_mode = Config::getB("io_mode");
- auto io_graph_combined = Config::getB("io_graph_combined");
- auto use_graphs = Config::getB("mem_graphs");
- auto tty_mode = Config::getB("tty_mode");
+ auto show_swap = Config::getB("show_swap");
+ auto swap_disk = Config::getB("swap_disk");
+ auto show_disks = Config::getB("show_disks");
+ auto show_io_stat = Config::getB("show_io_stat");
+ auto io_mode = Config::getB("io_mode");
+ auto io_graph_combined = Config::getB("io_graph_combined");
+ auto use_graphs = Config::getB("mem_graphs");
+ auto tty_mode = Config::getB("tty_mode");
auto& graph_symbol = (tty_mode ? "tty" : Config::getS("graph_symbol_mem"));
auto& graph_bg = Symbols::graph_symbols.at((graph_symbol == "default" ? Config::getS("graph_symbol") + "_up" : graph_symbol + "_up")).at(6);
auto totalMem = Mem::get_totalMem();
@@ -1124,20 +1139,20 @@ namespace Mem {
if (io_graph_combined) {
deque<long long> combined(disk.io_read.size(), 0);
rng::transform(disk.io_read, disk.io_write, combined.begin(), std::plus<long long>());
- io_graph