Sha256: c501ee39a0c281c069e14a5e844295da0e84215a6d747b0b711bdcc6ba3d7b46

Contents?: true

Size: 1.66 KB

Versions: 54

Compression:

Stored size: 1.66 KB

Contents

#!/usr/bin/env ruby

require "rubygems"
require "highline/import"

# The old way, using ask() and say()...
choices = %w{ruby python perl}
say("This is the old way using ask() and say()...")
say("Please choose your favorite programming language:")
say(choices.map { |c| "  #{c}\n" }.join)

case ask("?  ", choices)
when "ruby"
  say("Good choice!")
else
  say("Not from around here, are you?")
end

# The new and improved choose()...
say("\nThis is the new mode (default)...")
choose do |menu|
  menu.prompt = "Please choose your favorite programming language?  "

  menu.choice :ruby do say("Good choice!") end
  menu.choices(:python, :perl) do say("Not from around here, are you?") end
end

say("\nThis is letter indexing...")
choose do |menu|
  menu.index        = :letter
  menu.index_suffix = ") "

  menu.prompt = "Please choose your favorite programming language?  "

  menu.choice :ruby do say("Good choice!") end
  menu.choices(:python, :perl) do say("Not from around here, are you?") end
end

say("\nThis is with a different layout...")
choose do |menu|
  menu.layout = :one_line

  menu.header = "Languages"
  menu.prompt = "Favorite?  "

  menu.choice :ruby do say("Good choice!") end
  menu.choices(:python, :perl) do say("Not from around here, are you?") end
end

say("\nYou can even build shells...")
loop do
  choose do |menu|
    menu.layout = :menu_only

    menu.shell  = true

    menu.choice(:load, "Load a file.") do |command, details|
      say("Loading file with options:  #{details}...")
    end
    menu.choice(:save, "Save a file.") do |command, details|
      say("Saving file with options:  #{details}...")
    end
    menu.choice(:quit, "Exit program.") { exit }
  end
end

Version data entries

54 entries across 53 versions & 10 rubygems

Version Path
brakeman-4.3.1 bundle/ruby/2.5.0/gems/highline-1.7.10/examples/menus.rb
brakeman-4.3.0 bundle/ruby/2.5.0/gems/highline-1.7.10/examples/menus.rb
brakeman-4.2.1 bundle/ruby/2.5.0/gems/highline-1.7.10/examples/menus.rb
brakeman-4.2.0 bundle/ruby/2.3.0/gems/highline-1.7.10/examples/menus.rb
brakeman-4.1.1 bundle/ruby/2.3.0/gems/highline-1.7.10/examples/menus.rb
brakeman-4.1.0 bundle/ruby/2.3.0/gems/highline-1.7.10/examples/menus.rb
highline-1.7.10 examples/menus.rb
brakeman-4.0.1 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-4.0.1.pre1 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-4.0.0 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-3.7.2 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-3.7.1 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-3.7.0 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-3.6.2 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-3.6.1 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-3.6.0 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-3.5.0 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-3.4.1 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-3.4.0 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb
brakeman-3.3.5 bundle/ruby/2.3.0/gems/highline-1.7.8/examples/menus.rb