From 6fca1c4d25566463e3711d216744515d1ad23696 Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Mon, 18 Sep 2017 16:32:41 +0200 Subject: [PATCH] Add K option to disable toggling of keyboard transmit mode 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. --- pick.1 | 8 +++++++- pick.c | 16 +++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pick.1 b/pick.1 index 3691c039..8fde9ce7 100644 --- a/pick.1 +++ b/pick.1 @@ -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 @@ -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 diff --git a/pick.c b/pick.c index 91500427..789b1bf0 100644 --- a/pick.c +++ b/pick.c @@ -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[]) @@ -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 @@ -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" @@ -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); } @@ -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);