-
Notifications
You must be signed in to change notification settings - Fork 8
/
menubox.rb
executable file
·85 lines (68 loc) · 1.89 KB
/
menubox.rb
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env ruby
# [email protected] Apr-01-2014
require [File.expand_path(File.dirname(__FILE__)), '../..', 'lib', 'mrdialog'].join('/')
begin
ME = File.basename($0)
if ENV['CHANGE_TITLE']
if ME =~ /(.+)\.rb$/
base = $1
puts "\033]0;mrdialog - #{base}\007"
end
end
dialog = MRDialog.new
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
dialog.clear = true
dialog.title = "MENU BOX"
dialog.extra_button = true
dialog.ok_label = "Send"
dialog.extra_label = "Save"
dialog.cancel_label = "Quit"
text = <<EOF
This example is taken from dialog/samples/menubox1
Hi, this is a menu box. You can use this to
present a list of choices for the user to
choose. If there are more items than can fit
on the screen, the menu will be scrolled.
You can use the UP/DOWN arrow keys, the first
letter of the choice as a hot key, or the
number keys 1-9 to choose an option.
Try it now!
Choose the OS you like:
EOF
items = []
menu_data = Struct.new(:tag, :item)
data = menu_data.new
data.tag = "Linux"
data.item = "The Great Unix Clone for 386/486"
items.push(data.to_a)
data = menu_data.new
data.tag = "NetBSD"
data.item = "Another free Unix Clone for 386/486"
items.push(data.to_a)
data = menu_data.new
data.tag = "OS/2"
data.item = "IBM OS/2"
items.push(data.to_a)
data = menu_data.new
data.tag = "WIN NT"
data.item = "Microsoft Windows NT"
items.push(data.to_a)
data = menu_data.new
data.tag = "PCDOS"
data.item = "IBM PC DOS"
items.push(data.to_a)
data = menu_data.new
data.tag = "MSDOS"
data.item = "Microsoft DOS"
items.push(data.to_a)
height = 0
width = 0
menu_height = 4
selected_item = dialog.menu(text, items, height, width, menu_height)
puts "Exit Code: #{dialog.exit_code}"
puts "Selected item: #{selected_item}"
rescue => e
puts "#{$!}"
t = e.backtrace.join("\n\t")
puts "Error: #{t}"
end