move to the prev/next header with Alt + n/p - iomenu - interactive terminal-based selection menu HTML git clone git://bitreich.org/iomenu git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/iomenu DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit e72aa011e805f26becc50b68673bad057a743c39 DIR parent 49b2a2f664d47cd98352daf4068933ae56633cf7 HTML Author: Josuah Demangeon <mail@josuah.net> Date: Sat, 5 May 2018 23:03:27 +0200 move to the prev/next header with Alt + n/p Diffstat: M iomenu.1 | 5 ++++- M iomenu.c | 34 +++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) --- DIR diff --git a/iomenu.1 b/iomenu.1 @@ -40,11 +40,14 @@ An active selection is highlighted, and can be controlled with keybindings. As printable keys are entered, the lines are filtered to match each word from the input. . -.Bl -tag -width XXXXXXXXXXXXXXX +.Bl -tag -width 6n . .It Ic Up Ns , Ic Down Ns , Ic Ctrl + p Ns , Ic Ctrl + n Move selection to the previous/next item. . +.It Ic Alt + p Ns , Ic Alt + n +Move selection to the previous/next header. +. .It Ic PageUp Ns , Ic PageDown Ns , Ic Alt + v Ns , Ic Ctrl + v Move one page up or down. . DIR diff --git a/iomenu.c b/iomenu.c @@ -124,15 +124,15 @@ read_stdin(void) } static void -move(int direction) +move(int sign) { extern char **matchv; extern int matchc; int i; - for (i = cur + direction; 0 <= i && i < matchc; i += direction) { - if (!hsflag || matchv[i][0] != '#') { + for (i = cur + sign; 0 <= i && i < matchc; i += sign) { + if (hsflag == 0 || matchv[i][0] != '#') { cur = i; break; } @@ -180,7 +180,7 @@ static void move_page(signed int sign) { extern struct winsize ws; - extern int matchc; + extern int matchc, cur; int i, rows; @@ -193,6 +193,26 @@ move_page(signed int sign) } static void +move_header(signed int sign) +{ + extern char **matchv; + extern int matchc, cur; + + move(sign); + if (hsflag == 0) + return; + for (cur += sign; 0 <= cur; cur += sign) { + if (cur >= matchc) { + cur--; + break; + } + if (matchv[cur][0] == '#') + break; + } + move(+1); +} + +static void remove_word() { extern char input[LINE_MAX]; @@ -277,10 +297,16 @@ top: case CTL('P'): move(-1); break; + case ALT('p'): + move_header(-1); + break; case CSI('B'): /* down */ case CTL('N'): move(+1); break; + case ALT('n'): + move_header(+1); + break; case CSI('5'): /* page up */ if (getkey() != '~') break;