Improve 0-10 key input

This commit is contained in:
romner 2023-07-19 16:22:45 +02:00
parent 972b2b6a01
commit 3a5e5fd5d3
2 changed files with 10 additions and 16 deletions

View file

@ -187,7 +187,7 @@ void term_resize(bool force) {
}
else return;
static const array<string, 5> all_boxes = {"cpu", "mem", "net", "proc", "gpu"};
static const array<string, 10> all_boxes = {"gpu5", "cpu", "mem", "net", "proc", "gpu0", "gpu1", "gpu2", "gpu3", "gpu4"};
Global::resized = true;
if (Runner::active) Runner::stop();
Term::refresh();
@ -225,9 +225,11 @@ void term_resize(bool force) {
auto key = Input::get();
if (key == "q")
clean_quit(0);
else if (is_in(key, "1", "2", "3", "4")) {
else if (std::isdigit(*key.c_str())) {
Config::current_preset = -1;
Config::toggle_box(all_boxes.at(std::stoi(key) - 1));
auto box = all_boxes.at(*key.c_str() - '0');
if (box.rfind("gpu", 0) == 0 && (box[3] - '0' + 2) > (int)Gpu::gpu_names.size()) return;
Config::toggle_box(box);
boxes = Config::getS("shown_boxes");
}
}

View file

@ -260,21 +260,13 @@ namespace Input {
Menu::show(Menu::Menus::Options);
return;
}
else if (is_in(key, "1", "2", "3", "4")) {
else if (std::isdigit(*key.c_str())) {
atomic_wait(Runner::active);
Config::current_preset = -1;
static const array<string, 4> boxes = {"cpu", "mem", "net", "proc"};
Config::toggle_box(boxes.at(std::stoi(key) - 1));
Draw::calcSizes();
Runner::run("all", false, true);
return;
}
else if (is_in(key, "5", "6", "7", "8", "9", "0")) {
atomic_wait(Runner::active);
Config::current_preset = -1;
auto key_i = key == "0" ? 10 : std::stoi(key);
if (std::cmp_greater(key_i-3, Gpu::gpu_names.size())) return;
Config::toggle_box(std::string("gpu") + (char)(key_i-5 + '0'));
static const array<string, 10> boxes = {"gpu5", "cpu", "mem", "net", "proc", "gpu0", "gpu1", "gpu2", "gpu3", "gpu4"};
auto box = boxes.at(*key.c_str() - '0');
if (box.rfind("gpu", 0) == 0 && (box[3] - '0' + 2) > (int)Gpu::gpu_names.size()) return;
Config::toggle_box(box);
Draw::calcSizes();
Runner::run("all", false, true);
return;