Class: Hirb::Menu

### Home Classes Methods

### In Files

- lib/hirb/menu.rb

### Parent

Object

### Namespace

- CLASS Hirb::Menu::Error

### Methods

- ::render

### Files

- LICENSE.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Hirb
- Hirb::Console
- Hirb::DynamicView
- Hirb::Formatter
- Hirb::Helpers
- Hirb::Helpers::AutoTable
- Hirb::Helpers::ObjectTable
- Hirb::Helpers::ParentChildTree
- Hirb::Helpers::Table
- Hirb::Helpers::Table::Filters
- Hirb::Helpers::Table::Resizer
- Hirb::Helpers::Table::TooManyFieldsForWidthError
- Hirb::Helpers::Tree
- Hirb::Helpers::Tree::Node
- Hirb::Helpers::Tree::Node::MissingLevelError
- Hirb::Helpers::Tree::Node::MissingValueError
- Hirb::Helpers::Tree::ParentlessNodeError
- Hirb::Helpers::VerticalTable
- Hirb::Menu
- Hirb::Menu::Error
- Hirb::ObjectMethods
- Hirb::Pager
- Hirb::String
- Hirb::Util
- Hirb::View
- Hirb::Views

No matching classes.

# Hirb::Menu

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.

### Constants

CHOSEN_ARG
CHOSEN_REGEXP

  Detects valid choices and optional field/column

DIRECTIONS

### Public Class Methods

render(output, options={}, &block) click to toggle source

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.

#### Options:

:helper_class

  Helper class to render menu. Helper class is expected to implement numbering given a :number option. To use a very basic menu, set this to false. Defaults to Hirb::Helpers::AutoTable.

:prompt

  String for menu prompt. Defaults to "Choose: ".

:ask

  Always ask for input, even if there is only one choice. Default is true.

:directions

  Display directions before prompt. Default is true.

:readline

  Use readline to get user input if available. Input strings are added to readline history. Default is false.

:two_d

  Turn menu into a 2 dimensional (2D) menu by allowing user to pick values from table cells. Default is false.

:default_field

  Default field for a 2D menu. Defaults to first field in a table.

:action

  Turn menu into an action menu by letting user pass menu choices as an argument to a method/command. A menu choice’s place amongst other arguments is preserved. Default is false.

:multi_action

  Execute action menu multiple times iterating over the menu choices. Default is false.

:action_object

  Object that takes method/command calls. Default is main.

:command

  Default method/command to call when no command given.

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)

    # File lib/hirb/menu.rb, line 40
    def self.render(output, options={}, &block)
      new(options).render(output, &block)
    rescue Error=>e
      $stderr.puts "Error: #{e.message}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.