Skip to content

Commit

Permalink
Add K option to disable toggling of keyboard transmit mode
Browse files Browse the repository at this point in the history
Useful when running pick from within another interactive program (like
Vim) which does not re-enable keyboard transmit mode after executing an
external program.

Fixes #246.
  • Loading branch information
mptre committed Sep 19, 2017
1 parent 9886750 commit 6fca1c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion pick.1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.Nd fuzzy select anything
.Sh SYNOPSIS
.Nm
.Op Fl hvS
.Op Fl hvKS
.Op Fl d Op Fl o
.Op Fl x | Fl X
.Op Fl q Ar query
Expand All @@ -32,6 +32,12 @@ Both parts will be displayed but only the first part will be used when
searching.
.It Fl h
Output a help message and exit.
.It Fl K
Disable toggling of keyboard transmit mode.
Useful when running
.Nm
from within another interactive program which already has set the correct
transmit mode.
.It Fl o
Output description of selected choice on exit.
.It Fl q Ar query
Expand Down
16 changes: 11 additions & 5 deletions pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static unsigned int choices_lines, tty_columns, tty_lines;
static int descriptions;
static int sort = 1;
static int use_alternate_screen = 1;
static int use_keypad = 1;

int
main(int argc, char *argv[])
Expand All @@ -126,11 +127,14 @@ main(int argc, char *argv[])
err(1, "pledge");
#endif

while ((c = getopt(argc, argv, "dhoq:SvxX")) != -1)
while ((c = getopt(argc, argv, "dhoq:KSvxX")) != -1)
switch (c) {
case 'd':
descriptions = 1;
break;
case 'K':
use_keypad = 0;
break;
case 'o':
/*
* Only output description if descriptions are read and
Expand Down Expand Up @@ -198,9 +202,10 @@ main(int argc, char *argv[])
__dead void
usage(void)
{
fprintf(stderr, "usage: pick [-hvS] [-d [-o]] [-x | -X] [-q query]\n"
fprintf(stderr, "usage: pick [-hvKS] [-d [-o]] [-x | -X] [-q query]\n"
" -h output this help message and exit\n"
" -v output the version and exit\n"
" -K disable toggling of keyboard transmit mode\n"
" -S disable sorting\n"
" -d read and display descriptions\n"
" -o output description of selected on exit\n"
Expand Down Expand Up @@ -678,11 +683,11 @@ tty_init(int doinit)

tty_size();

if (use_keypad)
tty_putp(keypad_xmit, 0);
if (use_alternate_screen)
tty_putp(enter_ca_mode, 0);

tty_putp(keypad_xmit, 0);

toggle_sigwinch(0);
}

Expand Down Expand Up @@ -721,10 +726,11 @@ tty_restore(int doclose)
if (doclose)
fclose(tty_in);

tty_putp(keypad_local, 0);
tty_putp(carriage_return, 1); /* move cursor to first column */
tty_putp(clr_eos, 1);

if (use_keypad)
tty_putp(keypad_local, 0);
if (use_alternate_screen)
tty_putp(exit_ca_mode, 0);

Expand Down

0 comments on commit 6fca1c4

Please sign in to comment.