Add selection wrapping (-w).

This commit is contained in:
Jari Vetoniemi 2014-04-14 19:25:16 +03:00
parent 4f72d188ad
commit 617c4ab827
4 changed files with 55 additions and 3 deletions

View File

@ -91,7 +91,7 @@ static void parseArgs(int *argc, char **argv[])
* or parse them before running getopt.. */
for (;;) {
int opt = getopt_long(*argc, *argv, "hviw:l:I:p:Ibf:m", opts, NULL);
int opt = getopt_long(*argc, *argv, "hviwl:I:p:I:bfm:", opts, NULL);
if (opt < 0)
break;
@ -190,6 +190,7 @@ int main(int argc, char **argv)
bmMenuSetTitle(menu, client.title);
bmMenuSetFilterMode(menu, client.filterMode);
bmMenuSetWrap(menu, client.wrap);
readItemsToMenuFromStdin(menu);

View File

@ -202,6 +202,22 @@ void bmMenuSetFilterMode(bmMenu *menu, bmFilterMode mode);
*/
bmFilterMode bmMenuGetFilterMode(const bmMenu *menu);
/**
* Set selection wrapping on/off.
*
* @param menu bmMenu instance where to toggle selection wrapping.
* @param int 1 == on, 0 == off.
*/
void bmMenuSetWrap(bmMenu *menu, int wrap);
/**
* Get selection wrapping state.
*
* @param menu bmMenu instance where to get selection wrapping state.
* @return int for wrap state.
*/
int bmMenuGetWrap(const bmMenu *menu);
/**
* Set title to bmMenu instance.
*

View File

@ -141,6 +141,11 @@ struct _bmMenu {
* Drawing mode used in menu instance.
*/
bmDrawMode drawMode;
/**
* Should selection be wrapped?
*/
char wrap;
};
/* draw/curses.c */

View File

@ -172,6 +172,30 @@ bmFilterMode bmMenuGetFilterMode(const bmMenu *menu)
return menu->filterMode;
}
/**
* Set selection wrapping on/off.
*
* @param menu bmMenu instance where to toggle selection wrapping.
* @param int 1 == on, 0 == off.
*/
void bmMenuSetWrap(bmMenu *menu, int wrap)
{
assert(menu);
menu->wrap = (wrap ? 1 : 0);
}
/**
* Get selection wrapping state.
*
* @param menu bmMenu instance where to get selection wrapping state.
* @return int for wrap state.
*/
int bmMenuGetWrap(const bmMenu *menu)
{
assert(menu);
return menu->wrap;
}
/**
* Set title to bmMenu instance.
*
@ -572,13 +596,19 @@ bmRunResult bmMenuRunWithKey(bmMenu *menu, bmKey key, unsigned int unicode)
break;
case BM_KEY_UP:
if (menu->index > 0)
if (menu->index > 0) {
menu->index--;
} else if (menu->wrap) {
menu->index = itemsCount - 1;
}
break;
case BM_KEY_DOWN:
if (menu->index < itemsCount - 1)
if (menu->index < itemsCount - 1) {
menu->index++;
} else if (menu->wrap) {
menu->index = 0;
}
break;
case BM_KEY_PAGE_UP: