NetHack::Menu - interact with NetHack's menus
Version 0.06 released Jan 2009
use NetHack::Menu; my $menu = NetHack::Menu->new(vt => $term_vt102); # compile all pages of the menu until ($menu->at_end) { $term_vt102->process($nh->send_and_recv($menu->next)); } # we want to stuff all blessed items into our bag $menu->select(sub { /blessed/ }); # but we don't want things that will make our bag explode $menu->deselect(sub { /cancell|bag.*(holding|tricks)/ }); $term_vt102->process($nh->send_and_recv($menu->commit));
NetHack requires a lot of menu management. This module aims to alleviate the difficulty of parsing and interacting with menus.
This module is meant to be as general and flexible as possible. You just give it a Term::VT102 object, send the commands it gives you to NetHack, and update the Term::VT102 object. Your code should look roughly the same as the code given in the Synopsis.
NetHack::Menu
Takes a Term::VT102 (or a behaving subclass, such as Term::VT102::Boundless or Term::VT102::ZeroBased). Also takes an optional select_count which determines the type of menu. NetHack::Menu cannot intuit it by itself, it depends on the application to know what it is dealing with. Default: multi.
select_count
multi
Accessor for select_count. Default: multi.
WARNING: No-select menus are potentially ambiguous with --More--. See below.
Is there currently a menu on the screen?
This will return whether we've finished compiling the menu. This must be called for each page because this is what does all the compilation.
Note that if there's no menu, this will croak.
croak
Returns the string to be used to get to the next page. Note that you should not ignore this method and use > or a space if your menu may not start on page 1. This method will make sure everything is hunky-dory anyway, so you should still use it.
>
Evaluates the code for each item on the menu and selects those which produce a true value. The code ref receives $_ as the text of the item (e.g. a blessed +1 quarterstaff (weapon in hands)). The code ref also receives the item's selector (the character you'd type to toggle the item) as an argument.
$_
a blessed +1 quarterstaff (weapon in hands)
Note that you can stack up multiple selects (and deselects) before eventually finishing the menu with $menu->commit.
$menu->commit
Do note that selecting is not the same as toggling.
This currently returns no useful value.
Same as select, but instead of returning a truth value the coderef should return undef (if no change is to be made for this item), a non-negative integer (to select a specific amount), or the special string 'all'.
Same as select, but different in the expected way. :)
:)
This will return the string to be sent that will navigate the menu and toggle the requested items.
Not everyone uses the default ^, |, and > menu accelerators. Provide a way to change them.
^
|
Not everyone uses Term::VT102. Provide some way to pass in just a string or something. This will be added on an if-needed basis. Anyone?
Shawn M Moore, <sartak at gmail.com>
<sartak at gmail.com>
Unfortunately, NetHack uses the string --More-- to indicate a no-select menu. This is ambiguous with a list of messages that spills over onto another "page".
--More--
The expected way to handle no-select menus is to:
This can be done by looking to see if it contains, for example, "Discoveries". Note that "Things that are here" can appear on the third line. Argh!
Please report any other bugs through RT: email bug-nethack-menu at rt.cpan.org, or browse http://rt.cpan.org/NoAuth/ReportBug.html?Queue=NetHack-Menu.
bug-nethack-menu at rt.cpan.org
You can find this documentation for this module with the perldoc command.
perldoc NetHack::Menu
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/NetHack-Menu
CPAN Ratings
http://cpanratings.perl.org/d/NetHack-Menu
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=NetHack-Menu
Search CPAN
http://search.cpan.org/dist/NetHack-Menu
Copyright 2007 Shawn M Moore.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install NetHack::Menu, copy and paste the appropriate command in to your terminal.
cpanm
cpanm NetHack::Menu
CPAN shell
perl -MCPAN -e shell install NetHack::Menu
For more information on module installation, please visit the detailed CPAN module installation guide.