2020-02-01 20:46:18 +00:00
|
|
|
% notcurses_menu(3)
|
|
|
|
% nick black <nickblack@linux.com>
|
2021-02-10 00:34:03 +00:00
|
|
|
% v2.2.1
|
2020-02-01 20:46:18 +00:00
|
|
|
|
|
|
|
# NAME
|
|
|
|
|
|
|
|
notcurses_menu - operations on menus
|
|
|
|
|
|
|
|
# SYNOPSIS
|
|
|
|
|
2020-04-19 22:46:32 +00:00
|
|
|
**#include <notcurses/notcurses.h>**
|
2020-02-01 20:46:18 +00:00
|
|
|
|
2020-02-01 21:09:44 +00:00
|
|
|
```c
|
2020-02-01 21:06:46 +00:00
|
|
|
struct ncmenu;
|
2020-02-10 20:41:25 +00:00
|
|
|
struct ncplane;
|
|
|
|
struct ncinput;
|
|
|
|
struct notcurses;
|
2020-02-01 21:06:46 +00:00
|
|
|
|
2020-02-02 11:46:45 +00:00
|
|
|
struct ncmenu_section {
|
|
|
|
char* name; // utf-8 c string
|
|
|
|
struct ncmenu_item {
|
|
|
|
char* desc; // utf-8 menu item, NULL for horizontal separator
|
|
|
|
ncinput shortcut; // shortcut, all should be distinct
|
|
|
|
}* items;
|
|
|
|
int itemcount;
|
|
|
|
};
|
|
|
|
|
2020-05-29 18:53:53 +00:00
|
|
|
#define NCMENU_OPTION_BOTTOM 0x0001 // bottom row (as opposed to top row)
|
2020-07-24 02:07:06 +00:00
|
|
|
#define NCMENU_OPTION_HIDING 0x0002 // hide the menu when not unrolled
|
2020-05-09 12:41:03 +00:00
|
|
|
|
2020-02-02 11:46:45 +00:00
|
|
|
typedef struct ncmenu_options {
|
2020-02-02 11:57:10 +00:00
|
|
|
struct ncmenu_section* sections; // 'sectioncount' menu_sections
|
2020-02-02 11:46:45 +00:00
|
|
|
int sectioncount; // must be positive
|
2020-02-01 21:06:46 +00:00
|
|
|
uint64_t headerchannels; // styling for header
|
|
|
|
uint64_t sectionchannels; // styling for sections
|
2020-11-06 23:15:57 +00:00
|
|
|
uint64_t flags; // bitfield on NCMENU_OPTION_*
|
2020-02-02 11:46:45 +00:00
|
|
|
} ncmenu_options;
|
2020-02-01 21:06:46 +00:00
|
|
|
```
|
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**struct ncmenu* ncmenu_create(struct notcurses* ***nc***, const menu_options* ***opts***);**
|
2020-02-01 21:06:46 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int ncmenu_unroll(struct ncmenu* ***n***, int ***sectionidx***);**
|
2020-02-01 21:06:46 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int ncmenu_rollup(struct ncmenu* ***n***);**
|
2020-02-01 21:06:46 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int ncmenu_nextsection(struct ncmenu* ***n***);**
|
2020-02-10 20:41:25 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int ncmenu_prevsection(struct ncmenu* ***n***);**
|
2020-02-10 20:41:25 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int ncmenu_nextitem(struct ncmenu* ***n***);**
|
2020-02-10 20:41:25 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int ncmenu_previtem(struct ncmenu* ***n***);**
|
2020-02-10 20:41:25 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int ncmenu_item_set_status(struct ncmenu* ***n***, const char* ***section***, const char* ***item***, bool ***enabled***);**
|
2020-10-15 07:03:43 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**const char* ncmenu_selected(const struct ncmenu* ***n***, struct ncinput* ***ni***);**
|
2020-02-04 06:05:51 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**const char* ncmenu_mouse_selected(const struct ncmenu* ***n***, const struct ncinput* ***click***, struct ncinput* ***ni***);**
|
2020-07-24 02:07:06 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**struct ncplane* ncmenu_plane(struct ncmenu* ***n***);**
|
2020-02-01 20:46:18 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**bool ncmenu_offer_input(struct ncmenu* ***n***, const struct ncinput* ***nc***);**
|
2020-02-10 20:41:25 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int ncmenu_destroy(struct ncmenu* ***n***);**
|
2020-02-01 20:46:18 +00:00
|
|
|
|
2020-02-10 20:18:28 +00:00
|
|
|
# DESCRIPTION
|
2020-02-02 11:57:10 +00:00
|
|
|
|
2020-02-10 20:18:28 +00:00
|
|
|
A notcurses instance supports menu bars on the top or bottom row of the true
|
|
|
|
screen. A menu is composed of sections, which are in turn composed of items.
|
|
|
|
Either no sections are visible, and the menu is *rolled up*, or exactly one
|
|
|
|
section is *unrolled*. **ncmenu_rollup** places an ncmenu in the rolled up
|
|
|
|
state. **ncmenu_unroll** rolls up any unrolled section, and unrolls the
|
|
|
|
specified one. **ncmenu_destroy** removes a menu bar, and frees all associated
|
|
|
|
resources.
|
2020-02-01 20:46:18 +00:00
|
|
|
|
2020-02-10 20:41:25 +00:00
|
|
|
**ncmenu_selected** return the selected item description, or NULL if no section
|
2020-07-24 02:07:06 +00:00
|
|
|
is unrolled, or no valid item is selected. **ncmenu_mouse_selected** returns
|
|
|
|
the item selected by a mouse click (described in **click**), which must be on
|
|
|
|
the actively unrolled section. In either case, if there is a shortcut for the
|
|
|
|
item and **ni** is not **NULL**, **ni** will be filled in with the shortcut.
|
2020-02-10 20:41:25 +00:00
|
|
|
|
|
|
|
The menu can be driven either entirely by the application, via direct calls to
|
|
|
|
**ncmenu_previtem**, **ncmenu_prevsection**, and the like, or **struct ncinput**
|
|
|
|
objects can be handed to **ncmenu_offer_input**. In the latter case, the menu
|
2020-07-24 02:07:06 +00:00
|
|
|
will largely manage itself. The application must handle item selection (usually
|
|
|
|
via the Enter key and/or mouse click) itself, since the menu cannot arbitrarily
|
|
|
|
call into the application. **ncmenu_offer_input** will handle clicks to unroll
|
|
|
|
menu sections, clicks to dismiss the menu, Escape to dismiss the menu, left
|
|
|
|
and right to change menu sections, and up and down to change menu items (these
|
|
|
|
latter are only consumed if there is an actively unrolled section).
|
2020-02-04 06:05:51 +00:00
|
|
|
|
2020-02-01 20:46:18 +00:00
|
|
|
# RETURN VALUES
|
|
|
|
|
2020-02-10 20:41:25 +00:00
|
|
|
**ncmenu_create** returns **NULL** on error, or a pointer to a valid new ncmenu.
|
2020-02-02 11:57:10 +00:00
|
|
|
Other functions return non-zero on error, or zero on success. Almost all errors
|
|
|
|
are due to invalid parameters.
|
2020-02-01 20:46:18 +00:00
|
|
|
|
2020-02-10 20:41:25 +00:00
|
|
|
**ncmenu_offer_input** returns **true** if the menu "consumed" the input, i.e.
|
|
|
|
found it relevant and took an action. Otherwise, **false** is returned, and the
|
|
|
|
**struct ncinput** should be considered irrelevant to the menu.
|
|
|
|
|
2020-02-01 20:46:18 +00:00
|
|
|
# SEE ALSO
|
|
|
|
|
2020-02-10 20:41:25 +00:00
|
|
|
**notcurses(3)**,
|
|
|
|
**notcurses_input(3)**,
|
2020-05-09 00:56:39 +00:00
|
|
|
**notcurses_plane(3)**
|