mirror of
https://github.com/aristocratos/btop.git
synced 2024-05-18 19:33:03 +12:00
Merge pull request #722 from MartinPit/hot-reload
This commit is contained in:
commit
97e78ebb12
76
src/btop.cpp
76
src/btop.cpp
|
@ -109,6 +109,7 @@ namespace Global {
|
||||||
atomic<bool> should_sleep (false);
|
atomic<bool> should_sleep (false);
|
||||||
atomic<bool> _runner_started (false);
|
atomic<bool> _runner_started (false);
|
||||||
atomic<bool> init_conf (false);
|
atomic<bool> init_conf (false);
|
||||||
|
atomic<bool> reload_conf (false);
|
||||||
|
|
||||||
bool arg_tty{};
|
bool arg_tty{};
|
||||||
bool arg_low_color{};
|
bool arg_low_color{};
|
||||||
|
@ -365,9 +366,38 @@ void _signal_handler(const int sig) {
|
||||||
case SIGUSR1:
|
case SIGUSR1:
|
||||||
// Input::poll interrupt
|
// Input::poll interrupt
|
||||||
break;
|
break;
|
||||||
|
case SIGUSR2:
|
||||||
|
Global::reload_conf = true;
|
||||||
|
Input::interrupt();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//* Config init
|
||||||
|
void init_config(){
|
||||||
|
atomic_lock lck(Global::init_conf);
|
||||||
|
vector<string> load_warnings;
|
||||||
|
Config::load(Config::conf_file, load_warnings);
|
||||||
|
Config::set("lowcolor", (Global::arg_low_color ? true : not Config::getB("truecolor")));
|
||||||
|
|
||||||
|
static bool first_init = true;
|
||||||
|
|
||||||
|
if (Global::debug and first_init) {
|
||||||
|
Logger::set("DEBUG");
|
||||||
|
Logger::debug("Running in DEBUG mode!");
|
||||||
|
}
|
||||||
|
else Logger::set(Config::getS("log_level"));
|
||||||
|
|
||||||
|
static string log_level;
|
||||||
|
if (const string current_level = Config::getS("log_level"); log_level != current_level) {
|
||||||
|
log_level = current_level;
|
||||||
|
Logger::info("Logger set to " + (Global::debug ? "DEBUG" : log_level));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& err_str : load_warnings) Logger::warning(err_str);
|
||||||
|
first_init = false;
|
||||||
|
}
|
||||||
|
|
||||||
//* Manages secondary thread for collection and drawing of boxes
|
//* Manages secondary thread for collection and drawing of boxes
|
||||||
namespace Runner {
|
namespace Runner {
|
||||||
atomic<bool> active (false);
|
atomic<bool> active (false);
|
||||||
|
@ -896,22 +926,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//? Config init
|
//? Config init
|
||||||
{
|
init_config();
|
||||||
atomic_lock lck(Global::init_conf);
|
|
||||||
vector<string> load_warnings;
|
|
||||||
Config::load(Config::conf_file, load_warnings);
|
|
||||||
Config::set("lowcolor", (Global::arg_low_color ? true : not Config::getB("truecolor")));
|
|
||||||
|
|
||||||
if (Global::debug) {
|
|
||||||
Logger::set("DEBUG");
|
|
||||||
Logger::debug("Starting in DEBUG mode!");
|
|
||||||
}
|
|
||||||
else Logger::set(Config::getS("log_level"));
|
|
||||||
|
|
||||||
Logger::info("Logger set to " + (Global::debug ? "DEBUG" : Config::getS("log_level")));
|
|
||||||
|
|
||||||
for (const auto& err_str : load_warnings) Logger::warning(err_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
//? Try to find and set a UTF-8 locale
|
//? Try to find and set a UTF-8 locale
|
||||||
if (std::setlocale(LC_ALL, "") != nullptr and not s_contains((string)std::setlocale(LC_ALL, ""), ";")
|
if (std::setlocale(LC_ALL, "") != nullptr and not s_contains((string)std::setlocale(LC_ALL, ""), ";")
|
||||||
|
@ -1036,6 +1051,7 @@ int main(int argc, char **argv) {
|
||||||
std::signal(SIGCONT, _signal_handler);
|
std::signal(SIGCONT, _signal_handler);
|
||||||
std::signal(SIGWINCH, _signal_handler);
|
std::signal(SIGWINCH, _signal_handler);
|
||||||
std::signal(SIGUSR1, _signal_handler);
|
std::signal(SIGUSR1, _signal_handler);
|
||||||
|
std::signal(SIGUSR2, _signal_handler);
|
||||||
|
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
sigemptyset(&mask);
|
sigemptyset(&mask);
|
||||||
|
@ -1087,9 +1103,27 @@ int main(int argc, char **argv) {
|
||||||
try {
|
try {
|
||||||
while (not true not_eq not false) {
|
while (not true not_eq not false) {
|
||||||
//? Check for exceptions in secondary thread and exit with fail signal if true
|
//? Check for exceptions in secondary thread and exit with fail signal if true
|
||||||
if (Global::thread_exception) clean_quit(1);
|
if (Global::thread_exception) {
|
||||||
else if (Global::should_quit) clean_quit(0);
|
clean_quit(1);
|
||||||
else if (Global::should_sleep) { Global::should_sleep = false; _sleep(); }
|
}
|
||||||
|
else if (Global::should_quit) {
|
||||||
|
clean_quit(0);
|
||||||
|
}
|
||||||
|
else if (Global::should_sleep) {
|
||||||
|
Global::should_sleep = false;
|
||||||
|
_sleep();
|
||||||
|
}
|
||||||
|
//? Hot reload config from CTRL + R or SIGUSR2
|
||||||
|
else if (Global::reload_conf) {
|
||||||
|
Global::reload_conf = false;
|
||||||
|
if (Runner::active) Runner::stop();
|
||||||
|
Config::unlock();
|
||||||
|
init_config();
|
||||||
|
Theme::updateThemes();
|
||||||
|
Theme::setTheme();
|
||||||
|
Draw::banner_gen(0, 0, false, true);
|
||||||
|
Global::resized = true;
|
||||||
|
}
|
||||||
|
|
||||||
//? Make sure terminal size hasn't changed (in case of SIGWINCH not working properly)
|
//? Make sure terminal size hasn't changed (in case of SIGWINCH not working properly)
|
||||||
term_resize(Global::resized);
|
term_resize(Global::resized);
|
||||||
|
@ -1124,9 +1158,9 @@ int main(int argc, char **argv) {
|
||||||
update_ms = Config::getI("update_ms");
|
update_ms = Config::getI("update_ms");
|
||||||
future_time = time_ms() + update_ms;
|
future_time = time_ms() + update_ms;
|
||||||
}
|
}
|
||||||
else if (future_time - current_time > update_ms)
|
else if (future_time - current_time > update_ms) {
|
||||||
future_time = current_time;
|
future_time = current_time;
|
||||||
|
}
|
||||||
//? Poll for input and process any input detected
|
//? Poll for input and process any input detected
|
||||||
else if (Input::poll(min((uint64_t)1000, future_time - current_time))) {
|
else if (Input::poll(min((uint64_t)1000, future_time - current_time))) {
|
||||||
if (not Runner::active) Config::unlock();
|
if (not Runner::active) Config::unlock();
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace Input {
|
||||||
//* Map for translating key codes to readable values
|
//* Map for translating key codes to readable values
|
||||||
const std::unordered_map<string, string> Key_escapes = {
|
const std::unordered_map<string, string> Key_escapes = {
|
||||||
{"\033", "escape"},
|
{"\033", "escape"},
|
||||||
|
{"\x12", "ctrl_r"},
|
||||||
{"\n", "enter"},
|
{"\n", "enter"},
|
||||||
{" ", "space"},
|
{" ", "space"},
|
||||||
{"\x7f", "backspace"},
|
{"\x7f", "backspace"},
|
||||||
|
@ -258,8 +259,10 @@ namespace Input {
|
||||||
Draw::calcSizes();
|
Draw::calcSizes();
|
||||||
Runner::run("all", false, true);
|
Runner::run("all", false, true);
|
||||||
return;
|
return;
|
||||||
}
|
} else if (is_in(key, "ctrl_r")) {
|
||||||
else
|
kill(getpid(), SIGUSR2);
|
||||||
|
return;
|
||||||
|
} else
|
||||||
keep_going = true;
|
keep_going = true;
|
||||||
|
|
||||||
if (not keep_going) return;
|
if (not keep_going) return;
|
||||||
|
|
|
@ -177,6 +177,7 @@ namespace Menu {
|
||||||
{"F2, o", "Shows options."},
|
{"F2, o", "Shows options."},
|
||||||
{"F1, ?, h", "Shows this window."},
|
{"F1, ?, h", "Shows this window."},
|
||||||
{"ctrl + z", "Sleep program and put in background."},
|
{"ctrl + z", "Sleep program and put in background."},
|
||||||
|
{"ctrl + r", "Reloads config file from disk."},
|
||||||
{"q, ctrl + c", "Quits program."},
|
{"q, ctrl + c", "Quits program."},
|
||||||
{"+, -", "Add/Subtract 100ms to/from update timer."},
|
{"+, -", "Add/Subtract 100ms to/from update timer."},
|
||||||
{"Up, Down", "Select in process list."},
|
{"Up, Down", "Select in process list."},
|
||||||
|
|
Loading…
Reference in a new issue