Widgets::Menu(3pm)
π
Widgets::Menu(3pm) β aka Curses::Widgets::Menu π
okay bestie, sit down, we're doing terminal menus today β¨ this page lives in the User Contributed Perl Documentation section of your man pages, and it's literally all about Curses::Widgets::Menu, the Menu Widget situation. no cap.
β¨ NAME β¨
Curses::Widgets::Menu β Menu Widgets π
it's giving "menus, but make it object-oriented." periodt.
πΈ MODULE VERSION πΈ
$Id: Menu.pm,v 1.103 2002/11/14 01:26:34 corliss Exp corliss $
yes she's an elder, she's still iconic π
π¦ SYNOPSIS π¦
here's the whole vibe, copy-paste ready:
use Curses::Widgets::Menu;
$menu = Curses::Widgets::Menu->new({
COLUMNS => 10,
INPUTFUNC => \&scankey,
FOREGROUND => undef,
BACKGROUND => 'black',
FOCUSSWITCH => "\t",
X => 1,
Y => 1,
MENUS => {
MENUORDER => [qw(File)],
File => {
ITEMORDER => [qw(Save Quit)],
Save => \&Save,
Quit => \&Quit,
},
CURSORPOS => 'File',
BORDER => 1,
});
$menu->draw($mwh, 1);
$menu->execute;
See the Curses::Widgets pod for other methods.
likeβ¦ look at her. she's doing so much. π«Ά
psst β for the other methods, go read the Curses::Widgets pod. that's where the rest of the lore lives.
π REQUIREMENTS π
you're gonna need all three of these or it's not happening, bestie:
CursesCurses::WidgetsCurses::Widgets::ListBox
π DESCRIPTION π
Curses::Widgets::Menu hands you simplified OO access to menus, which β ngl β is exactly what we deserve. every item in a menu can be tied to a subroutine reference, and that sub gets called the moment the item is selected. main character behavior fr π
π METHODS π
πΈ new (inherited from Curses::Widgets)
$menu = Curses::Widgets::Menu->new({
INPUTFUNC => \&scankey,
FOREGROUND => undef,
BACKGROUND => 'black',
FOCUSSWITCH => "\t",
MENUS => {
MENUORDER => [qw(File)],
File => {
ITEMORDER => [qw(Save Quit)],
Save => \&Save,
Quit => \&Quit,
},
CURSORPOS => 'File',
BORDER => 1,
});
new instantiates a brand new Menu object, slay β¨
and here's the tea: the only mandatory key/value pairs in the configuration hash are X and Y. everything else is optional and comes with defaults, which are:
INPUTFUNCβ default\&scankeyβ function to use to scan for keystrokesFOREGROUNDβ defaultundefβ default foreground colourBACKGROUNDβ default'black'β default background colourFOCUSSWITCHβ default"\t"β characters which signify end of inputMENUSβ default{}β menu structureCURSORPOSβ default''β current position of the cursorBORDERβ default0β avoid window borders
now, the MENUS option? she's a hash of hashes, okay. each hash is a separate menu, and the constituent hashes are Entry/Function pairs. and every single one of those hashes requires a special key/value pair that determines the order of the items when displayed. each item is separated by two spaces. don't ask, just do it π«Ά
π draw
$menu->draw($mwh, 1);
draw renders the menu in its current state β she's serving looks, live π
this requires a valid handle to a curses window in which it will render itself.
the optional second argument? if it's true, the selection cursor gets rendered too. so basically: cursor goes on, cursor goes off. your call bestie.
β popup
$menu->popup;
this method causes the menu to be displayed. and since β theoretically β the menu should never be seen unless it's being actively used, we always assume we need to draw a cursor on the list as well. she said "if you're seeing me, I'm working." iconic π
π₯ execute
$menu->execute;
this acts like the standard Curses::Widgets method of the same name, with one exception: selecting any menu item will also cause it to exit β having already called the associated item subroutine. so like, the sub runs first, then she dips. bye bestie π
π HISTORY π
2002/10/17 -- First implementation
the origin story. a humble beginning. we love a glow-up π
π«Ά AUTHOR/COPYRIGHT π«Ά
(c) 2001 Arthur Corliss (corliss@digitalmages.com)
give him his flowers, he earned them π
and that's the whole page, bestie β she's from perl v5.34.0, dated 2022-06-12, and honestly? still eating. π
β¨
π¦ where this page comes from
- debian bookworm: libcurses-widgets-perl 1.997-8
- debian trixie: libcurses-widgets-perl 1.997-8
- ubuntu noble: libcurses-widgets-perl 1.997-8
- ubuntu resolute: libcurses-widgets-perl 1.997-8
- ubuntu stonking: libcurses-widgets-perl 1.997-8
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms