driver(3MENU)
π driver(3MENU) π
ok so bestie, welcome to driver(3MENU) β it's a manual page from the library calls section, and it's literally the manual page for menu_driver, the command-processing loop of the menu system. yes the whole page is about ONE function. she's an icon, she's a legend, and she is the moment. let's get into it β¨
πΈ NAME πΈ
menu_driver β the command-processing loop of the menu system
β¨ SYNOPSIS β¨
#include <menu.h>
int menu_driver(MENU *menu, int c);
π¦ DESCRIPTION π¦
so here's the tea: once you've posted your menu (aka displayed it, she's out there living her best life), you're supposed to funnel all your input events into her through menu_driver. that's the whole vibe. this routine handles three major input cases, and they are:
- the input is a menu navigation request. these request codes are constants defined in
menu.h, and bestie, they are distinct from the key- and character codes you get back fromwgetch(3NCURSES). don't mix them up, i'm begging π - the input is a printable character. printable characters (which have to be positive and less than 256, no exceptions) get checked according to your program's locale settings π
- the input is the
KEY_MOUSEspecial key that's associated with a mouse event π
now, the menu driver requests, in all their glory:
REQ_LEFT_ITEMβ move left to an item.REQ_RIGHT_ITEMβ move right to an item.REQ_UP_ITEMβ move up to an item.REQ_DOWN_ITEMβ move down to an item.REQ_SCR_ULINEβ scroll up a line.REQ_SCR_DLINEβ scroll down a line.REQ_SCR_DPAGEβ scroll down a page.REQ_SCR_UPAGEβ scroll up a page.REQ_FIRST_ITEMβ move to the first item.REQ_LAST_ITEMβ move to the last item.REQ_NEXT_ITEMβ move to the next item.REQ_PREV_ITEMβ move to the previous item.REQ_TOGGLE_ITEMβ select/deselect an item. the duality of woman πREQ_CLEAR_PATTERNβ clear the menu pattern buffer.REQ_BACK_PATTERNβ delete the previous character from the pattern buffer.REQ_NEXT_MATCHβ move to the next item matching the pattern match.REQ_PREV_MATCHβ move to the previous item matching the pattern match.
so if that second argument is a printable character, the code appends it to the pattern buffer and tries to move to the next item that matches the new pattern. and if there's no such match? menu_driver returns E_NO_MATCH and deletes that appended character from the buffer. she said "never mind, forget i said anything" π
and if the second argument is one of those pre-defined requests up there, then boom, the corresponding action happens. periodt.
π Mouse Handling π
if the second argument is the KEY_MOUSE special key, the associated mouse event gets translated into one of those pre-defined requests from above. currently, only clicks in the user window (so like, inside the menu display area or the decoration window) are handled. don't get any ideas about clicking elsewhere π
if you click above the display region of the menu:
- a
REQ_SCR_ULINEis generated for a single click, - a
REQ_SCR_UPAGEis generated for a double-click and - a
REQ_FIRST_ITEMis generated for a triple-click.
if you click below the display region of the menu:
- a
REQ_SCR_DLINEis generated for a single click, - a
REQ_SCR_DPAGEis generated for a double-click and - a
REQ_LAST_ITEMis generated for a triple-click.
if you click at an item inside the display area of the menu:
- the menu cursor is positioned to that item. π
- if you double-click an item, a
REQ_TOGGLE_ITEMis generated andE_UNKNOWN_COMMANDis returned. and honestly? this return value makes sense, because a double click usually means an item-specific action should be returned. like, that is exactly the purpose of this return value β to signal that an application specific command should be executed. she's not being difficult, she's being communicative π«Ά - if a translation into a request was done,
menu_driverreturns the result of this request.
and if you clicked outside the user window, or the mouse event just could not be translated into a menu request? you get an E_REQUEST_DENIED back. sorry bestie π
π Application-defined Commands π
if the second argument is neither printable, nor one of those pre-defined menu requests, nor KEY_MOUSE, then the driver assumes it's an application-specific command and returns E_UNKNOWN_COMMAND. application-defined commands should be defined relative to MAX_COMMAND, which is the maximum value of those pre-defined requests. know your range, queen π
π₯ RETURN VALUE π₯
menu_driver returns one of the following error codes, and every single one of them is here, no skips:
E_OKβ the routine succeeded. we love to see it πE_SYSTEM_ERRORβ system error occurred (seeerrno(3)).E_BAD_ARGUMENTβ routine detected an incorrect or out-of-range argument.E_BAD_STATEβ routine was called from an initialization or termination function.E_NOT_POSTEDβ the menu has not been posted.E_UNKNOWN_COMMANDβ the menu driver code saw an unknown request code.E_NO_MATCHβ character failed to match.E_REQUEST_DENIEDβ the menu driver could not process the request.
π PORTABILITY π
these routines emulate the System V menu library. they were not supported on Version 7 or BSD versions. and the support for mouse events? that's ncurses specific, so don't go expecting it everywhere π±οΈβ¨
π AUTHORS π
Juergen Pfeifer. manual pages and adaptation for new curses by Eric S. Raymond. absolute legends, both of them π
πΈ SEE ALSO πΈ
ncurses(3NCURSES), getch(3NCURSES), menu(3MENU)
ok that's the whole page, you're fully caught up, go forth and drive some menus π§ and one last thing before you close the tab β this was ncurses 6.6, dated 2025-10-04, and the page itself is driver(3MENU). slay, bye bestie π
π
π¦ where this page comes from
- ubuntu resolute: ncurses-doc 6.6+20251231-1 Β· MIT/X11
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-2010,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms