lib/menu.rb in rubytext-0.0.81 vs lib/menu.rb in rubytext-0.0.82

- old
+ new

@@ -1,10 +1,9 @@ module RubyText def self.menu(win: STDSCR, r: 0, c: 0, items:, curr: 0, fg: White, bg: Blue) -# save_flags RubyText.hide_cursor high = items.size + 2 wide = items.map(&:length).max + 4 win.saveback(high, wide, r, c) mwin = RubyText.window(high, wide, r+win.r0+1, c+win.c0+1, @@ -27,59 +26,55 @@ when X::KEY_DOWN sel += 1 if sel < max when 27 win.restback(high, wide, r, c) RubyText.show_cursor -# rest_flags return [nil, nil] when 10 win.restback(high, wide, r, c) RubyText.show_cursor -# rest_flags return [sel, items[sel]] end RubyText.show_cursor -# rest_flags end end def self.selector(win: STDSCR, r: 0, c: 0, rows: 10, cols: 20, items:, fg: White, bg: Blue, win2:, callback:, enter: nil, quit: "q") high = rows wide = cols - win.saveback(high, wide, r, c) mwin = RubyText.window(high, wide, r, c, fg: fg, bg: bg) handler = callback X.stdscr.keypad(true) RubyText.hide_cursor norm = RubyText::Effects.new(:normal) rev = RubyText::Effects.new(:reverse) sel = 0 max = items.size - 1 - send(handler, sel, items[sel], win2) + handler.call(sel, items[sel], win2) loop do mwin.home items.each.with_index do |item, row| - mwin.left - style = (sel == row) ? rev : norm - mwin.puts style, " #{item} " + mwin.crlf + style = (sel == row) ? :reverse : :normal + mwin.print fx(" #{item}", style) end ch = getch case ch when X::KEY_UP if sel > 0 sel -= 1 - send(handler, sel, items[sel], win2) + handler.call(sel, items[sel], win2) end when X::KEY_DOWN if sel < max sel += 1 - send(handler, sel, items[sel], win2) + handler.call(sel, items[sel], win2) end when 10 # Enter if enter - del = send(enter, sel, items[sel], win2) + del = enter.call(sel, items[sel], win2) if del items -= [items[sel]] raise end end