Add ctrl+u/d/b/f vim keys (#582)

Ctrl+u/d = fast scroll up/down
Ctrl+b/f = page up/down
This commit is contained in:
Isak 2024-01-19 11:07:47 +01:00
parent b2df50396b
commit ec641d4de2
4 changed files with 25 additions and 4 deletions

View File

@ -63,7 +63,7 @@ namespace Config {
"#* Use whitespace \" \" as separator between different presets.\n" "#* Use whitespace \" \" as separator 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,g,G\" keys for directional control in lists.\n" {"vim_keys", "#* Set to True to enable \"h,j,k,l,g,G,ctrl+u/d/b/f\" keys for directional control in lists.\n"
"#* Conflicting keys for h:\"help\" and k:\"kill\" is accessible while holding shift."}, "#* 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."},

View File

@ -1501,11 +1501,11 @@ namespace Proc {
} }
else selected++; else selected++;
} }
else if (cmd_key == "page_up") { else if (cmd_key == "page_up" or (vim_keys and cmd_key == "ctrl+b")) {
if (selected > 0 and start == 0) selected = 0; if (selected > 0 and start == 0) selected = 0;
else start = max(0, start - select_max); else start = max(0, start - select_max);
} }
else if (cmd_key == "page_down") { else if (cmd_key == "page_down" or (vim_keys and cmd_key == "ctrl+f")) {
if (selected > 0 and start >= numpids - select_max) selected = select_max; if (selected > 0 and start >= numpids - select_max) selected = select_max;
else start = clamp(start + select_max, 0, max(0, numpids - select_max)); else start = clamp(start + select_max, 0, max(0, numpids - select_max));
} }
@ -1517,6 +1517,21 @@ namespace Proc {
start = max(0, numpids - select_max); start = max(0, numpids - select_max);
if (selected > 0) selected = select_max; if (selected > 0) selected = select_max;
} }
else if (vim_keys and cmd_key == "ctrl+u") {
if (start > 0 and selected <= 10) {
start = max(0, start - 10);
}
else selected = max(0, selected - 10);
if (Config::getI("proc_last_selected") > 0) Config::set("proc_last_selected", 0);
}
else if (vim_keys and cmd_key == "ctrl+d") {
if (start < numpids - select_max and selected == select_max) start += 10;
else if (selected == 0 and last_selected > 0) {
selected = last_selected;
Config::set("proc_last_selected", 0);
}
else selected += 10;
}
else if (cmd_key.starts_with("mousey")) { else if (cmd_key.starts_with("mousey")) {
int mouse_y = std::stoi(cmd_key.substr(6)); int mouse_y = std::stoi(cmd_key.substr(6));
start = clamp((int)round((double)mouse_y * (numpids - select_max - 2) / (select_max - 2)), 0, max(0, numpids - select_max)); start = clamp((int)round((double)mouse_y * (numpids - select_max - 2) / (select_max - 2)), 0, max(0, numpids - select_max));

View File

@ -65,6 +65,10 @@ namespace Input {
{"[6~", "page_down"}, {"[6~", "page_down"},
{"\t", "tab"}, {"\t", "tab"},
{"[Z", "shift_tab"}, {"[Z", "shift_tab"},
{"\x15", "ctrl+u"},
{"\x04", "ctrl+d"},
{"\x06", "ctrl+f"},
{"\x02", "ctrl+b"},
{"OP", "f1"}, {"OP", "f1"},
{"OQ", "f2"}, {"OQ", "f2"},
{"OR", "f3"}, {"OR", "f3"},
@ -407,7 +411,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") or (vim_keys and is_in(key, "j", "k", "g", "G"))) { else if (is_in(key, "up", "down", "page_up", "page_down", "home", "end") or (vim_keys and is_in(key, "j", "k", "g", "G", "ctrl+d", "ctrl+u", "ctrl+f", "ctrl+b"))) {
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

@ -246,6 +246,8 @@ namespace Menu {
"Enable vim keys.", "Enable vim keys.",
"Set to True to enable \"h,j,k,l\" keys for", "Set to True to enable \"h,j,k,l\" keys for",
"directional control in lists.", "directional control in lists.",
"Also enables ctrl + u/d for quicker scrolling",
"and ctrl + b/f for page up/down.",
"", "",
"Conflicting keys for", "Conflicting keys for",
"h (help) and k (kill)", "h (help) and k (kill)",