From 03f64c22defd801685de3bb92f4429dbe2808e83 Mon Sep 17 00:00:00 2001 From: aristocratos Date: Mon, 23 Aug 2021 17:35:27 +0200 Subject: [PATCH] Added btop_platform.cpp, moved btop_linux.cpp to btop_linux.hpp and updated robin_hood.h --- Makefile | 17 ++++++----- README.md | 6 ++-- include/robin_hood.h | 7 ++--- src/btop.cpp | 39 ++++++++------------------ src/btop_draw.cpp | 7 +++-- src/btop_input.cpp | 13 +++++++-- src/{btop_linux.cpp => btop_linux.hpp} | 8 ++---- src/btop_platform.cpp | 36 ++++++++++++++++++++++++ 8 files changed, 78 insertions(+), 55 deletions(-) rename src/{btop_linux.cpp => btop_linux.hpp} (99%) create mode 100644 src/btop_platform.cpp diff --git a/Makefile b/Makefile index bb5f385..0b0db54 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ #* Btop++ makefile v1.0 -BANNER = \n \033[38;5;196m██████\033[38;5;240m╗ \033[38;5;196m████████\033[38;5;240m╗ \033[38;5;196m██████\033[38;5;240m╗ \033[38;5;196m██████\033[38;5;240m╗\n \033[38;5;160m██\033[38;5;239m╔══\033[38;5;160m██\033[38;5;239m╗╚══\033[38;5;160m██\033[38;5;239m╔══╝\033[38;5;160m██\033[38;5;239m╔═══\033[38;5;160m██\033[38;5;239m╗\033[38;5;160m██\033[38;5;239m╔══\033[38;5;160m██\033[38;5;239m╗ \033[38;5;160m██\033[38;5;239m╗ \033[38;5;160m██\033[38;5;239m╗\n \033[38;5;124m██████\033[38;5;238m╔╝ \033[38;5;124m██\033[38;5;238m║ \033[38;5;124m██\033[38;5;238m║ \033[38;5;124m██\033[38;5;238m║\033[38;5;124m██████\033[38;5;238m╔╝ \033[38;5;124m██████\033[38;5;238m╗\033[38;5;124m██████\033[38;5;238m╗\n \033[38;5;88m██\033[38;5;237m╔══\033[38;5;88m██\033[38;5;237m╗ \033[38;5;88m██\033[38;5;237m║ \033[38;5;88m██\033[38;5;237m║ \033[38;5;88m██\033[38;5;237m║\033[38;5;88m██\033[38;5;237m╔═══╝ ╚═\033[38;5;88m██\033[38;5;237m╔═╝╚═\033[38;5;88m██\033[38;5;237m╔═╝\n \033[38;5;52m██████\033[38;5;236m╔╝ \033[38;5;52m██\033[38;5;236m║ ╚\033[38;5;52m██████\033[38;5;236m╔╝\033[38;5;52m██\033[38;5;236m║ ╚═╝ ╚═╝\n \033[38;5;235m╚═════╝ ╚═╝ ╚═════╝ ╚═╝ +BANNER = \n \033[38;5;196m██████\033[38;5;240m╗ \033[38;5;196m████████\033[38;5;240m╗ \033[38;5;196m██████\033[38;5;240m╗ \033[38;5;196m██████\033[38;5;240m╗\n \033[38;5;160m██\033[38;5;239m╔══\033[38;5;160m██\033[38;5;239m╗╚══\033[38;5;160m██\033[38;5;239m╔══╝\033[38;5;160m██\033[38;5;239m╔═══\033[38;5;160m██\033[38;5;239m╗\033[38;5;160m██\033[38;5;239m╔══\033[38;5;160m██\033[38;5;239m╗ \033[38;5;160m██\033[38;5;239m╗ \033[38;5;160m██\033[38;5;239m╗\n \033[38;5;124m██████\033[38;5;238m╔╝ \033[38;5;124m██\033[38;5;238m║ \033[38;5;124m██\033[38;5;238m║ \033[38;5;124m██\033[38;5;238m║\033[38;5;124m██████\033[38;5;238m╔╝ \033[38;5;124m██████\033[38;5;238m╗\033[38;5;124m██████\033[38;5;238m╗\n \033[38;5;88m██\033[38;5;237m╔══\033[38;5;88m██\033[38;5;237m╗ \033[38;5;88m██\033[38;5;237m║ \033[38;5;88m██\033[38;5;237m║ \033[38;5;88m██\033[38;5;237m║\033[38;5;88m██\033[38;5;237m╔═══╝ ╚═\033[38;5;88m██\033[38;5;237m╔═╝╚═\033[38;5;88m██\033[38;5;237m╔═╝\n \033[38;5;52m██████\033[38;5;236m╔╝ \033[38;5;52m██\033[38;5;236m║ ╚\033[38;5;52m██████\033[38;5;236m╔╝\033[38;5;52m██\033[38;5;236m║ ╚═╝ ╚═╝\n \033[38;5;235m╚═════╝ ╚═╝ ╚═════╝ ╚═╝ \033[1;3;38;5;240mMakefile v1.0\033[0m BTOP_VERSION = $(shell head -n100 src/btop.cpp 2>/dev/null | grep "Version =" | cut -f2 -d"\"" || echo " unknown") TIMESTAMP = $(shell date +%s 2>/dev/null || echo "0") @@ -22,16 +22,16 @@ ifneq ($(CXX),g++-10) endif #? Only enable fcf-protection if on x86_64 -ARCH = $(shell uname -p ||true) +ARCH = $(shell uname -p || echo unknown) ifeq ($(ARCH),x86_64) ADDFLAGS = -fcf-protection endif ifeq ($(ARCH),unknown) - ARCH = $(shell uname -m ||true) + ARCH = $(shell uname -m || echo unknown) endif -PLATFORM = $(shell uname -s ||true) +PLATFORM = $(shell uname -s || echo unknown) -#? Use all CPU cores (will only be set if using Make >=4.3) +#? Use all CPU cores (will only be set if using Make 4.3+) MAKEFLAGS := --jobs=$(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) #? The Directories, Source, Includes, Objects and Binary @@ -62,13 +62,12 @@ all: msg directories btop msg: @printf " $(BANNER)\n" - @printf "\033[1;97mCompiler : \033[0m$(CXX) ($(CXX_VERSION))\n" + @printf "\033[1;97mCXX : \033[0m$(CXX) ($(CXX_VERSION))\n" @printf "\033[1;97mREQFLAGS : \033[0m$(REQFLAGS)\n" @printf "\033[1;97mWARNFLAGS : \033[0m$(WARNFLAGS)\n" @printf "\033[1;97mOPTFLAGS : \033[0m$(OPTFLAGS)\n" @printf "\033[1;97mLDCXXFLAGS : \033[0m$(LDCXXFLAGS)\n" - - @printf "\n\033[1;92mBuilding btop++ v$(BTOP_VERSION) for $(PLATFORM) ($(ARCH))\033[0m\n" + @printf "\n\033[1;92mBuilding btop++ v$(BTOP_VERSION) on $(PLATFORM) ($(ARCH))\033[0m\n" help: @printf "\033[1;97mbtop++ makefile\033[0m\n" @@ -135,7 +134,7 @@ btop: $(OBJECTS) #? Compile $(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT) @sleep 0.1 2>/dev/null || true - @printf "\033[1;97mCompiling $< \n" + @printf "\033[1;97mCompiling $<\033[0m\n" @$(CXX) $(CXXFLAGS) $(INC) -c -o $@ $< @$(CXX) $(CXXFLAGS) $(INC) -MM $(SRCDIR)/$*.$(SRCEXT) > $(BUILDDIR)/$*.$(DEPEXT) >/dev/null @cp -f $(BUILDDIR)/$*.$(DEPEXT) $(BUILDDIR)/$*.$(DEPEXT).tmp diff --git a/README.md b/README.md index 0ffe6ce..6f9da06 100644 --- a/README.md +++ b/README.md @@ -127,8 +127,8 @@ Options menu. #### Manual compilation and installation -Needs GCC 10 or higher, (GCC 11 or above strongly recommended for better CPU efficiency in compiled binary). -The makefile also needs GNU coreutils and sed installed. +Needs GCC 10 or higher, (GCC 11 or above strongly recommended for better CPU efficiency in the compiled binary). +The makefile also needs GNU coreutils and sed (should already be installed on any modern distribution). >Install dependencies (example for Ubuntu 21.04 Hirsute) @@ -142,7 +142,7 @@ sudo apt install coreutils sed git build-essential gcc-11 g++-11 ``` bash git clone https://github.com/aristocratos/btop.git cd btop -# use "make -j X" where X is threads, to manually set number of threads, the makefile will use all available cores by default +# use "make -j X" where X is threads, to manually set number of threads, the makefile will use all available cores by default on Make 4.3+ make ``` diff --git a/include/robin_hood.h b/include/robin_hood.h index 48ae0b6..511a308 100644 --- a/include/robin_hood.h +++ b/include/robin_hood.h @@ -36,7 +36,7 @@ // see https://semver.org/ #define ROBIN_HOOD_VERSION_MAJOR 3 // for incompatible API changes #define ROBIN_HOOD_VERSION_MINOR 11 // for adding functionality in a backwards-compatible manner -#define ROBIN_HOOD_VERSION_PATCH 2 // for backwards-compatible bug fixes +#define ROBIN_HOOD_VERSION_PATCH 3 // for backwards-compatible bug fixes #include #include @@ -2427,15 +2427,14 @@ private: << (static_cast(mNumElements) * 100.0 / (static_cast(mMask) + 1))) - nextHashMultiplier(); if (mNumElements * 2 < calcMaxNumElementsAllowed(mMask + 1)) { // we have to resize, even though there would still be plenty of space left! // Try to rehash instead. Delete freed memory so we don't steadyily increase mem in case // we have to rehash a few times + nextHashMultiplier(); rehashPowerOfTwo(mMask + 1, true); } else { - // Each resize use a different hash so we don't so easily overflow. - // Make sure we only have odd numbers, so that the multiplication is reversible! + // we've reached the capacity of the map, so the hash seems to work nice. Keep using it. rehashPowerOfTwo((mMask + 1) * 2, false); } return true; diff --git a/src/btop.cpp b/src/btop.cpp index 08019ae..5c84c29 100644 --- a/src/btop.cpp +++ b/src/btop.cpp @@ -38,23 +38,6 @@ tab-size = 4 #include #include -#if defined(__linux__) - #define LINUX -#elif defined(__unix__) or not defined(__APPLE__) and defined(__MACH__) - #include - #if defined(BSD) - #error BSD support not yet implemented! - #endif -#elif defined(__APPLE__) and defined(__MACH__) - #include - #if TARGET_OS_MAC == 1 - #define OSX - #error OSX support not yet implemented! - #endif -#else - #error Platform not supported! -#endif - using std::string, std::string_view, std::vector, std::atomic, std::endl, std::cout, std::min, std::flush, std::endl; using std::string_literals::operator""s, std::to_string, std::future, std::async, std::bitset, std::future_status; namespace fs = std::filesystem; @@ -331,7 +314,7 @@ bool update_clock() { out.clear(); if (new_clock.size() != clock_len) { - out = Mv::to(y, x+(width / 2)-(clock_len / 2)) + Fx::ub + Theme::c("cpu_box") + Symbols::h_line * clock_len; + if (not Global::resized) out = Mv::to(y, x+(width / 2)-(clock_len / 2)) + Fx::ub + Theme::c("cpu_box") + Symbols::h_line * clock_len; clock_len = new_clock.size(); } @@ -647,7 +630,7 @@ namespace Runner { else if (box == "clock") { cout << Term::sync_start << Global::clock << Term::sync_end << flush; } - else if (box.empty() and Config::current_boxes.empty()) { + else if (Config::current_boxes.empty()) { cout << Term::sync_start << Term::clear + Mv::to(10, 10) << "No boxes shown!" << Term::sync_end << flush; } else { @@ -726,15 +709,15 @@ int main(int argc, char **argv) { } } //? Try to find global btop theme path relative to binary path - #if defined(LINUX) +#if defined(__linux__) { std::error_code ec; Global::self_path = fs::read_symlink("/proc/self/exe", ec).remove_filename(); } - #endif +#endif if (std::error_code ec; not Global::self_path.empty()) { - Theme::theme_dir = fs::canonical(Global::self_path / "../share/btop/themes", ec); - if (ec or not fs::is_directory(Theme::theme_dir) or access(Theme::theme_dir.c_str(), R_OK) == -1) Theme::theme_dir.clear(); - } + Theme::theme_dir = fs::canonical(Global::self_path / "../share/btop/themes", ec); + if (ec or not fs::is_directory(Theme::theme_dir) or access(Theme::theme_dir.c_str(), R_OK) == -1) Theme::theme_dir.clear(); + } //? If relative path failed, check two most common absolute paths if (Theme::theme_dir.empty()) { for (auto theme_path : {"/usr/local/share/btop/themes", "/usr/share/btop/themes"}) { @@ -785,7 +768,7 @@ int main(int argc, char **argv) { if (not found and Global::utf_force) Logger::warning("No UTF-8 locale detected! Forcing start with --utf-force argument."); else if (not found) { - Global::exit_error_msg = "No UTF-8 locale detected! Use --utf-force argument to start anyway."; + 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); } else @@ -868,15 +851,15 @@ int main(int argc, char **argv) { //? Trigger secondary thread to redraw if terminal has been resized if (Global::resized) { - Global::resized = false; Draw::calcSizes(); update_clock(); + Global::resized = false; Runner::run("all", true); atomic_wait(Runner::active); } //? Update clock if needed - if (update_clock()) { + if (update_clock() and not Menu::active) { Runner::run("clock"); } @@ -891,7 +874,7 @@ int main(int argc, char **argv) { for (auto current_time = time_ms(); current_time < future_time; current_time = time_ms()) { //? Check for external clock changes and for changes to the update timer - if (update_ms != (uint64_t)Config::getI("update_ms")) { + if (std::cmp_not_equal(update_ms, Config::getI("update_ms"))) { update_ms = Config::getI("update_ms"); future_time = time_ms() + update_ms; } diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index 450d136..3ab01bb 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -612,10 +612,11 @@ namespace Mem { disk_meters_free[name] = Draw::Meter{disk_meter, "free"}; } } - } - out += Mv::to(y, x + width - 6) + Fx::ub + Theme::c("mem_box") + Symbols::title_left + (io_mode ? Fx::b : "") + Theme::c("hi_fg") + out += Mv::to(y, x + width - 6) + Fx::ub + Theme::c("mem_box") + Symbols::title_left + (io_mode ? Fx::b : "") + Theme::c("hi_fg") + 'i' + Theme::c("title") + 'o' + Fx::ub + Theme::c("mem_box") + Symbols::title_right; - Input::mouse_mappings["i"] = {y, x + width - 5, 1, 2}; + Input::mouse_mappings["i"] = {y, x + width - 5, 1, 2}; + } + } //? Mem and swap diff --git a/src/btop_input.cpp b/src/btop_input.cpp index 63a26e0..33f6d35 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -250,10 +250,14 @@ namespace Input { Config::set("proc_filter", ""s); else if (key == "ö") { - if (Global::overlay.empty()) + if (Global::overlay.empty()) { Global::overlay = Mv::to(Term::height / 2, Term::width / 2) + "\x1b[1;32mTESTING"; - else + Menu::active = true; + } + else { Global::overlay.clear(); + Menu::active = false; + } Runner::run("all", true, true); } else if (key.starts_with("mouse_")) { @@ -387,6 +391,11 @@ namespace Input { if (key == "i") { Config::flip("io_mode"); } + if (key == "d") { + Config::flip("show_disks"); + no_update = false; + Draw::calcSizes(); + } else keep_going = true; if (not keep_going) { diff --git a/src/btop_linux.cpp b/src/btop_linux.hpp similarity index 99% rename from src/btop_linux.cpp rename to src/btop_linux.hpp index e2b7704..ea3535f 100644 --- a/src/btop_linux.cpp +++ b/src/btop_linux.hpp @@ -16,8 +16,6 @@ indent = tab tab-size = 4 */ -#if defined(__linux__) - #include #include #include @@ -551,7 +549,7 @@ namespace Mem { mem_info current_mem {}; auto collect(const bool no_update) -> mem_info& { - if (Runner::stopping or no_update) return current_mem; + 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"); auto& show_disks = Config::getB("show_disks"); @@ -1466,6 +1464,4 @@ namespace Tools { pread.close(); return stod(upstr); } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/btop_platform.cpp b/src/btop_platform.cpp new file mode 100644 index 0000000..f7e256d --- /dev/null +++ b/src/btop_platform.cpp @@ -0,0 +1,36 @@ +/* Copyright 2021 Aristocratos (jakob@qvantnet.com) + + Licensed under the Apache License, Version 2.0 (the "License"); + 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 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +indent = tab +tab-size = 4 +*/ + + +#if defined(__linux__) + #include +#elif defined(__unix__) or not defined(__APPLE__) and defined(__MACH__) + #include + #if defined(__FreeBSD__) + #error FreeBSD support not yet implemented! + //#include + #endif +#elif defined(__APPLE__) and defined(__MACH__) + #include + #if TARGET_OS_MAC == 1 + #error OSX support not yet implemented! + //#include + #endif +#else + #error Platform not supported! +#endif \ No newline at end of file