Skip to content

Commit

Permalink
Add toggle sorting key binding
Browse files Browse the repository at this point in the history
  • Loading branch information
mptre committed Nov 6, 2017
1 parent f833b3a commit d36423b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TESTS=tests/key-alt-enter.t \
tests/key-ctrl-e.t \
tests/key-ctrl-k.t \
tests/key-ctrl-l.t \
tests/key-ctrl-o.t \
tests/key-ctrl-u.t \
tests/key-ctrl-w.t \
tests/key-del.t \
Expand Down
5 changes: 5 additions & 0 deletions pick.1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Supply an initial search query.
.It Fl S
Disable sorting.
Only filter the choices instead of additionally sorting by score.
This option can be toggled from within the interface,
see
.Sx COMMANDS .
.It Fl v
Output the version and exit.
.It Fl x
Expand All @@ -64,6 +67,8 @@ see
.Xr termios 4 .
.It Ic Ctrl-L
Redraw interface with respect to the current size of the terminal.
.It Ic Ctrl-O
Toggle sorting.
.It Ic Up Ns / Ns Ic Down | Ic Ctrl-P Ns / Ns Ic Ctrl-N
Select between choices matching the current search query.
.It Ic Page-Down Ns / Ns Ic Page-Up | Ic Ctrl-V Ns / Ns Ic Alt-V | Ic Alt-Space
Expand Down
7 changes: 7 additions & 0 deletions pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum key {
CTRL_E,
CTRL_K,
CTRL_L,
CTRL_O,
CTRL_U,
CTRL_W,
CTRL_Z,
Expand Down Expand Up @@ -445,6 +446,10 @@ selected_choice(void)
case CTRL_L:
tty_size();
break;
case CTRL_O:
sort = !sort;
dofilter = 1;
break;
case CTRL_W:
if (cursor_position == 0)
break;
Expand Down Expand Up @@ -708,6 +713,7 @@ tty_init(int doinit)
new_attributes.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
new_attributes.c_cc[VMIN] = 1;
new_attributes.c_cc[VTIME] = 0;
new_attributes.c_cc[VDISCARD] = _POSIX_VDISABLE;
tcsetattr(fileno(tty_in), TCSANOW, &new_attributes);

if (doinit && (tty_out = fopen("/dev/tty", "w")) == NULL)
Expand Down Expand Up @@ -928,6 +934,7 @@ get_key(const char **key)
KEY(CTRL_E, "\005"),
KEY(CTRL_K, "\013"),
KEY(CTRL_L, "\014"),
KEY(CTRL_O, "\017"),
KEY(CTRL_U, "\025"),
KEY(CTRL_W, "\027"),
KEY(CTRL_W, "\033\177"),
Expand Down
16 changes: 16 additions & 0 deletions tests/key-ctrl-o.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
description: Ctrl-O toggles sorting
keys: foo \017 \n # CTRL_O ENTER
stdin:
foo bar
foo
stdout:
foo bar

description: it works in conjuction with the -S option
args: -S
keys: foo \017 \n # CTRL_O ENTER
stdin:
foo bar
foo
stdout:
foo

0 comments on commit d36423b

Please sign in to comment.