Skip to content

Commit

Permalink
Improve 0-10 key input
Browse files Browse the repository at this point in the history
  • Loading branch information
romner-set committed Jul 19, 2023
1 parent 972b2b6 commit 3a5e5fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/btop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
}
}
Expand Down
18 changes: 5 additions & 13 deletions src/btop_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3a5e5fd

Please sign in to comment.