menu_hook(3X)

okay bestie, pull up a chair because this is the menu_hook(3X) page from the ncurses library-calls girlies, and it's literally about letting your app sneak little callback functions into the menu machinery πŸŽ€


🌸 NAME 🌸

menu_hook β€” set hooks for automatic invocation by applications πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <menu.h>

int set_item_init(MENU *menu, Menu_Hook func);
Menu_Hook item_init(const MENU *menu);

int set_item_term(MENU *menu, Menu_Hook func);
Menu_Hook item_term(const MENU *menu);

int set_menu_init(MENU *menu, Menu_Hook func);
Menu_Hook menu_init(const MENU *menu);

int set_menu_term(MENU *menu, Menu_Hook func);
Menu_Hook menu_term(const MENU *menu);

πŸ’– DESCRIPTION πŸ’–

So these functions are the whole vibe of letting you set hook functions that get called at various points while menu_driver is doing its automatic processing of input event codes. it's giving "let me inject my own little moment into your pipeline" and honestly? iconic.

  • set_item_init β€” sets a hook that gets called at menu-post time AND every single time the selected item changes (after the change, so you're seeing the new reality, not the old one ✨). and item_init hands you back the current item init hook, if there is one β€” or NULL if there's no such hook, no cap.
  • set_item_term β€” sets a hook that gets called at menu-unpost time AND each time the selected item changes (before the change, so catch it while it's still the old item πŸ‘€). and item_term returns the current item term hook, if any β€” NULL if there isn't one.
  • set_menu_init β€” sets a hook called at menu-post time and just after the top row on the menu changes, once it's posted. menu_init returns the current menu init hook, if any β€” NULL if there is none, fr fr.
  • set_menu_term β€” sets a hook called at menu-unpost time and just before the top row on the menu changes, once it's posted. menu_term returns the current menu term hook, if any β€” NULL if there's no such hook.
not me realizing "post" and "unpost" are the main character events here β€” every one of these hooks is anchored to posting, unposting, item changes, or top-row changes. that's the whole map, bestie πŸ—ΊοΈπŸ’œ

🌈 RETURN VALUE 🌈

the routines that return pointers return NULL on error. (yes, that's the item_init, item_term, menu_init and menu_term girlies 🫢)

the other routines return one of these:

  • E_OK β€” the routine succeeded. slay. βœ…
  • E_SYSTEM_ERROR β€” a system error occurred (go peek at errno(3), it knows what happened 😭).

🧚 PORTABILITY 🧚

these routines emulate the System V menu library. they were not supported on Version 7 or BSD versions. so if you're time-traveling to those, this is a no πŸ’€


πŸ‘‘ AUTHORS πŸ‘‘

Juergen Pfeifer. manual pages and adaptation for new curses by Eric S. Raymond. absolute legends, we stan 🫢


⭐ SEE ALSO ⭐

  • curses(3X)
  • menu(3X)

and that's the page, bestie!! this whole thing ships with ncurses 6.6, dated 2024-12-28, and it's filed under menu_hook(3X) in the Library calls section πŸ’–βœ¨ go forth and hook responsibly πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from