summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraristocratos <gnmjpl@gmail.com>2021-09-18 02:13:35 +0200
committeraristocratos <gnmjpl@gmail.com>2021-09-18 02:13:35 +0200
commitcffa3032702daad7095be42aef00a39ccd0dae2f (patch)
tree98c424627b871e350660b0b826deb5d8a62583df
parent07c468a8b712d05223270590d8ff7cd0317a0c4d (diff)
Added battery info in Cpu::draw()
-rw-r--r--CHANGELOG.md10
-rw-r--r--Makefile11
-rw-r--r--README.md26
-rw-r--r--src/btop.cpp4
-rw-r--r--src/btop_draw.cpp44
-rw-r--r--src/btop_tools.cpp10
-rw-r--r--src/btop_tools.hpp2
7 files changed, 79 insertions, 28 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0ee033f..9e1d042 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,9 +1,3 @@
-## v0.9.0
+## v1.0.0
-* Test release
-* Testing...
-
-## v0.8.0
-
-* Filler
-* Testing... \ No newline at end of file
+* First release for Linux
diff --git a/Makefile b/Makefile
index fda7136..9bce83d 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,10 @@ ifeq ($(ARCH),x86_64)
override ADDFLAGS += -fcf-protection
endif
+ifeq ($(STATIC),true)
+ override ADDFLAGS += -static -static-libgcc -static-libstdc++
+endif
+
#? Make sure PLATFORM Darwin is OSX and not Darwin
ifeq ($(PLATFORM),Darwin)
ifeq ($(shell sw_vers >/dev/null 2>&1; echo $$?),0)
@@ -74,7 +78,7 @@ OBJEXT := o
override REQFLAGS := -std=c++20
WARNFLAGS := -Wall -Wextra -pedantic
OPTFLAGS ?= -O2 -ftree-loop-vectorize -flto=$(THREADS)
-LDCXXFLAGS := -pthread -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector -fstack-clash-protection -static $(ADDFLAGS)
+LDCXXFLAGS := -pthread -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector -fstack-clash-protection $(ADDFLAGS)
override CXXFLAGS += $(REQFLAGS) $(LDCXXFLAGS) $(OPTFLAGS) $(WARNFLAGS)
override LDFLAGS += $(LDCXXFLAGS) $(OPTFLAGS) $(WARNFLAGS)
INC := -I$(INCDIR) -I$(SRCDIR)
@@ -106,14 +110,15 @@ pre:
@printf "\n\033[1;92mBuilding btop++ \033[93m(\033[97mv$(BTOP_VERSION)\033[93m)\033[0m\n"
help:
+ @printf " $(BANNER)\n"
@printf "\033[1;97mbtop++ makefile\033[0m\n"
@printf "usage: make [argument]\n\n"
@printf "arguments:\n"
@printf " all Compile btop (default argument)\n"
@printf " clean Remove built objects\n"
@printf " distclean Remove built objects and binaries\n"
- @printf " install Install btop++ to \$$PREFIX\n"
- @printf " setuid Set installed binary owner/group to \$$SU_USER/\$$SU_OWNER and set SUID bit\n"
+ @printf " install Install btop++ to \$$PREFIX ($(PREFIX))\n"
+ @printf " setuid Set installed binary owner/group to \$$SU_USER/\$$SU_GROUP ($(SU_USER)/$(SU_GROUP)) and set SUID bit\n"
@printf " uninstall Uninstall btop++ from \$$PREFIX\n"
#? Make the Directories
diff --git a/README.md b/README.md
index 22324ac..321f466 100644
--- a/README.md
+++ b/README.md
@@ -157,7 +157,7 @@ Also needs a UTF8 locale and a font that covers:
3. **(Optional) Set suid bit to make btop always run as root (or other user)**
- No need for `sudo` to enable signal sending to any process and to prevent /proc read permissions problems on some systems.
+ Enables signal sending to any process without starting with `sudo` and can prevent /proc read permissions problems on some systems.
* **Run setuid.sh or:**
@@ -175,11 +175,19 @@ Also needs a UTF8 locale and a font that covers:
sudo make uninstall
```
+* **Show help**
+
+ ```bash
+ make help
+ ```
+
## Compilation
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).
+ Only 64-bit for now.
+
+ The makefile also needs GNU coreutils and `sed` (should already be installed on any modern distribution).
1. **Install dependencies (example for Ubuntu 21.04 Hirsute)**
@@ -197,7 +205,11 @@ Also needs a UTF8 locale and a font that covers:
3. **Compile**
- Notice! Manually set $ARCH if cross-compiling
+ Append `STATIC=true` to `make` command for static compilation.
+
+ Notice! Manually set `$ARCH` variable if cross-compiling
+
+ Use `$ADDFLAGS` variable for appending flags to both compiler and linker.
``` bash
make
@@ -239,6 +251,12 @@ Also needs a UTF8 locale and a font that covers:
make distclean
```
+* **Show help**
+
+ ```bash
+ make help
+ ```
+
## Configurability
All options changeable from within UI.
@@ -442,7 +460,7 @@ optional arguments:
-lc, --low-color disable truecolor, converts 24-bit colors to 256-color
-t, --tty_on force (ON) tty mode, max 16 colors and tty friendly graph symbols
+t, --tty_off force (OFF) tty mode
- --utf-foce force start even if no UTF-8 locale was detected
+ --utf-foce force start even if no UTF-8 locale was detected
--debug start in DEBUG mode: shows microsecond timer for information collect
and screen draw functions and sets loglevel to DEBUG
```
diff --git a/src/btop.cpp b/src/btop.cpp
index 42336dd..7dca917 100644
--- a/src/btop.cpp
+++ b/src/btop.cpp
@@ -91,14 +91,14 @@ void argumentParser(const int& argc, char **argv) {
for(int i = 1; i < argc; i++) {
const string argument = argv[i];
if (is_in(argument, "-h", "--help")) {
- cout << "usage: btop [-h] [-v] [-/+t] [--debug]\n\n"
+ cout << "usage: btop [-h] [-v] [-/+t] [--utf-foce] [--debug]\n\n"
<< "optional arguments:\n"
<< " -h, --help show this help message and exit\n"
<< " -v, --version show version info and exit\n"
<< " -lc, --low-color disable truecolor, converts 24-bit colors to 256-color\n"
<< " -t, --tty_on force (ON) tty mode, max 16 colors and tty friendly graph symbols\n"
<< " +t, --tty_off force (OFF) tty mode\n"
- << " --utf-foce force start even if no UTF-8 locale was detected\n"
+ << " --utf-foce force start even if no UTF-8 locale was detected\n"
<< " --debug start in DEBUG mode: shows microsecond timer for information collect\n"
<< " and screen draw functions and sets loglevel to DEBUG\n"
<< endl;
diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp
index 148b7e5..f51f989 100644
--- a/src/btop_draw.cpp
+++ b/src/btop_draw.cpp
@@ -309,7 +309,7 @@ namespace Draw {
}
- clock_str = uresize(clock_str, std::max(0, width - 56));
+ clock_str = uresize(clock_str, std::max(10, width - 66 - (Term::width >= 100 and Config::getB("show_battery") and Cpu::has_battery ? 22 : 0)));
out.clear();
if (clock_str.size() != clock_len) {
@@ -472,6 +472,21 @@ namespace Cpu {
vector<Draw::Graph> core_graphs;
vector<Draw::Graph> temp_graphs;
+ unsigned long fastrand(void) {
+ static unsigned long x=123456789, y=362436069, z=521288629;
+ unsigned long t;
+ x ^= x << 16;
+ x ^= x >> 5;
+ x ^= x << 1;
+
+ t = x;
+ x = y;
+ y = z;
+ z = t ^ x ^ y;
+
+ return z;
+ }
+
string draw(const cpu_info& cpu, const bool force_redraw, const bool data_same) {
if (Runner::stopping) return "";
if (force_redraw) redraw = true;
@@ -485,18 +500,20 @@ namespace Cpu {
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");
+ 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;
string out;
out.reserve(width * height);
+
//* Redraw elements not needed to be updated every cycle
if (redraw) {
- auto& cpu_bottom = Config::getB("cpu_bottom");
mid_line = (not single_graph and graph_up_field != graph_lo_field);
graph_up_height = (single_graph ? height - 2 : ceil((double)(height - 2) / 2) - (mid_line and height % 2 != 0 ? 1 : 0));
const int graph_low_height = height - 2 - graph_up_height - (mid_line ? 1 : 0);
const int button_y = cpu_bottom ? y + height - 1 : y;
out += box;
- 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);
//? Buttons on title
out += Mv::to(button_y, x + 10) + title_left + Theme::c("hi_fg") + Fx::b + 'm' + Theme::c("title") + "enu" + Fx::ub + title_right;
@@ -549,14 +566,31 @@ namespace Cpu {
};
const auto& [percent, seconds, status] = current_bat;
+
if (redraw or percent != old_percent or seconds != old_seconds or status != old_status) {
old_percent = percent;
old_seconds = seconds;
old_status = status;
- const string bat_time = (seconds > 0 ? to_string(seconds / 3600) + ':' + to_string((seconds % 3600) / 60) : "");
+ const string str_time = (seconds > 0 ? sec_to_dhms(seconds, true, true) : "");
+ const string str_percent = to_string(percent) + '%';
const auto& bat_symbol = bat_symbols.at((bat_symbols.contains(status) ? status : "unknown"));
+ const int current_len = (Term::width >= 100 ? 11 : 0) + str_time.size() + str_percent.size() + to_string(Config::getI("update_ms")).size();
+ const int current_pos = Term::width - current_len - 17;
+
+ if ((bat_pos != current_pos or bat_len != current_len) and bat_pos > 0 and not redraw)
+ out += Mv::to(y, bat_pos) + Fx::ub + Theme::c("cpu_box") + Symbols::h_line * (bat_len + 4);
+ bat_pos = current_pos;
+ bat_len = current_len;
+
+ out += Mv::to(y, bat_pos) + title_left + Theme::c("title") + Fx::b + "BAT" + bat_symbol + ' ' + str_percent
+ + (Term::width >= 100 ? Fx::ub + ' ' + bat_meter(percent) + Fx::b : "")
+ + (not str_time.empty() ? ' ' + Theme::c("title") + str_time : "") + Fx::ub + title_right;
}
}
+ else if (bat_pos > 0) {
+ out += Mv::to(y, bat_pos) + Fx::ub + Theme::c("cpu_box") + Symbols::h_line * (bat_len + 4);
+ bat_pos = bat_len = 0;
+ }
try {
//? Cpu graphs
diff --git a/src/btop_tools.cpp b/src/btop_tools.cpp
index 378ac54..e9f31f8 100644
--- a/src/btop_tools.cpp
+++ b/src/btop_tools.cpp
@@ -257,14 +257,14 @@ namespace Tools {
return (newstr.empty()) ? str : newstr + (string)oldstr;
}
- string sec_to_dhms(size_t seconds) {
+ string sec_to_dhms(size_t seconds, bool no_days, bool no_seconds) {
size_t days = seconds / 86400; seconds %= 86400;
size_t hours = seconds / 3600; seconds %= 3600;
size_t minutes = seconds / 60; seconds %= 60;
- string out = (days > 0 ? to_string(days) + "d " : "")
- + (hours < 10 ? "0" : "") + to_string(hours) + ":"
- + (minutes < 10 ? "0" : "") + to_string(minutes) + ":"
- + (seconds < 10 ? "0" : "") + to_string(seconds);
+ string out = (not no_days and days > 0 ? to_string(days) + "d " : "")
+ + (hours < 10 ? "0" : "") + to_string(hours) + ':'
+ + (minutes < 10 ? "0" : "") + to_string(minutes)
+ + (not no_seconds ? ':' + (seconds < 10 ? "0" : "") + to_string(seconds) : "");
return out;
}
diff --git a/src/btop_tools.hpp b/src/btop_tools.hpp
index c8ad871..da4a784 100644
--- a/src/btop_tools.hpp
+++ b/src/btop_tools.hpp
@@ -252,7 +252,7 @@ namespace Tools {
string trans(const string& str);
//* Convert seconds to format "<days>d <hours>:<minutes>:<seconds>" and return string
- string sec_to_dhms(size_t seconds);
+ 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