Skip to content

Commit

Permalink
Add ctrl+u/d/b/f vim keys (#582)
Browse files Browse the repository at this point in the history
Ctrl+u/d = fast scroll up/down
Ctrl+b/f = page up/down
  • Loading branch information
isak102 committed Jan 19, 2024
1 parent b2df503 commit a5e54ef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/btop_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace Config {
"#* Use whitespace \" \" as separator 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,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."},

{"rounded_corners", "#* Rounded corners on boxes, is ignored if TTY mode is ON."},
Expand Down
19 changes: 17 additions & 2 deletions src/btop_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1501,11 +1501,11 @@ namespace Proc {
}
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;
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;
else start = clamp(start + select_max, 0, max(0, numpids - select_max));
}
Expand All @@ -1517,6 +1517,21 @@ namespace Proc {
start = max(0, numpids - 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")) {
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));
Expand Down
6 changes: 5 additions & 1 deletion src/btop_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ namespace Input {
{"[6~", "page_down"},
{"\t", "tab"},
{"[Z", "shift_tab"},
{"\x15", "ctrl+u"},
{"\x04", "ctrl+d"},
{"\x06", "ctrl+f"},
{"\x02", "ctrl+b"},
{"OP", "f1"},
{"OQ", "f2"},
{"OR", "f3"},
Expand Down Expand Up @@ -407,7 +411,7 @@ namespace Input {
Menu::show(Menu::Menus::SignalChoose);
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:
redraw = false;
auto old_selected = Config::getI("proc_selected");
Expand Down
2 changes: 2 additions & 0 deletions src/btop_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ namespace Menu {
"Enable vim keys.",
"Set to True to enable \"h,j,k,l\" keys for",
"directional control in lists.",
"Also enables ctrl + u/d for quicker scrolling",
"and ctrl + f/b for page up/down.",
"",
"Conflicting keys for",
"h (help) and k (kill)",
Expand Down

0 comments on commit a5e54ef

Please sign in to comment.