lib/ppcurses/menu/menu_item.rb in ppcurses-0.0.22 vs lib/ppcurses/menu/menu_item.rb in ppcurses-0.0.23

- old
+ new

@@ -8,11 +8,15 @@ SELECTED_CHAR = '✓' class MenuItem attr_accessor :title - attr_accessor :action + + # Who to notify when menu is selected chosen? + # The target should be a method selector, and + attr_accessor :target + attr_accessor :state attr_accessor :selectable def initialize( title ) @title = title @@ -43,9 +47,19 @@ def handle_key(key) if key == ' ' and @selectable toggle_on_off_state + unless @target.nil? + @target.call(self) + end + return true + end + + if key == ENTER + unless @target.nil? + @target.call(self) + end return true end false end