diff options
-rw-r--r-- | CHANGELOG.md | 10 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | src/btop.cpp | 48 | ||||
-rw-r--r-- | src/btop_draw.cpp | 1 | ||||
-rw-r--r-- | src/btop_tools.cpp | 4 | ||||
-rw-r--r-- | src/btop_tools.hpp | 8 | ||||
-rw-r--r-- | src/linux/btop_collect.cpp | 5 | ||||
-rw-r--r-- | themes/night-owl.theme | 92 |
8 files changed, 142 insertions, 29 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 10532f5..9ec21b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## v1.0.11 + +* Changed: atomic_wait to use while loop instead of wait() because of rare stall when a signal handler is triggered while waiting + +* Fixed: Get real / mountpoint when running inside snap + +* Fixed: UTF8 set LANG and LC_ALL to empty before UTF8 search and fixed empty error msg on exit before signal handler init + +* Changed: Init will continue with a warning if UTF-8 locale are detected and it fails to set the locale + ## v1.0.10 * Added: Wait for terminal size properties to be available at start @@ -7,7 +7,7 @@ ![Linux](https://img.shields.io/badge/-Linux-grey?logo=linux) ![Usage](https://img.shields.io/badge/Usage-System%20resource%20monitor-yellow) ![c++20](https://img.shields.io/badge/cpp-c%2B%2B20-green) -![btop_version](https://img.shields.io/github/v/tag/aristocratos/btop?label=version) +![latest_release](https://img.shields.io/github/v/tag/aristocratos/btop?label=release) [![Donate](https://img.shields.io/badge/-Donate-yellow?logo=paypal)](https://paypal.me/aristocratos) [![Sponsor](https://img.shields.io/badge/-Sponsor-red?logo=github)](https://github.com/sponsors/aristocratos) [![Coffee](https://img.shields.io/badge/-Buy%20me%20a%20Coffee-grey?logo=Ko-fi)](https://ko-fi.com/aristocratos) @@ -124,6 +124,7 @@ Also needs a UTF8 locale and a font that covers: * Unicode Block “Braille Patterns” U+2800 - U+28FF (Not needed in TTY mode or with graphs set to type: block or tty.) * Unicode Block “Geometric Shapes” U+25A0 - U+25FF * Unicode Block "Box Drawing" and "Block Elements" U+2500 - U+259F +* Unicode Block "General punctuation" U+2005 ### **Notice (Text rendering issues)** diff --git a/src/btop.cpp b/src/btop.cpp index 0bd5ab8..bef5a16 100644 --- a/src/btop.cpp +++ b/src/btop.cpp @@ -55,7 +55,7 @@ namespace Global { {"#801414", "██████╔╝ ██║ ╚██████╔╝██║ ╚═╝ ╚═╝"}, {"#000000", "╚═════╝ ╚═╝ ╚═════╝ ╚═╝"}, }; - const string Version = "1.0.10"; + const string Version = "1.0.12"; int coreCount; string overlay; @@ -712,42 +712,54 @@ int main(int argc, char **argv) { } //? Try to find and set a UTF-8 locale - if (bool found = false; std::setlocale(LC_ALL, NULL) == NULL or not str_to_upper(s_replace((string)std::setlocale(LC_ALL, NULL), "-", "")).ends_with("UTF8")) { - if (std::getenv("LANG") != NULL and str_to_upper(s_replace((string)std::getenv("LANG"), "-", "")).ends_with("UTF8") and std::setlocale(LC_ALL, std::getenv("LANG")) != NULL) { - found = true; + if (std::setlocale(LC_ALL, "") != NULL 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 = 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")) { + found = std::getenv(loc_env); + if (std::setlocale(LC_ALL, found.c_str()) == NULL) { + set_failure = true; + Logger::warning("Failed to set locale " + found + " continuing anyway."); + } + } } - else { - if (setenv("LANG", "", 1) == 0) { + if (found.empty()) { + if (setenv("LC_ALL", "", 1) == 0 and setenv("LANG", "", 1) == 0) { try { if (const auto loc = std::locale("").name(); not loc.empty() and loc != "*") { for (auto& l : ssplit(loc, ';')) { if (str_to_upper(s_replace(l, "-", "")).ends_with("UTF8")) { - if (std::setlocale(LC_ALL, l.substr(l.find('=') + 1).c_str()) != NULL) { - found = true; + found = l.substr(l.find('=') + 1); + if (std::setlocale(LC_ALL, found.c_str()) != NULL) { + break; } - break; } } } } - catch (...) { found = false; } + catch (...) { found.clear(); } } } - if (not found and Global::utf_force) + if (found.empty() and Global::utf_force) Logger::warning("No UTF-8 locale detected! Forcing start with --utf-force argument."); - else if (not found) { + else if (found.empty()) { Global::exit_error_msg = "No UTF-8 locale detected!\nUse --utf-force argument to force start if you're sure your terminal can handle it."; - exit(1); + clean_quit(1); } - else - Logger::debug("Setting LC_ALL=" + (string)std::setlocale(LC_ALL, NULL)); + else if (not set_failure) + Logger::debug("Setting LC_ALL=" + found); } //? Initialize terminal and set options if (not Term::init()) { Global::exit_error_msg = "No tty detected!\nbtop++ needs an interactive shell to run."; - exit(1); + clean_quit(1); } if (Term::current_tty != "unknown") Logger::info("Running on " + Term::current_tty); @@ -768,7 +780,7 @@ int main(int argc, char **argv) { Term::refresh(); if (++t_count == 100) { Global::exit_error_msg = "Failed to get size of terminal!"; - exit(1); + clean_quit(1); } } } @@ -779,7 +791,7 @@ int main(int argc, char **argv) { } catch (const std::exception& e) { Global::exit_error_msg = "Exception in Shared::init() -> " + (string)e.what(); - exit(1); + clean_quit(1); } //? Update list of available themes and generate the selected theme diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index 0234d3a..7406d15 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -1418,6 +1418,7 @@ namespace Proc { else if (p.cpu_p >= 10'000) { cpu_str = to_string(p.cpu_p / 1000); cpu_str.resize(3); + if (cpu_str.ends_with('.')) cpu_str.pop_back(); cpu_str += "k"; } string mem_str = (mem_bytes ? floating_humanizer(p.mem, true) : ""); diff --git a/src/btop_tools.cpp b/src/btop_tools.cpp index dc3a0bd..bb75f2f 100644 --- a/src/btop_tools.cpp +++ b/src/btop_tools.cpp @@ -329,7 +329,6 @@ namespace Tools { atomic_lock::~atomic_lock() { active_locks--; this->atom.store(false); - atomic_notify(this->atom); } string readfile(const std::filesystem::path& path, const string& fallback) { @@ -340,7 +339,8 @@ namespace Tools { for (string readstr; getline(file, readstr); out += readstr); } catch (const std::exception& e) { - throw std::runtime_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); } diff --git a/src/btop_tools.hpp b/src/btop_tools.hpp index 7bb0445..97e010a 100644 --- a/src/btop_tools.hpp +++ b/src/btop_tools.hpp @@ -269,15 +269,9 @@ namespace Tools { string hostname(); string username(); -// #if __GNUC__ < 11 inline void atomic_wait(const atomic<bool>& atom, const bool old=true) noexcept { while (atom.load() == old) sleep_ms(1); } - inline void atomic_notify(const atomic<bool>& atom) noexcept { (void)atom; } -// #else -// inline void atomic_wait(const atomic<bool>& atom, const bool old=true) noexcept { if (atom == old) atom.wait(old); } -// inline void atomic_notify(const atomic<bool>& atom) noexcept { atom.notify_all(); } -// #endif - //* Waits for atomic<bool> to be false and sets it to true on construct, sets to false and notifies on destruct + //* Waits for atomic<bool> to be false and sets it to true on construct, sets to false on destruct class atomic_lock { atomic<bool>& atom; bool not_true = false; diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index d8ea597..56730e7 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -1007,7 +1007,10 @@ namespace Net { auto& saved_stat = net.at(iface).stat.at(dir); auto& bandwidth = net.at(iface).bandwidth.at(dir); - const uint64_t val = max((uint64_t)stoul(readfile(sys_file, "0")), saved_stat.last); + uint64_t val = saved_stat.last; + try { val = max((uint64_t)stoul(readfile(sys_file, "0")), val); } + catch (const std::invalid_argument&) {} + catch (const std::out_of_range&) {} //? Update speed, total and top values saved_stat.speed = round((double)(val - saved_stat.last) / ((double)(new_timestamp - timestamp) / 1000)); diff --git a/themes/night-owl.theme b/themes/night-owl.theme new file mode 100644 index 0000000..7537fea --- /dev/null +++ b/themes/night-owl.theme @@ -0,0 +1,92 @@ +#Bashtop theme with night-owl colors +#by zkourouma + +# Colors should be in 6 or 2 character hexadecimal or single spaced rgb decimal: "#RRGGBB", "#BW" or "0-255 0-255 0-255" +# example for white: "#ffffff", "#ff" or "255 255 255". + +# All graphs and meters can be gradients +# For single color graphs leave "mid" and "end" variable empty. +# Use "start" and "end" variables for two color gradient +# Use "start", "mid" and "end" for three color gradient + +# Main background, empty for terminal default, need to be empty if you want transparent background +theme[main_bg]="#011627" + +# Main text color +theme[main_fg]="#d6deeb" + +# Title color for boxes +theme[title]="#ffffff" + +# Higlight color for keyboard shortcuts +theme[hi_fg]="#addb67" + +# Background color of selected items +theme[selected_bg]="#000000" + +# Foreground color of selected items +theme[selected_fg]="#ffeb95" + +# Color of inactive/disabled text +theme[inactive_fg]="#575656" + +# Color of text appearing on top of graphs, i.e uptime and current network graph scaling +theme[graph_text]="#585858" + +# Misc colors for processes box including mini cpu graphs, details memory graph and details status text +theme[proc_misc]="#22da6e" + +# Cpu box outline color +theme[cpu_box]="#ffffff" + +# Memory/disks box outline color +theme[mem_box]="#ffffff" + +# Net up/down box outline color +theme[net_box]="#ffffff" + +# Processes box outline color +theme[proc_box]="#ffffff" + +# Box divider line and small boxes line color +theme[div_line]="#ffffff" + +# Temperature graph colors +theme[temp_start]="#82aaff" +theme[temp_mid]="#c792ea" +theme[temp_end]="#fb4394" + +# CPU graph colors +theme[cpu_start]="#22da6e" +theme[cpu_mid]="#addb67" +theme[cpu_end]="#ef5350" + +# Mem/Disk free meter +theme[free_start]="#4e5900" +theme[free_mid]="" +theme[free_end]="#22da6e" + +# Mem/Disk cached meter +theme[cached_start]="#82aaff" +theme[cached_mid]="" +theme[cached_end]="#82aaff" + +# Mem/Disk available meter +theme[available_start]="#addb67" +theme[available_mid]="" +theme[available_end]="#ffeb95" + +# Mem/Disk used meter +theme[used_start]="#ef5350" +theme[used_mid]="" +theme[used_end]="#ef5350" + +# Download graph colors +theme[download_start]="#3d4070" +theme[download_mid]="#6c71c4" +theme[download_end]="#a3a8f7" + +# Upload graph colors +theme[upload_start]="#701c45" +theme[upload_mid]="#c792ea" +theme[upload_end]="#c792ea" |