Add --filter option.

This commit is contained in:
Julian Mehne 2020-11-12 18:20:21 +01:00 committed by Jari Vetoniemi
parent 4cbc0343c3
commit 7523af7d18
2 changed files with 7 additions and 0 deletions

View File

@ -168,6 +168,7 @@ usage(FILE *out, const char *name)
" -h, --help display this help and exit.\n"
" -v, --version display version.\n"
" -i, --ignorecase match items case insensitively.\n"
" -F, --filter filter entries for a given string.\n"
" -w, --wrap wraps cursor selection.\n"
" -l, --list list items vertically with the given number of lines.\n"
" -p, --prompt defines the prompt text to be displayed.\n"
@ -221,6 +222,7 @@ do_getopt(struct client *client, int *argc, char **argv[])
{ "version", no_argument, 0, 'v' },
{ "ignorecase", no_argument, 0, 'i' },
{ "filter", required_argument, 0, 'F' },
{ "wrap", no_argument, 0, 'w' },
{ "list", required_argument, 0, 'l' },
{ "prompt", required_argument, 0, 'p' },
@ -274,6 +276,9 @@ do_getopt(struct client *client, int *argc, char **argv[])
case 'i':
client->filter_mode = BM_FILTER_MODE_DMENU_CASE_INSENSITIVE;
break;
case 'F':
client->initial_filter = optarg;
break;
case 'w':
client->wrap = true;
break;
@ -424,6 +429,7 @@ run_menu(const struct client *client, struct bm_menu *menu, void (*item_cb)(cons
{
bm_menu_set_highlighted_index(menu, client->selected);
bm_menu_grab_keyboard(menu, true);
bm_menu_set_filter(menu, client->initial_filter);
if (client->ifne && !bm_menu_get_items(menu, NULL))
return BM_RUN_RESULT_CANCEL;

View File

@ -11,6 +11,7 @@ struct client {
const char *title;
const char *prefix;
const char *font;
const char *initial_filter;
uint32_t line_height;
uint32_t lines;
uint32_t selected;