lib/wmiirc/menu.rb
##
# Shows a menu (where the user must press keys on their keyboard to
# make a choice) with the given items and returns the chosen item.
#
# If nothing was chosen, then nil is returned.
#
# ==== Parameters
#
# [choices]
#   List of choices to display in the menu.
#
# [prompt]
#   Instructions on what the user should enter or choose.
#
# [history_name]
#   Basename of the file in which the user's
#   choices will be stored: the history file.
#
# [history_size]
#   Number of items to keep in the history file.
#
Shows a menu (where the user must press keys on their keyboard to
make a choice) with the given items and returns the chosen item.

If nothing was chosen, then nil is returned.

Parameters

[choices]
List of choices to display in the menu.

[prompt]
Instructions on what the user should enter or choose.

[history_name]
Basename of the file in which the user's
choices will be stored: the history file.

[history_size]
Number of items to keep in the history file.
Shows a menu ( where the user must press keys on their keyboard to make a choice ) with the given items and returns the chosen item . If nothing was chosen then nil is returned . Parameters [ choices ] List of choices to display in the menu . [ prompt ] Instructions on what the user should enter or choose . [ history_name ] Basename of the file in which the user ' s choices will be stored : the history file . [ history_size ] Number of items to keep in the history file .
def key_menu choices, prompt = nil, history_name = nil, history_size = 200
    command = ['wimenu']
    command.push '-p', prompt if prompt
    if history_name
      history_file = File.join(HISTORY_DIR, history_name)
      command.push '-h', history_file, '-n', history_size.to_s
      if File.exist? history_file
        history = File.read(history_file).chomp.split(/\n/)
        choices = history.reverse.concat(choices).uniq
      end
    end
    IO.popen(command.shelljoin, 'r+') do |menu|
      menu.puts choices
      menu.close_write
      choice = menu.read
      choice unless choice.empty?
    end
  end
def key_menu choices , prompt = nil , history_name = nil , history_size = 200 command = [ 'wimenu' ] command . push '-p' , prompt if prompt if history_name history_file = File . join ( HISTORY_DIR , history_name ) command . push '-h' , history_file , '-n' , history_size . to_s if File . exist? history_file history = File . read ( history_file ) . chomp . split ( / \n / ) choices = history . reverse . concat ( choices ) . uniq end end IO . popen ( command . shelljoin , 'r+' ) do | menu | menu . puts choices menu . close_write choice = menu . read choice unless choice . empty? end end
Shows a menu (where the user must press keys on their keyboard to
make a choice) with the given items and returns the chosen item.
Shows a menu ( where the user must press keys on their keyboard to make a choice ) with the given items and returns the chosen item .
# show history before actual choices
choices
<not_specific>
prompt
<not_specific>
history_name
<not_specific>
history_size
<not_specific>