lib/ppcurses/menu/BaseMenu.rb in ppcurses-0.0.25 vs lib/ppcurses/menu/BaseMenu.rb in ppcurses-0.1.0
- old
+ new
@@ -1,7 +1,5 @@
-require 'curses'
-
module PPCurses
#noinspection RubyResolve
class BaseMenu
@@ -9,24 +7,19 @@
attr_accessor :selection
attr_accessor :side_wall_char
attr_accessor :top_bot_wall_char
- #
- # Current base ruby is 1.9.2. action_items could be an optional parameter
- # if the base was moved up to 2.0
- #
- def initialize(menu_items, action_items )
+
+ def initialize(menu_items, action_items=nil)
@selection=0
@max_menu_width = 0
@side_wall_char = '|'
@top_bot_wall_char = '-'
- sample = menu_items[0]
-
- case sample
+ case menu_items[0]
when String
# Case 1: menu_items is a list of strings, with an associated action list
build_menu_items(menu_items, action_items)
else
# Case 2: Received a list of MenuItem, or objects that implement
@@ -59,17 +52,18 @@
display = menu_items[i].display_string
@max_menu_width = display.length if display.length > @max_menu_width
}
end
+ def set_origin( point )
+ @win.move_to_point( point )
+ end
+
def create_window
w_height = @menu_items.length + 4
w_width = @max_menu_width + 4
- @win = Window.new(w_height,w_width,(lines-w_height) / 2, (cols-w_width)/2)
-
+ @win = PPCurses::Window.new(w_height,w_width,(Curses.lines-w_height) / 2, (Curses.cols-w_width)/2)
@win.timeout=-1
- # Enables reading arrow keys in getch
- @win.keypad(true)
end
def set_sub_menu(menu)
@sub_menu = menu
end