Widgets::Menu(3pm)

πŸ“¦
version 1.997 Β· 2 versions
  • 1.997 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.997 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’… 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:

  • Curses
  • Curses::Widgets
  • Curses::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 keystrokes
  • FOREGROUND β€” default undef β€” default foreground colour
  • BACKGROUND β€” default 'black' β€” default background colour
  • FOCUSSWITCH β€” default "\t" β€” characters which signify end of input
  • MENUS β€” default {} β€” menu structure
  • CURSORPOS β€” default '' β€” current position of the cursor
  • BORDER β€” default 0 β€” 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.


$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 πŸŽ€


(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. πŸ’…βœ¨