mirror of https://github.com/aristocratos/btop.git
Merge branch 'aristocratos:main' into restore-from-maximized
This commit is contained in:
commit
b980e5a2f7
|
@ -36,18 +36,19 @@ jobs:
|
|||
- name: Compile
|
||||
uses: vmactions/freebsd-vm@v0
|
||||
with:
|
||||
release: 13.1
|
||||
release: 13.2
|
||||
usesh: true
|
||||
prepare: |
|
||||
pkg install -y gmake gcc11 coreutils git
|
||||
git config --global --add safe.directory /Users/runner/work/btop/btop
|
||||
run: |
|
||||
gmake
|
||||
gmake STATIC=true STRIP=true
|
||||
GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")
|
||||
mv bin/btop bin/btop-$GIT_HASH
|
||||
ls -alh bin
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: btop-x86_64-FreeBSD-13.1
|
||||
name: btop-x86_64-FreeBSD-13.2
|
||||
path: 'bin/*'
|
||||
if-no-files-found: error
|
||||
|
|
6
Makefile
6
Makefile
|
@ -57,7 +57,11 @@ ifeq ($(CXX_IS_CLANG),true)
|
|||
endif
|
||||
ifeq ($(CLANG_WORKS),false)
|
||||
#? Try to find a newer GCC version
|
||||
ifeq ($(shell command -v g++-12 >/dev/null; echo $$?),0)
|
||||
ifeq ($(shell command -v g++-13 >/dev/null; echo $$?),0)
|
||||
CXX := g++-13
|
||||
else ifeq ($(shell command -v g++13 >/dev/null; echo $$?),0)
|
||||
CXX := g++13
|
||||
else ifeq ($(shell command -v g++-12 >/dev/null; echo $$?),0)
|
||||
CXX := g++-12
|
||||
else ifeq ($(shell command -v g++12 >/dev/null; echo $$?),0)
|
||||
CXX := g++12
|
||||
|
|
|
@ -17,11 +17,13 @@ tab-size = 4
|
|||
*/
|
||||
|
||||
#include <array>
|
||||
#include <ranges>
|
||||
#include <atomic>
|
||||
#include <fstream>
|
||||
#include <ranges>
|
||||
#include <string_view>
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include "btop_config.hpp"
|
||||
#include "btop_shared.hpp"
|
||||
#include "btop_tools.hpp"
|
||||
|
@ -193,7 +195,7 @@ namespace Config {
|
|||
"#* The level set includes all lower levels, i.e. \"DEBUG\" will show all logging info."}
|
||||
};
|
||||
|
||||
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"},
|
||||
|
@ -219,9 +221,9 @@ namespace Config {
|
|||
{"proc_command", ""},
|
||||
{"selected_name", ""},
|
||||
};
|
||||
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},
|
||||
|
@ -268,9 +270,9 @@ namespace Config {
|
|||
{"proc_filtering", false},
|
||||
{"is_maximized", false},
|
||||
};
|
||||
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},
|
||||
|
@ -281,9 +283,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;
|
||||
|
@ -370,7 +372,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);
|
||||
|
@ -400,7 +402,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;
|
||||
|
||||
|
@ -408,7 +410,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!";
|
||||
|
@ -457,7 +459,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))
|
||||
|
@ -467,7 +469,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)));
|
||||
|
|
|
@ -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" };
|
||||
|
@ -68,44 +69,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();
|
||||
|
|
|
@ -543,14 +543,16 @@ namespace Mem {
|
|||
|
||||
// find all zpools in the system. Do this only at startup.
|
||||
void get_zpools() {
|
||||
std::regex toReplace("\\.");
|
||||
PipeWrapper poolPipe = PipeWrapper("zpool list -H -o name", "r");
|
||||
|
||||
while (not std::feof(poolPipe())) {
|
||||
char poolName[512];
|
||||
size_t len = 512;
|
||||
if (fgets(poolName, len, poolPipe())) {
|
||||
poolName[strcspn(poolName, "\n")] = 0;
|
||||
Logger::debug("zpool found: " + string(poolName));
|
||||
Mem::zpools.push_back(poolName);
|
||||
Mem::zpools.push_back(std::regex_replace(poolName, toReplace, "%25"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -583,7 +585,7 @@ namespace Mem {
|
|||
}
|
||||
|
||||
// this code is for ZFS mounts
|
||||
for (string poolName : Mem::zpools) {
|
||||
for (const auto &poolName : Mem::zpools) {
|
||||
char sysCtl[1024];
|
||||
snprintf(sysCtl, sizeof(sysCtl), "sysctl kstat.zfs.%s.dataset | egrep \'dataset_name|nread|nwritten\'", poolName.c_str());
|
||||
PipeWrapper f = PipeWrapper(sysCtl, "r");
|
||||
|
|
|
@ -73,7 +73,6 @@ namespace Cpu {
|
|||
vector<string> available_fields = {"total"};
|
||||
vector<string> available_sensors = {"Auto"};
|
||||
cpu_info current_cpu;
|
||||
fs::path freq_path = "/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq";
|
||||
bool got_sensors = false, cpu_temp_only = false;
|
||||
int core_offset = 0;
|
||||
|
||||
|
@ -164,7 +163,6 @@ namespace Shared {
|
|||
arg_max = sysconf(_SC_ARG_MAX);
|
||||
|
||||
//? Init for namespace Cpu
|
||||
if (not fs::exists(Cpu::freq_path) or access(Cpu::freq_path.c_str(), R_OK) == -1) Cpu::freq_path.clear();
|
||||
Cpu::current_cpu.core_percent.insert(Cpu::current_cpu.core_percent.begin(), Shared::coreCount, {});
|
||||
Cpu::current_cpu.temp.insert(Cpu::current_cpu.temp.begin(), Shared::coreCount + 1, {});
|
||||
Cpu::core_old_totals.insert(Cpu::core_old_totals.begin(), Shared::coreCount, 0);
|
||||
|
|
|
@ -18,6 +18,9 @@ tab-size = 4
|
|||
|
||||
#include "smc.hpp"
|
||||
|
||||
static constexpr size_t MaxIndexCount = sizeof("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") - 1;
|
||||
static constexpr const char *KeyIndexes = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
static UInt32 _strtoul(char *str, int size, int base) {
|
||||
UInt32 total = 0;
|
||||
int i;
|
||||
|
@ -34,7 +37,7 @@ static UInt32 _strtoul(char *str, int size, int base) {
|
|||
|
||||
static void _ultostr(char *str, UInt32 val) {
|
||||
str[0] = '\0';
|
||||
sprintf(str, "%c%c%c%c",
|
||||
snprintf(str, 5, "%c%c%c%c",
|
||||
(unsigned int)val >> 24,
|
||||
(unsigned int)val >> 16,
|
||||
(unsigned int)val >> 8,
|
||||
|
@ -44,10 +47,8 @@ static void _ultostr(char *str, UInt32 val) {
|
|||
namespace Cpu {
|
||||
|
||||
SMCConnection::SMCConnection() {
|
||||
IOMasterPort(kIOMasterPortDefault, &masterPort);
|
||||
|
||||
CFMutableDictionaryRef matchingDictionary = IOServiceMatching("AppleSMC");
|
||||
result = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator);
|
||||
result = IOServiceGetMatchingServices(0, matchingDictionary, &iterator);
|
||||
if (result != kIOReturnSuccess) {
|
||||
throw std::runtime_error("failed to get AppleSMC");
|
||||
}
|
||||
|
@ -92,12 +93,15 @@ namespace Cpu {
|
|||
long long SMCConnection::getTemp(int core) {
|
||||
char key[] = SMC_KEY_CPU_TEMP;
|
||||
if (core >= 0) {
|
||||
snprintf(key, 5, "TC%1dc", core);
|
||||
if ((size_t)core > MaxIndexCount) {
|
||||
return -1;
|
||||
}
|
||||
snprintf(key, 5, "TC%1cc", KeyIndexes[core]);
|
||||
}
|
||||
long long result = getSMCTemp(key);
|
||||
if (result == -1) {
|
||||
// try again with C
|
||||
snprintf(key, 5, "TC%1dC", core);
|
||||
snprintf(key, 5, "TC%1dC", KeyIndexes[core]);
|
||||
result = getSMCTemp(key);
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue