Added: Toggle in options for enabling directional vim keys "h,j,k,l"

This commit is contained in:
aristocratos 2021-10-12 17:34:52 +02:00
parent 07145f9351
commit 2df9b58ff1
4 changed files with 35 additions and 18 deletions

View File

@ -54,6 +54,9 @@ namespace Config {
"#* Use withespace \" \" as seprator between different presets.\n" "#* Use withespace \" \" as seprator between different presets.\n"
"#* Example: \"cpu:0:default,mem:0:tty,proc:1:default cpu:0:braille,proc:0:tty\""}, "#* 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."}, {"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" {"graph_symbol", "#* Default symbols to use for graph creation, \"braille\", \"block\" or \"tty\".\n"
@ -231,6 +234,7 @@ namespace Config {
{"net_auto", true}, {"net_auto", true},
{"net_sync", false}, {"net_sync", false},
{"show_battery", true}, {"show_battery", true},
{"vim_keys", false},
{"tty_mode", false}, {"tty_mode", false},
{"force_tty", false}, {"force_tty", false},
{"lowcolor", false}, {"lowcolor", false},

View File

@ -1039,9 +1039,10 @@ namespace Proc {
auto selected = Config::getI("proc_selected"); auto selected = Config::getI("proc_selected");
auto last_selected = Config::getI("proc_last_selected"); auto last_selected = Config::getI("proc_last_selected");
const int select_max = (Config::getB("show_detailed") ? Proc::select_max - 8 : Proc::select_max); 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; 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--; if (start > 0 and selected == 1) start--;
else selected--; else selected--;
if (Config::getI("proc_last_selected") > 0) Config::set("proc_last_selected", 0); 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) { else if (cmd_key == "mouse_scroll_down" and start < numpids - select_max) {
start = min(numpids - select_max, start + 3); 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++; if (start < numpids - select_max and selected == select_max) start++;
else if (selected == 0 and last_selected > 0) { else if (selected == 0 and last_selected > 0) {
selected = last_selected; selected = last_selected;

View File

@ -182,7 +182,9 @@ namespace Input {
if (key.empty()) return; if (key.empty()) return;
try { try {
auto& filtering = Config::getB("proc_filtering"); 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 //? Global input actions
if (not filtering) { if (not filtering) {
bool keep_going = false; bool keep_going = false;
@ -193,7 +195,7 @@ namespace Input {
Menu::show(Menu::Menus::Main); Menu::show(Menu::Menus::Main);
return; return;
} }
else if (is_in(key, "F1", "h")) { else if (is_in(key, "F1", help_key)) {
Menu::show(Menu::Menus::Help); Menu::show(Menu::Menus::Help);
return; return;
} }
@ -252,13 +254,13 @@ namespace Input {
else else
return; 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")); int cur_i = v_index(Proc::sort_vector, Config::getS("proc_sorting"));
if (--cur_i < 0) if (--cur_i < 0)
cur_i = Proc::sort_vector.size() - 1; cur_i = Proc::sort_vector.size() - 1;
Config::set("proc_sorting", Proc::sort_vector.at(cur_i)); 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")); int cur_i = v_index(Proc::sort_vector, Config::getS("proc_sorting"));
if (std::cmp_greater(++cur_i, Proc::sort_vector.size() - 1)) if (std::cmp_greater(++cur_i, Proc::sort_vector.size() - 1))
cur_i = 0; cur_i = 0;
@ -344,7 +346,7 @@ namespace Input {
if (key == "-" or key == "space") Proc::collapse = pid; if (key == "-" or key == "space") Proc::collapse = pid;
no_update = false; 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); atomic_wait(Runner::active);
if (Config::getB("show_detailed") and Config::getI("proc_selected") == 0 and Proc::detailed.status == "Dead") return; 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)); Menu::show(Menu::Menus::SignalSend, (key == "t" ? SIGTERM : SIGKILL));
@ -356,7 +358,7 @@ namespace Input {
Menu::show(Menu::Menus::SignalChoose); Menu::show(Menu::Menus::SignalChoose);
return; 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: proc_mouse_scroll:
redraw = false; redraw = false;
auto old_selected = Config::getI("proc_selected"); auto old_selected = Config::getI("proc_selected");

View File

@ -177,6 +177,15 @@ namespace Menu {
"Will force 16-color mode and TTY theme,", "Will force 16-color mode and TTY theme,",
"set all graph symbols to \"tty\" and swap", "set all graph symbols to \"tty\" and swap",
"out other non tty friendly symbols."}, "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", {"presets",
"Define presets for the layout of the boxes.", "Define presets for the layout of the boxes.",
"", "",
@ -695,7 +704,7 @@ namespace Menu {
else if (key == "backspace" and selected_signal != -1) { else if (key == "backspace" and selected_signal != -1) {
selected_signal = (selected_signal < 10 ? -1 : selected_signal / 10); 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; if (selected_signal == 1) selected_signal = 31;
else if (selected_signal < 6) selected_signal += 25; else if (selected_signal < 6) selected_signal += 25;
else { else {
@ -704,7 +713,7 @@ namespace Menu {
if (selected_signal <= 16 and offset) selected_signal--; 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; if (selected_signal == 31) selected_signal = 1;
else if (selected_signal < 1 or selected_signal == 16) selected_signal = 1; else if (selected_signal < 1 or selected_signal == 16) selected_signal = 1;
else if (selected_signal > 26) selected_signal -= 25; else if (selected_signal > 26) selected_signal -= 25;
@ -715,11 +724,11 @@ namespace Menu {
if (selected_signal > 31) selected_signal = 31; 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; if (--selected_signal < 1) selected_signal = 31;
else if (selected_signal == 16) selected_signal--; 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; if (++selected_signal > 31) selected_signal = 1;
else if (selected_signal == 16) selected_signal++; else if (selected_signal == 16) selected_signal++;
} }
@ -903,10 +912,10 @@ namespace Menu {
exit(0); 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; 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; if (--selected < 0) selected = 2;
} }
else { else {
@ -956,6 +965,7 @@ namespace Menu {
{"cpu_sensor", std::cref(Cpu::available_sensors)} {"cpu_sensor", std::cref(Cpu::available_sensors)}
}; };
auto& tty_mode = Config::getB("tty_mode"); auto& tty_mode = Config::getB("tty_mode");
auto& vim_keys = Config::getB("vim_keys");
if (max_items == 0) { if (max_items == 0) {
for (const auto& cat : categories) { for (const auto& cat : categories) {
if ((int)cat.size() > max_items) max_items = cat.size(); 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")) { else if (is_in(key, "escape", "q", "o", "backspace")) {
return Closed; 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 (++selected > select_max or selected >= item_height) {
if (page < pages - 1) page++; if (page < pages - 1) page++;
else if (pages > 1) page = 0; else if (pages > 1) page = 0;
selected = 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 (--selected < 0) {
if (page > 0) page--; if (page > 0) page--;
else if (pages > 1) page = pages - 1; else if (pages > 1) page = pages - 1;
@ -1089,12 +1099,12 @@ namespace Menu {
selected_cat = key.back() - '0' - 1; selected_cat = key.back() - '0' - 1;
page = selected = 0; 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]; const auto& option = categories[selected_cat][item_height * page + selected][0];
if (selPred.test(isInt)) { if (selPred.test(isInt)) {
const int mod = (option == "update_ms" ? 100 : 1); const int mod = (option == "update_ms" ? 100 : 1);
long value = Config::getI(option); long value = Config::getI(option);
if (key == "right") value += mod; if (key == "right" or (vim_keys and key == "l")) value += mod;
else value -= mod; else value -= mod;
if (Config::intValid(option, to_string(value))) if (Config::intValid(option, to_string(value)))