1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
# frozen_string_literal: true
require_relative "../lib/tty-prompt"
@prompt = TTY::Prompt.new(quiet: true)
@cool = 0
def main_menu(_from = nil)
name = @prompt.select("Cool Menu") do |menu|
menu.enum "."
menu.choice "Coolness Status", :status_menu
menu.choice "Manage Coolness", :manage_menu
menu.choice "Exit", "exit"
end
next_menu(name, :main_menu)
end
def next_menu(name, from)
if name.is_a?(Symbol)
send(name, from)
else
eval(name)
end
end
def status_menu(from)
name = @prompt.select("Coolness is at #{@cool}") do |menu|
menu.enum "."
menu.choice "Back", from
menu.choice "Exit", "exit"
end
next_menu(name, :status_menu)
end
def manage_menu(_from)
name = @prompt.select("Coolness is at #{@cool}.\nManage") do |menu|
menu.enum "."
menu.choice "Add coolness", :add_cool
menu.choice "Back", :main_menu
menu.choice "Exit", "exit"
end
next_menu(name, :manage_menu)
end
def add_cool(from)
@cool += 1
next_menu(from, from)
end
main_menu
|