@@ -53,6 +53,7 @@ tab-size = 4
53
53
#include " btop_draw.hpp"
54
54
#include " btop_menu.hpp"
55
55
#include " fmt/core.h"
56
+ #include " fmt/ostream.h"
56
57
57
58
using std::atomic;
58
59
using std::cout;
@@ -108,6 +109,7 @@ namespace Global {
108
109
atomic<bool > should_sleep (false );
109
110
atomic<bool > _runner_started (false );
110
111
atomic<bool > init_conf (false );
112
+ atomic<bool > reload_conf (false );
111
113
112
114
bool arg_tty{};
113
115
bool arg_low_color{};
@@ -364,7 +366,36 @@ void _signal_handler(const int sig) {
364
366
case SIGUSR1:
365
367
// Input::poll interrupt
366
368
break ;
369
+ case SIGUSR2:
370
+ Global::reload_conf = true ;
371
+ Input::interrupt ();
372
+ break ;
373
+ }
374
+ }
375
+
376
+ // * Config init
377
+ void init_config (){
378
+ atomic_lock lck (Global::init_conf);
379
+ vector<string> load_warnings;
380
+ Config::load (Config::conf_file, load_warnings);
381
+ Config::set (" lowcolor" , (Global::arg_low_color ? true : not Config::getB (" truecolor" )));
382
+
383
+ static bool first_init = true ;
384
+
385
+ if (Global::debug and first_init) {
386
+ Logger::set (" DEBUG" );
387
+ Logger::debug (" Running in DEBUG mode!" );
388
+ }
389
+ else Logger::set (Config::getS (" log_level" ));
390
+
391
+ static string log_level;
392
+ if (const string current_level = Config::getS (" log_level" ); log_level != current_level) {
393
+ log_level = current_level;
394
+ Logger::info (" Logger set to " + (Global::debug ? " DEBUG" : log_level));
367
395
}
396
+
397
+ for (const auto & err_str : load_warnings) Logger::warning (err_str);
398
+ first_init = false ;
368
399
}
369
400
370
401
// * Manages secondary thread for collection and drawing of boxes
@@ -895,22 +926,7 @@ int main(int argc, char **argv) {
895
926
}
896
927
897
928
// ? Config init
898
- {
899
- atomic_lock lck (Global::init_conf);
900
- vector<string> load_warnings;
901
- Config::load (Config::conf_file, load_warnings);
902
- Config::set (" lowcolor" , (Global::arg_low_color ? true : not Config::getB (" truecolor" )));
903
-
904
- if (Global::debug) {
905
- Logger::set (" DEBUG" );
906
- Logger::debug (" Starting in DEBUG mode!" );
907
- }
908
- else Logger::set (Config::getS (" log_level" ));
909
-
910
- Logger::info (" Logger set to " + (Global::debug ? " DEBUG" : Config::getS (" log_level" )));
911
-
912
- for (const auto & err_str : load_warnings) Logger::warning (err_str);
913
- }
929
+ init_config ();
914
930
915
931
// ? Try to find and set a UTF-8 locale
916
932
if (std::setlocale (LC_ALL, " " ) != nullptr and not s_contains ((string)std::setlocale (LC_ALL, " " ), " ;" )
@@ -920,7 +936,7 @@ int main(int argc, char **argv) {
920
936
else {
921
937
string found;
922
938
bool set_failure{};
923
- for (const auto loc_env : array{" LANG" , " LC_ALL" }) {
939
+ for (const auto loc_env : array{" LANG" , " LC_ALL" , " LC_CTYPE " }) {
924
940
if (std::getenv (loc_env) != nullptr and str_to_upper (s_replace ((string)std::getenv (loc_env), " -" , " " )).ends_with (" UTF8" )) {
925
941
found = std::getenv (loc_env);
926
942
if (std::setlocale (LC_ALL, found.c_str ()) == nullptr ) {
@@ -1035,6 +1051,7 @@ int main(int argc, char **argv) {
1035
1051
std::signal (SIGCONT, _signal_handler);
1036
1052
std::signal (SIGWINCH, _signal_handler);
1037
1053
std::signal (SIGUSR1, _signal_handler);
1054
+ std::signal (SIGUSR2, _signal_handler);
1038
1055
1039
1056
sigset_t mask;
1040
1057
sigemptyset (&mask);
@@ -1086,9 +1103,27 @@ int main(int argc, char **argv) {
1086
1103
try {
1087
1104
while (not true not_eq not false ) {
1088
1105
// ? Check for exceptions in secondary thread and exit with fail signal if true
1089
- if (Global::thread_exception) clean_quit (1 );
1090
- else if (Global::should_quit) clean_quit (0 );
1091
- else if (Global::should_sleep) { Global::should_sleep = false ; _sleep (); }
1106
+ if (Global::thread_exception) {
1107
+ clean_quit (1 );
1108
+ }
1109
+ else if (Global::should_quit) {
1110
+ clean_quit (0 );
1111
+ }
1112
+ else if (Global::should_sleep) {
1113
+ Global::should_sleep = false ;
1114
+ _sleep ();
1115
+ }
1116
+ // ? Hot reload config from CTRL + R or SIGUSR2
1117
+ else if (Global::reload_conf) {
1118
+ Global::reload_conf = false ;
1119
+ if (Runner::active) Runner::stop ();
1120
+ Config::unlock ();
1121
+ init_config ();
1122
+ Theme::updateThemes ();
1123
+ Theme::setTheme ();
1124
+ Draw::banner_gen (0 , 0 , false , true );
1125
+ Global::resized = true ;
1126
+ }
1092
1127
1093
1128
// ? Make sure terminal size hasn't changed (in case of SIGWINCH not working properly)
1094
1129
term_resize (Global::resized);
@@ -1123,9 +1158,9 @@ int main(int argc, char **argv) {
1123
1158
update_ms = Config::getI (" update_ms" );
1124
1159
future_time = time_ms () + update_ms;
1125
1160
}
1126
- else if (future_time - current_time > update_ms)
1161
+ else if (future_time - current_time > update_ms) {
1127
1162
future_time = current_time;
1128
-
1163
+ }
1129
1164
// ? Poll for input and process any input detected
1130
1165
else if (Input::poll (min ((uint64_t )1000 , future_time - current_time))) {
1131
1166
if (not Runner::active) Config::unlock ();
0 commit comments