diff --git a/src/btop_config.cpp b/src/btop_config.cpp index 2a1bbc0..a26323f 100644 --- a/src/btop_config.cpp +++ b/src/btop_config.cpp @@ -54,6 +54,9 @@ namespace Config { "#* Use withespace \" \" as seprator between different presets.\n" "#* Example: \"cpu:0:default,mem:0:tty,proc:1:default cpu:0:braille,proc:0:tty\""}, + {"vim_keys", "#* Set to True to enable \"h,j,k,l\" keys for directional control in lists.\n" + "#* Conflicting keys for h:\"help\" and k:\"kill\" is accessible while holding shift."}, + {"rounded_corners", "#* Rounded corners on boxes, is ignored if TTY mode is ON."}, {"graph_symbol", "#* Default symbols to use for graph creation, \"braille\", \"block\" or \"tty\".\n" @@ -231,6 +234,7 @@ namespace Config { {"net_auto", true}, {"net_sync", false}, {"show_battery", true}, + {"vim_keys", false}, {"tty_mode", false}, {"force_tty", false}, {"lowcolor", false}, diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index d290832..a489d37 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -1039,9 +1039,10 @@ namespace Proc { auto selected = Config::getI("proc_selected"); auto last_selected = Config::getI("proc_last_selected"); const int select_max = (Config::getB("show_detailed") ? Proc::select_max - 8 : Proc::select_max); + auto& vim_keys = Config::getB("vim_keys"); int numpids = Proc::numpids; - if (cmd_key == "up" and selected > 0) { + if ((cmd_key == "up" or (vim_keys and cmd_key == "k")) and selected > 0) { if (start > 0 and selected == 1) start--; else selected--; if (Config::getI("proc_last_selected") > 0) Config::set("proc_last_selected", 0); @@ -1052,7 +1053,7 @@ namespace Proc { else if (cmd_key == "mouse_scroll_down" and start < numpids - select_max) { start = min(numpids - select_max, start + 3); } - else if (cmd_key == "down") { + else if (cmd_key == "down" or (vim_keys and cmd_key == "j")) { if (start < numpids - select_max and selected == select_max) start++; else if (selected == 0 and last_selected > 0) { selected = last_selected; diff --git a/src/btop_input.cpp b/src/btop_input.cpp index 2056bea..df9e35a 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -182,7 +182,9 @@ namespace Input { if (key.empty()) return; try { auto& filtering = Config::getB("proc_filtering"); - + auto& vim_keys = Config::getB("vim_keys"); + auto help_key = (vim_keys ? "H" : "h"); + auto kill_key = (vim_keys ? "K" : "k"); //? Global input actions if (not filtering) { bool keep_going = false; @@ -193,7 +195,7 @@ namespace Input { Menu::show(Menu::Menus::Main); return; } - else if (is_in(key, "F1", "h")) { + else if (is_in(key, "F1", help_key)) { Menu::show(Menu::Menus::Help); return; } @@ -252,13 +254,13 @@ namespace Input { else return; } - else if (key == "left") { + else if (key == "left" or (vim_keys and key == "h")) { int cur_i = v_index(Proc::sort_vector, Config::getS("proc_sorting")); if (--cur_i < 0) cur_i = Proc::sort_vector.size() - 1; Config::set("proc_sorting", Proc::sort_vector.at(cur_i)); } - else if (key == "right") { + else if (key == "right" or (vim_keys and key == "l")) { int cur_i = v_index(Proc::sort_vector, Config::getS("proc_sorting")); if (std::cmp_greater(++cur_i, Proc::sort_vector.size() - 1)) cur_i = 0; @@ -344,7 +346,7 @@ namespace Input { if (key == "-" or key == "space") Proc::collapse = pid; no_update = false; } - else if (is_in(key, "t", "k") and (Config::getB("show_detailed") or Config::getI("selected_pid") > 0)) { + else if (is_in(key, "t", kill_key) and (Config::getB("show_detailed") or Config::getI("selected_pid") > 0)) { atomic_wait(Runner::active); if (Config::getB("show_detailed") and Config::getI("proc_selected") == 0 and Proc::detailed.status == "Dead") return; Menu::show(Menu::Menus::SignalSend, (key == "t" ? SIGTERM : SIGKILL)); @@ -356,7 +358,7 @@ namespace Input { Menu::show(Menu::Menus::SignalChoose); return; } - else if (is_in(key, "up", "down", "page_up", "page_down", "home", "end")) { + else if (is_in(key, "up", "down", "page_up", "page_down", "home", "end") or (vim_keys and is_in(key, "j", "k"))) { proc_mouse_scroll: redraw = false; auto old_selected = Config::getI("proc_selected"); diff --git a/src/btop_menu.cpp b/src/btop_menu.cpp index 3128544..6c9eb8d 100644 --- a/src/btop_menu.cpp +++ b/src/btop_menu.cpp @@ -177,6 +177,15 @@ namespace Menu { "Will force 16-color mode and TTY theme,", "set all graph symbols to \"tty\" and swap", "out other non tty friendly symbols."}, + {"vim_keys", + "Enable vim keys.", + "Set to True to enable \"h,j,k,l\" keys for", + "directional control in lists.", + "", + "Conflicting keys for", + "h (help) and k (kill)", + "is accessible while holding shift."}, + {"presets", "Define presets for the layout of the boxes.", "", @@ -695,7 +704,7 @@ namespace Menu { else if (key == "backspace" and selected_signal != -1) { selected_signal = (selected_signal < 10 ? -1 : selected_signal / 10); } - else if (key == "up" and selected_signal != 16) { + else if (is_in(key, "up", "k") and selected_signal != 16) { if (selected_signal == 1) selected_signal = 31; else if (selected_signal < 6) selected_signal += 25; else { @@ -704,7 +713,7 @@ namespace Menu { if (selected_signal <= 16 and offset) selected_signal--; } } - else if (key == "down") { + else if (is_in(key, "down", "j")) { if (selected_signal == 31) selected_signal = 1; else if (selected_signal < 1 or selected_signal == 16) selected_signal = 1; else if (selected_signal > 26) selected_signal -= 25; @@ -715,11 +724,11 @@ namespace Menu { if (selected_signal > 31) selected_signal = 31; } } - else if (key == "left" and selected_signal > 0 and selected_signal != 16) { + else if (is_in(key, "left", "h") and selected_signal > 0 and selected_signal != 16) { if (--selected_signal < 1) selected_signal = 31; else if (selected_signal == 16) selected_signal--; } - else if (key == "right" and selected_signal <= 31 and selected_signal != 16) { + else if (is_in(key, "right", "l") and selected_signal <= 31 and selected_signal != 16) { if (++selected_signal > 31) selected_signal = 1; else if (selected_signal == 16) selected_signal++; } @@ -903,10 +912,10 @@ namespace Menu { exit(0); } } - else if (is_in(key, "down", "tab", "mouse_scroll_down")) { + else if (is_in(key, "down", "tab", "mouse_scroll_down", "j")) { if (++selected > 2) selected = 0; } - else if (is_in(key, "up", "shift_tab", "mouse_scroll_up")) { + else if (is_in(key, "up", "shift_tab", "mouse_scroll_up", "k")) { if (--selected < 0) selected = 2; } else { @@ -956,6 +965,7 @@ namespace Menu { {"cpu_sensor", std::cref(Cpu::available_sensors)} }; auto& tty_mode = Config::getB("tty_mode"); + auto& vim_keys = Config::getB("vim_keys"); if (max_items == 0) { for (const auto& cat : categories) { if ((int)cat.size() > max_items) max_items = cat.size(); @@ -1054,14 +1064,14 @@ namespace Menu { else if (is_in(key, "escape", "q", "o", "backspace")) { return Closed; } - else if (is_in(key, "down", "mouse_scroll_down")) { + else if (is_in(key, "down", "mouse_scroll_down") or (vim_keys and key == "j")) { if (++selected > select_max or selected >= item_height) { if (page < pages - 1) page++; else if (pages > 1) page = 0; selected = 0; } } - else if (is_in(key, "up", "mouse_scroll_up")) { + else if (is_in(key, "up", "mouse_scroll_up") or (vim_keys and key == "k")) { if (--selected < 0) { if (page > 0) page--; else if (pages > 1) page = pages - 1; @@ -1089,12 +1099,12 @@ namespace Menu { selected_cat = key.back() - '0' - 1; page = selected = 0; } - else if (is_in(key, "left", "right")) { + else if (is_in(key, "left", "right") or (vim_keys and is_in(key, "h", "l"))) { const auto& option = categories[selected_cat][item_height * page + selected][0]; if (selPred.test(isInt)) { const int mod = (option == "update_ms" ? 100 : 1); long value = Config::getI(option); - if (key == "right") value += mod; + if (key == "right" or (vim_keys and key == "l")) value += mod; else value -= mod; if (Config::intValid(option, to_string(value)))