mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-28 07:11:24 +12:00
Merge pull request #640 from imwints/refresh-rate
This commit is contained in:
commit
114a98d813
3 changed files with 27 additions and 5 deletions
24
src/btop.cpp
24
src/btop.cpp
|
@ -16,6 +16,7 @@ indent = tab
|
||||||
tab-size = 4
|
tab-size = 4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
@ -51,6 +52,7 @@ tab-size = 4
|
||||||
#include "btop_theme.hpp"
|
#include "btop_theme.hpp"
|
||||||
#include "btop_draw.hpp"
|
#include "btop_draw.hpp"
|
||||||
#include "btop_menu.hpp"
|
#include "btop_menu.hpp"
|
||||||
|
#include "fmt/core.h"
|
||||||
|
|
||||||
using std::atomic;
|
using std::atomic;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
|
@ -109,15 +111,16 @@ namespace Global {
|
||||||
bool arg_tty{}; // defaults to false
|
bool arg_tty{}; // defaults to false
|
||||||
bool arg_low_color{}; // defaults to false
|
bool arg_low_color{}; // defaults to false
|
||||||
int arg_preset = -1;
|
int arg_preset = -1;
|
||||||
|
int arg_update = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//* A simple argument parser
|
//* A simple argument parser
|
||||||
void argumentParser(const int& argc, char **argv) {
|
void argumentParser(const int argc, char **argv) {
|
||||||
for(int i = 1; i < argc; i++) {
|
for(int i = 1; i < argc; i++) {
|
||||||
const string argument = argv[i];
|
const string argument = argv[i];
|
||||||
if (is_in(argument, "-h", "--help")) {
|
if (is_in(argument, "-h", "--help")) {
|
||||||
fmt::println(
|
fmt::println(
|
||||||
"usage: btop [-h] [-v] [-/+t] [-p <id>] [--utf-force] [--debug]\n\n"
|
"usage: btop [-h] [-v] [-/+t] [-p <id>] [-u <ms>] [--utf-force] [--debug]\n\n"
|
||||||
"optional arguments:\n"
|
"optional arguments:\n"
|
||||||
" -h, --help show this help message and exit\n"
|
" -h, --help show this help message and exit\n"
|
||||||
" -v, --version show version info and exit\n"
|
" -v, --version show version info and exit\n"
|
||||||
|
@ -125,6 +128,7 @@ void argumentParser(const int& argc, char **argv) {
|
||||||
" -t, --tty_on force (ON) tty mode, max 16 colors and tty friendly graph symbols\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"
|
" +t, --tty_off force (OFF) tty mode\n"
|
||||||
" -p, --preset <id> start with preset, integer value between 0-9\n"
|
" -p, --preset <id> start with preset, integer value between 0-9\n"
|
||||||
|
" -u, --update <ms> set the program update rate in milliseconds\n"
|
||||||
" --utf-force force start even if no UTF-8 locale was detected\n"
|
" --utf-force force start even if no UTF-8 locale was detected\n"
|
||||||
" --debug start in DEBUG mode: shows microsecond timer for information collect\n"
|
" --debug start in DEBUG mode: shows microsecond timer for information collect\n"
|
||||||
" and screen draw functions and sets loglevel to DEBUG"
|
" and screen draw functions and sets loglevel to DEBUG"
|
||||||
|
@ -159,6 +163,19 @@ void argumentParser(const int& argc, char **argv) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (is_in(argument, "-u", "--update")) {
|
||||||
|
if (++i >= argc) {
|
||||||
|
fmt::println("ERROR: Update option needs an argument");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
const std::string value = argv[i];
|
||||||
|
if (isint(value)) {
|
||||||
|
Global::arg_update = std::clamp(std::stoi(value), 100, Config::ONE_DAY_MILLIS);
|
||||||
|
} else {
|
||||||
|
fmt::println("ERROR: Invalid update rate");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (argument == "--utf-force")
|
else if (argument == "--utf-force")
|
||||||
Global::utf_force = true;
|
Global::utf_force = true;
|
||||||
else if (argument == "--debug")
|
else if (argument == "--debug")
|
||||||
|
@ -1054,6 +1071,9 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
//? ------------------------------------------------ MAIN LOOP ----------------------------------------------------
|
//? ------------------------------------------------ MAIN LOOP ----------------------------------------------------
|
||||||
|
|
||||||
|
if (Global::arg_update != 0) {
|
||||||
|
Config::set("update_ms", Global::arg_update);
|
||||||
|
}
|
||||||
uint64_t update_ms = Config::getI("update_ms");
|
uint64_t update_ms = Config::getI("update_ms");
|
||||||
auto future_time = time_ms();
|
auto future_time = time_ms();
|
||||||
|
|
||||||
|
|
|
@ -488,8 +488,8 @@ namespace Config {
|
||||||
if (name == "update_ms" and i_value < 100)
|
if (name == "update_ms" and i_value < 100)
|
||||||
validError = "Config value update_ms set too low (<100).";
|
validError = "Config value update_ms set too low (<100).";
|
||||||
|
|
||||||
else if (name == "update_ms" and i_value > 86400000)
|
else if (name == "update_ms" and i_value > ONE_DAY_MILLIS)
|
||||||
validError = "Config value update_ms set too high (>86400000).";
|
validError = fmt::format("Config value update_ms set too high (>{}).", ONE_DAY_MILLIS);
|
||||||
|
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -58,6 +58,8 @@ namespace Config {
|
||||||
extern vector<string> available_batteries;
|
extern vector<string> available_batteries;
|
||||||
extern int current_preset;
|
extern int current_preset;
|
||||||
|
|
||||||
|
constexpr int ONE_DAY_MILLIS = 1000 * 60 * 60 * 24;
|
||||||
|
|
||||||
[[nodiscard]] std::optional<std::filesystem::path> get_config_dir() noexcept;
|
[[nodiscard]] std::optional<std::filesystem::path> get_config_dir() noexcept;
|
||||||
|
|
||||||
//* Check if string only contains space separated valid names for boxes
|
//* Check if string only contains space separated valid names for boxes
|
||||||
|
@ -97,7 +99,7 @@ namespace Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
//* Set config key <name> to int <value>
|
//* Set config key <name> to int <value>
|
||||||
inline void set(const std::string_view name, const int& value) {
|
inline void set(const std::string_view name, const int value) {
|
||||||
if (_locked(name)) intsTmp.insert_or_assign(name, value);
|
if (_locked(name)) intsTmp.insert_or_assign(name, value);
|
||||||
else ints.at(name) = value;
|
else ints.at(name) = value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue