From 3a5e5fd5d37da33cbec48635f5c97502c824755b Mon Sep 17 00:00:00 2001 From: romner Date: Wed, 19 Jul 2023 16:22:45 +0200 Subject: [PATCH] Improve 0-10 key input --- src/btop.cpp | 8 +++++--- src/btop_input.cpp | 18 +++++------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/btop.cpp b/src/btop.cpp index 5001126..02e6af2 100644 --- a/src/btop.cpp +++ b/src/btop.cpp @@ -187,7 +187,7 @@ void term_resize(bool force) { } else return; - static const array all_boxes = {"cpu", "mem", "net", "proc", "gpu"}; + static const array 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"); } } diff --git a/src/btop_input.cpp b/src/btop_input.cpp index 60d717c..8c0904a 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -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 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 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;