1
0
Fork 0
mirror of https://github.com/Cloudef/bemenu synced 2024-05-18 21:46:15 +02:00

Add option to exit bemenu using esc in vim binds normal mode

This commit is contained in:
ItsProfessional 2023-06-15 21:58:26 +05:30 committed by Jari Vetoniemi
parent f92da7b438
commit c9b891e89b
7 changed files with 50 additions and 1 deletions

View File

@ -185,6 +185,7 @@ usage(FILE *out, const char *name)
" --fixed-height prevent the display from changing height on filter.\n"
" --scrollbar display scrollbar. (none (default), always, autohide)\n"
" --counter display a matched/total items counter. (none (default), always)\n"
" -e, --vim-esc-exits exit bemenu when pressing escape in normal mode for vim bindings\n"
" --accept-single immediately return if there is only one item.\n"
" --ifne only display menu if there are items.\n"
" --fork always fork. (bemenu-run)\n"
@ -275,6 +276,7 @@ do_getopt(struct client *client, int *argc, char **argv[])
{ "fixed-height", no_argument, 0, 0x090 },
{ "scrollbar", required_argument, 0, 0x100 },
{ "counter", required_argument, 0, 0x10a },
{ "vim-esc-exits",no_argument, 0, 'e' },
{ "accept-single",no_argument, 0, 0x11a },
{ "ifne", no_argument, 0, 0x117 },
{ "fork", no_argument, 0, 0x118 },
@ -372,6 +374,9 @@ do_getopt(struct client *client, int *argc, char **argv[])
case 0x10a:
client->counter = (!strcmp(optarg, "always"));
break;
case 'e':
client->vim_esc_exits = true;
break;
case 0x11a:
client->accept_single = true;
break;
@ -555,6 +560,7 @@ menu_with_options(struct client *client)
bm_menu_set_fixed_height(menu, client->fixed_height);
bm_menu_set_scrollbar(menu, client->scrollbar);
bm_menu_set_counter(menu, client->counter);
bm_menu_set_vim_esc_exits(menu, client->vim_esc_exits);
bm_menu_set_panel_overlap(menu, !client->no_overlap);
bm_menu_set_spacing(menu, !client->no_spacing);
bm_menu_set_password(menu, client->password);

View File

@ -29,6 +29,7 @@ struct client {
bool wrap;
bool fixed_height;
bool counter;
bool vim_esc_exits;
bool accept_single;
bool ifne;
bool no_overlap;

View File

@ -733,6 +733,24 @@ BM_PUBLIC void bm_menu_set_counter(struct bm_menu *menu, bool mode);
BM_PUBLIC bool bm_menu_get_counter(struct bm_menu *menu);
/**
* Set vim escape exit mode of the bar.
*
* @param menu bm_menu to set the vim escape exit mode for.
* @param mode to be set.
*/
BM_PUBLIC void bm_menu_set_vim_esc_exits(struct bm_menu *menu, bool mode);
/**
* Get the vim escape exit mode of the bar.
*
* @param menu bm_menu to get the vim escape exit mode from.
* @param mode current vim escape exit mode
*/
BM_PUBLIC bool bm_menu_get_vim_esc_exits(struct bm_menu *menu);
/**
* Set the vertical alignment of the bar.
*

View File

@ -362,6 +362,11 @@ struct bm_menu {
*/
enum bm_scrollbar_mode scrollbar;
/**
* Current vim escape exit mode.
*/
bool vim_esc_exits;
/**
* Current counter display mode.
*/

View File

@ -458,6 +458,18 @@ bm_menu_get_scrollbar(struct bm_menu *menu)
return menu->scrollbar;
}
void
bm_menu_set_vim_esc_exits(struct bm_menu *menu, bool mode)
{
menu->vim_esc_exits = mode;
}
bool
bm_menu_get_vim_esc_exits(struct bm_menu *menu)
{
return menu->vim_esc_exits;
}
void
bm_menu_set_counter(struct bm_menu *menu, bool mode)
{

View File

@ -206,7 +206,11 @@ enum bm_vim_code bm_vim_key_press(struct bm_menu *menu, enum bm_key key, uint32_
if(key == BM_KEY_ESCAPE && unicode == 99) return BM_VIM_EXIT;
if(menu->vim_mode == 'n'){
if(key == BM_KEY_ESCAPE) return BM_VIM_CONSUME;
if(key == BM_KEY_ESCAPE){
if(menu->vim_esc_exits) return BM_VIM_EXIT;
return BM_VIM_CONSUME;
}
if(unicode == 0 || unicode > 128) return BM_VIM_IGNORE;
if(menu->vim_last_key == 0) return vim_on_first_key(menu, unicode, item_count, items_displayed);

View File

@ -102,6 +102,9 @@ list of executables under PATH and the selected items are executed.
: Only display a scrollbar when the number of items exceeds the number
of lines.
*-e, --vim-esc-exits*
Exit bemenu when pressing escape in normal mode for vim bindings.
## Backend options
These options are only available on backends specified in the parentheses: