Class: RETerm::Menu
- Inherits:
-
Object
- Object
- RETerm::Menu
- Includes:
- EventDispatcher
- Defined in:
- lib/reterm/menu.rb
Overview
Graphical menu rendered on screen
TODO: look into working this into std component/activation subsystem
Instance Attribute Summary collapse
-
#window ⇒ Object
Returns the value of attribute window.
Instance Method Summary collapse
-
#attach_to(win) ⇒ Object
Attach menu to specified window.
-
#cols ⇒ Object
Return number of cols in menu.
-
#detach ⇒ Object
Destroy menu subsystem.
-
#drive(i) ⇒ Object
Drive menu from input.
-
#driver_map ⇒ Object
Static map of menu drivers to internal representations.
- #finalize! ⇒ Object
-
#initialize(items = {}) ⇒ Menu
constructor
Menus should be instantiated with a hash of label/value pairs to assign to menu.
-
#rows ⇒ Object
Return number of rows in menu.
Methods included from EventDispatcher
Constructor Details
#initialize(items = {}) ⇒ Menu
Menus should be instantiated with a hash of label/value pairs to assign to menu
12 13 14 15 16 17 18 19 |
# File 'lib/reterm/menu.rb', line 12 def initialize(items={}) @items = items = Ncurses::Menu.(items.collect { |k,v| Ncurses::Menu.new_item(k.to_s, v.to_s) }) .(Ncurses::Menu::O_SHOWDESC) end |
Instance Attribute Details
#window ⇒ Object
Returns the value of attribute window.
8 9 10 |
# File 'lib/reterm/menu.rb', line 8 def window @window end |
Instance Method Details
#attach_to(win) ⇒ Object
Attach menu to specified window
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/reterm/menu.rb', line 32 def attach_to(win) .(win.win) win.component = self @child_win = win.create_child :rows => rows, :cols => cols, :x => 1, :y => 1 .(@child_win.win) . self end |
#cols ⇒ Object
Return number of cols in menu
27 28 29 |
# File 'lib/reterm/menu.rb', line 27 def cols @cols ||= @items.keys.max { |k| k.size }.size + 3 end |
#detach ⇒ Object
Destroy menu subsystem
46 47 48 |
# File 'lib/reterm/menu.rb', line 46 def detach . end |
#drive(i) ⇒ Object
Drive menu from input
76 77 78 79 |
# File 'lib/reterm/menu.rb', line 76 def drive(i) i = driver_map[i] if i.is_a?(Symbol) Ncurses::Menu.(, i) end |
#driver_map ⇒ Object
Static map of menu drivers to internal representations.
XXX defined here (as opposed to a const) since these consts won’t be available until after init_scr
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/reterm/menu.rb', line 57 def driver_map @driver_map ||= { :left => Ncurses::Menu::REQ_LEFT_ITEM, :right => Ncurses::Menu::REQ_RIGHT_ITEM, :up => Ncurses::Menu::REQ_UP_ITEM, :down => Ncurses::Menu::REQ_DOWN_ITEM, :scr_up_line => Ncurses::Menu::REQ_SCR_ULINE, :scr_down_line => Ncurses::Menu::REQ_SCR_DLINE, :scr_down_page => Ncurses::Menu::REQ_SCR_DPAGE, :scr_up_page => Ncurses::Menu::REQ_SCR_UPAGE, :first => Ncurses::Menu::REQ_FIRST_ITEM, :last => Ncurses::Menu::REQ_LAST_ITEM, :next => Ncurses::Menu::REQ_NEXT_ITEM, :prev => Ncurses::Menu::REQ_PREV_ITEM, :toggle => Ncurses::Menu::REQ_TOGGLE_ITEM } end |
#finalize! ⇒ Object
50 51 |
# File 'lib/reterm/menu.rb', line 50 def finalize! end |
#rows ⇒ Object
Return number of rows in menu
22 23 24 |
# File 'lib/reterm/menu.rb', line 22 def rows @items.size end |