Class: PPCurses::Menu
Overview
noinspection RubyResolve
Direct Known Subclasses
Instance Attribute Summary collapse
-
#selection ⇒ Object
Returns the value of attribute selection.
Attributes inherited from BaseMenu
#menu_items, #side_wall_char, #top_bot_wall_char
Instance Method Summary collapse
- #handle_menu_selection(c) ⇒ Object
- #menu_selection ⇒ Object
- #set_global_action(action) ⇒ Object
- #show ⇒ Object
Methods inherited from BaseMenu
#build_menu_items, #close, #create_window, #find_max_menu_width, #hide, #initialize, #selected_menu_name, #set_origin, #set_sub_menu
Constructor Details
This class inherits a constructor from PPCurses::BaseMenu
Instance Attribute Details
#selection ⇒ Object
Returns the value of attribute selection.
5 6 7 |
# File 'lib/ppcurses/menu/Menu.rb', line 5 def selection @selection end |
Instance Method Details
#handle_menu_selection(c) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ppcurses/menu/Menu.rb', line 48 def (c) n_choices = @menu_items.length if c == KEY_UP (@selection == 0) ? @selection = n_choices - 1 : @selection -= 1 self.show return true end if c == KEY_DOWN (@selection == n_choices-1) ? @selection = 0 : @selection += 1 self.show return true end if c == ENTER && !@global_action.nil? unless @global_action.nil? @global_action.execute end self.show return true end item_consumed = @menu_items[@selection].handle_key(c) if item_consumed self.show end item_consumed end |
#menu_selection ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ppcurses/menu/Menu.rb', line 30 def while 1 c = @win.getch not_processed = !self.(c) if c == ESCAPE self.hide break end @sub_menu.(c) if not_processed && @sub_menu end end |
#set_global_action(action) ⇒ Object
25 26 27 28 |
# File 'lib/ppcurses/menu/Menu.rb', line 25 def set_global_action(action) PPCurses.implements_protocol(action, %w(execute)) @global_action = action end |
#show ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ppcurses/menu/Menu.rb', line 7 def show @win.box(self.side_wall_char, self.top_bot_wall_char) y = 2 x = 2 (0...@menu_items.length).each { |i| @win.setpos(y, x) @win.attron(Curses::A_REVERSE) if @selection == i @win.addstr(@menu_items[i].display_string) @win.attroff(Curses::A_REVERSE) if @selection == i y += 1 } @win.refresh @sub_menu.show if @sub_menu end |