-
Notifications
You must be signed in to change notification settings - Fork 8
/
radiolist.rb
executable file
·86 lines (70 loc) · 2.08 KB
/
radiolist.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
# muquit@muquit.com Apr-01-2014
require [File.expand_path(File.dirname(__FILE__)), '../..', 'lib', 'mrdialog'].join('/')
require 'pp'
class TestRadiolist
ME = File.basename($0)
def initialize
if ENV['CHANGE_TITLE']
if ME =~ /(.+)\.rb$/
base = $1
puts "\033]0;mrdialog - #{base}\007"
end
end
end
def doit
dialog = MRDialog.new
dialog.clear = true
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
text = <<EOF
This example is taken from dialog/samples/radiolist
shell script.
Hi, this is a radiolist box. You can use this to
present a list of choices which can be turned on or
off. If there are more items than can fit on the
screen, the list 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.
Press SPACE to toggle an option on/off.
Which of the following are fruits?
EOF
items = []
radiolist_data = Struct.new(:tag, :item, :select)
data = radiolist_data.new
data.tag = "Apple"
data.item = "It's an applie"
data.select = false
items.push(data.to_a)
data = radiolist_data.new
data.tag = "Dog"
data.item = "No it's not my dog"
data.select = true
items.push(data.to_a)
data = radiolist_data.new
data.tag = "Orange"
data.item = "Yeah! it is juicy"
data.select = false
items.push(data.to_a)
dialog.title = "RADIOLIST"
dialog.extra_button = true
dialog.ok_label = "Edit"
dialog.extra_label = "Delete"
dialog.cancel_label = "Quit"
selected_item = dialog.radiolist(text, items)
exit_code = dialog.exit_code
case exit_code
when dialog.dialog_ok
puts "OK Pressed"
when dialog.dialog_extra
puts "Extra Pressed"
when dialog.dialog_cancel
puts "Cancel Pressed"
when dialog.dialog_esc
puts "Escape Pressed"
end
puts "Selected item: #{selected_item}"
end
end
if __FILE__ == $0
TestRadiolist.new.doit
end