From 73e42780f47fc14abbaaa04f8dadf8262b8552a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Mon, 19 Apr 2021 01:06:31 +0300 Subject: [PATCH] Add more keybinds for scrolling in pager(1) b commonly corresponds to Page Up, and f is added to match. j and k for lines, ^F and ^B for pages, and g and G for home/end are from vi. C-n and C-p for lines and C-v and M-v for pages are from Emacs. < and > for home/end allow using Emacs M-< and M->, tho they are from less(1). --- utils/pager.1 | 14 +++++++------- utils/pager.c | 30 ++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/utils/pager.1 b/utils/pager.1 index 88376f71..10243e40 100644 --- a/utils/pager.1 +++ b/utils/pager.1 @@ -31,19 +31,19 @@ to show only selected escape codes. .Nm supports the following key commands: .Bl -tag -width "12345678" -.It Enter or Down Arrow +.It Sy Enter , Down Arrow , j , ^N Scroll the file one line down. -.It Up Arrow +.It Sy Up Arrow , k , ^P Scroll the file one line up. -.It Space or Page Down +.It Sy Space , Page Down , f , ^F , ^V Scroll the file one page down. -.It Page Up +.It Sy Page Up , b , ^B , ESC-v Scroll the file one page up. -.It End +.It Sy End , G , > Scroll all the way down to the end of the file. -.It Home +.It Sy Home , g , < Scroll all the way up to the beginning of the file. -.It q or Q +.It Sy q , Q Exit the pager. .El .Sh EXIT STATUS diff --git a/utils/pager.c b/utils/pager.c index aa70c6ad..b3b9acf3 100644 --- a/utils/pager.c +++ b/utils/pager.c @@ -162,14 +162,19 @@ static void prompt(bool at_end) } buffer[buffer_used] = '\0'; - if ( !strcmp(buffer, "\n") || !strcmp(buffer, "\e[B") ) + if ( !strcmp(buffer, "\n") || + !strcmp(buffer, "j") || + !strcmp(buffer, "\x0e") /* ^N */ || + !strcmp(buffer, "\e[B") /* Down Arrow */ ) { dprintf(1, "\r\e[J"); allowed_lines++; return; } - if ( !strcmp(buffer, "\e[A") ) + if ( !strcmp(buffer, "k") || + !strcmp(buffer, "\x10") /* ^P */ || + !strcmp(buffer, "\e[A") /* Up Arrow */ ) { if ( current_line <= possible_lines ) continue; @@ -180,14 +185,21 @@ static void prompt(bool at_end) return; } - if ( !strcmp(buffer, " ") || !strcmp(buffer, "\e[6~") ) + if ( !strcmp(buffer, " ") || + !strcmp(buffer, "f") || + !strcmp(buffer, "\x06") /* ^F */ || + !strcmp(buffer, "\x16") /* ^V */ || + !strcmp(buffer, "\e[6~") /* Page Down */ ) { dprintf(1, "\r\e[J"); allowed_lines = possible_lines; return; } - if ( !strcmp(buffer, "\e[5~") ) + if ( !strcmp(buffer, "b") || + !strcmp(buffer, "\x02") /* ^B */ || + !strcmp(buffer, "\ev") /* ESC-v */ || + !strcmp(buffer, "\e[5~") /* Page Up */) { if ( current_line <= possible_lines ) continue; @@ -201,7 +213,10 @@ static void prompt(bool at_end) return; } - if ( !strcmp(buffer, "\e[F") || !strcmp(buffer, "\e[4~") ) + if ( !strcmp(buffer, ">") || + !strcmp(buffer, "G") || + !strcmp(buffer, "\e[F") /* End */ || + !strcmp(buffer, "\e[4~") /* End (Linux console) */ ) { dprintf(1, "\r\e[J"); skipping_to_end = true; @@ -209,7 +224,10 @@ static void prompt(bool at_end) return; } - if ( !strcmp(buffer, "\e[H") || !strcmp(buffer, "\e[1~") ) + if ( !strcmp(buffer, "<") || + !strcmp(buffer, "g") || + !strcmp(buffer, "\e[H") /* Home */ || + !strcmp(buffer, "\e[1~") /* Home (Linux console) */ ) { if ( current_line <= possible_lines ) continue;