class Nknm::List::Selectors::Terminal

Public Instance Methods

selection() click to toggle source

Generate a menu within the terminal that allows a user to select the desired item from the list. @return [Object] the user-selected option

# File lib/nknm/list/selectors/terminal.rb, line 10
def selection
  items.each_with_index { |s, i| stream.puts "#{i + 1}) #{s}" }
  stream.write "? "
  idx = $stdin.readline.to_i - 1
  items[idx] if idx >= 0
end

Private Instance Methods

stream() click to toggle source
# File lib/nknm/list/selectors/terminal.rb, line 19
def stream
  @_stream ||= $stderr
end