summaryrefslogtreecommitdiff
path: root/examples/menus.rb
diff options
context:
space:
mode:
authorGregory Brown <gregory.t.brown@gmail.com>2009-02-02 11:59:04 -0500
committerGregory Brown <gregory.t.brown@gmail.com>2009-02-02 11:59:04 -0500
commit6ff9ffe5fabf766183db9ed1d548b70e21f02eb6 (patch)
tree19a69d22f4c15a7ec1dfb69988f2fa51365b08fe /examples/menus.rb
parent37cd9cff1783911ab51afd90ba6588ce12c58b57 (diff)
downloadhighline-6ff9ffe5fabf766183db9ed1d548b70e21f02eb6.tar.gz
restructuring
Diffstat (limited to 'examples/menus.rb')
-rw-r--r--examples/menus.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/examples/menus.rb b/examples/menus.rb
new file mode 100644
index 0000000..e31c11d
--- /dev/null
+++ b/examples/menus.rb
@@ -0,0 +1,65 @@
+#!/usr/local/bin/ruby -w
+
+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