@@ -16,6 +16,7 @@ indent = tab
16
16
tab-size = 4
17
17
*/
18
18
19
+ #include < algorithm>
19
20
#include < csignal>
20
21
#include < clocale>
21
22
#include < pthread.h>
@@ -51,6 +52,7 @@ tab-size = 4
51
52
#include " btop_theme.hpp"
52
53
#include " btop_draw.hpp"
53
54
#include " btop_menu.hpp"
55
+ #include " fmt/core.h"
54
56
55
57
using std::atomic;
56
58
using std::cout;
@@ -109,22 +111,24 @@ namespace Global {
109
111
bool arg_tty{}; // defaults to false
110
112
bool arg_low_color{}; // defaults to false
111
113
int arg_preset = -1 ;
114
+ int arg_update = 0 ;
112
115
}
113
116
114
117
// * A simple argument parser
115
- void argumentParser (const int & argc, char **argv) {
118
+ void argumentParser (const int argc, char **argv) {
116
119
for (int i = 1 ; i < argc; i++) {
117
120
const string argument = argv[i];
118
121
if (is_in (argument, " -h" , " --help" )) {
119
122
fmt::println (
120
- " usage: btop [-h] [-v] [-/+t] [-p <id>] [--utf-force] [--debug]\n\n "
123
+ " usage: btop [-h] [-v] [-/+t] [-p <id>] [-u <ms>] [- -utf-force] [--debug]\n\n "
121
124
" optional arguments:\n "
122
125
" -h, --help show this help message and exit\n "
123
126
" -v, --version show version info and exit\n "
124
127
" -lc, --low-color disable truecolor, converts 24-bit colors to 256-color\n "
125
128
" -t, --tty_on force (ON) tty mode, max 16 colors and tty friendly graph symbols\n "
126
129
" +t, --tty_off force (OFF) tty mode\n "
127
130
" -p, --preset <id> start with preset, integer value between 0-9\n "
131
+ " -u, --update <ms> set the program update rate in milliseconds\n "
128
132
" --utf-force force start even if no UTF-8 locale was detected\n "
129
133
" --debug start in DEBUG mode: shows microsecond timer for information collect\n "
130
134
" and screen draw functions and sets loglevel to DEBUG"
@@ -159,6 +163,19 @@ void argumentParser(const int& argc, char **argv) {
159
163
exit (1 );
160
164
}
161
165
}
166
+ else if (is_in (argument, " -u" , " --update" )) {
167
+ if (++i >= argc) {
168
+ fmt::println (" ERROR: Update option needs an argument" );
169
+ exit (1 );
170
+ }
171
+ const std::string value = argv[i];
172
+ if (isint (value)) {
173
+ Global::arg_update = std::clamp (std::stoi (value), 100 , Config::ONE_DAY_MILLIS);
174
+ } else {
175
+ fmt::println (" ERROR: Invalid update rate" );
176
+ exit (1 );
177
+ }
178
+ }
162
179
else if (argument == " --utf-force" )
163
180
Global::utf_force = true ;
164
181
else if (argument == " --debug" )
@@ -1054,6 +1071,9 @@ int main(int argc, char **argv) {
1054
1071
1055
1072
// ? ------------------------------------------------ MAIN LOOP ----------------------------------------------------
1056
1073
1074
+ if (Global::arg_update != 0 ) {
1075
+ Config::set (" update_ms" , Global::arg_update);
1076
+ }
1057
1077
uint64_t update_ms = Config::getI (" update_ms" );
1058
1078
auto future_time = time_ms ();
1059
1079
0 commit comments