Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return status of filtering choices #268

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct choice {
static int choicecmp(const void *, const void *);
static void delete_between(char *, size_t, size_t, size_t);
static char *eager_strpbrk(const char *, const char *);
static void filter_choices(size_t);
static int filter_choices(size_t);
static char *get_choices(void);
static enum key get_key(const char **);
static void handle_sigwinch(int);
Expand Down Expand Up @@ -325,8 +325,10 @@ selected_choice(void)
choices_count = choices.length;
query_grew = 0;
if (dofilter) {
filter_choices(choices_count);
dofilter = selection = yscroll = 0;
if (filter_choices(choices_count))
dofilter = selection = yscroll = 0;
else
dochoices = 0;
}

tty_putp(cursor_invisible, 0);
Expand Down Expand Up @@ -451,11 +453,13 @@ selected_choice(void)
break;
case CTRL_A:
cursor_position = 0;
dochoices = 0;
if (!dofilter)
dochoices = 0;
break;
case CTRL_E:
cursor_position = query_length;
dochoices = 0;
if (!dofilter)
dochoices = 0;
break;
case LINE_DOWN:
if (selection < choices_count - 1) {
Expand All @@ -475,13 +479,15 @@ selected_choice(void)
while (cursor_position > 0
&& isu8cont(query[--cursor_position]))
continue;
dochoices = 0;
if (!dofilter)
dochoices = 0;
break;
case RIGHT:
while (cursor_position < query_length
&& isu8cont(query[++cursor_position]))
continue;
dochoices = 0;
if (!dofilter)
dochoices = 0;
break;
case PAGE_DOWN:
if (selection + choices_lines < choices_count)
Expand Down Expand Up @@ -534,7 +540,7 @@ selected_choice(void)
* available.
* The first nchoices number of choices will be filtered.
*/
void
int
filter_choices(size_t nchoices)
{
struct choice *c;
Expand Down Expand Up @@ -567,11 +573,12 @@ filter_choices(size_t nchoices)
if ((nready = poll(&pfd, 1, 0)) == -1)
err(1, "poll");
if (nready == 1 && pfd.revents & (POLLIN | POLLHUP))
break;
return 0;
}
}

qsort(choices.v, nchoices, sizeof(struct choice), choicecmp);
return 1;
}

int
Expand Down