Class | Hirb::Menu |
In: |
lib/hirb/menu.rb
|
Parent: | Object |
This class provides a menu using Hirb‘s table helpers by default to display choices. Menu choices (syntax at Hirb::Util.choose_from_array) refer to rows. However, when in two_d mode, choices refer to specific cells by appending a ’:field’ to a choice. A field name can be an abbreviated. Menus can also have an action mode, which turns the menu prompt into a commandline that executes the choices as arguments and uses methods as actions/commands.
CHOSEN_REGEXP | = | /^(\d([^:]+)?|\*)(?::)?(\S+)?/ | Detects valid choices and optional field/column | |
CHOSEN_ARG | = | '%s' | ||
DIRECTIONS | = | "Specify individual choices (4,7), range of choices (1-3) or all choices (*)." |
This method will return an array unless it‘s exited by simply pressing return, which returns nil. If given a block, the block will yield if and with any menu items are chosen. All options except for the ones below are passed to render the menu.
Examples:
>> extend Hirb::Console => self >> menu [1,2,3], :prompt=> "So many choices, so little time: " >> menu [{:a=>1, :b=>2}, {:a=>3, :b=>4}], :fields=>[:a,b], :two_d=>true)