-
Notifications
You must be signed in to change notification settings - Fork 8
/
checklist.rb
executable file
·80 lines (67 loc) · 2.01 KB
/
checklist.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
#!/usr/bin/env ruby
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
require 'pp'
begin
ME = File.basename($0)
if ENV['CHANGE_TITLE']
if ME =~ /(.+)\.rb$/
base = $1
puts "\033]0;mrdialog - #{base}\007"
end
end
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. Set the option
notags to true if you don't want to diaplay the tags.
Which of the following are fruits?
EOF
items = []
checklist_data = Struct.new(:tag, :item, :select)
data = checklist_data.new
data.tag = "Apple"
data.item = "It's an applie"
data.select = false
items.push(data.to_a)
data = checklist_data.new
data.tag = "Dog"
data.item = "No it's not my dog"
data.select = true
items.push(data.to_a)
data = checklist_data.new
data.tag = "Orange"
data.item = "Yeah! it is juicy"
data.select = false
items.push(data.to_a)
data = checklist_data.new
data.tag = "Chicken"
data.item = "Normally not a pet"
data.select = true
items.push(data.to_a)
dialog = MRDialog.new
# dialog.notags = false
# dialog.dialog_options = "--no-tags"
dialog.clear = true
dialog.title = "CHECKLIST"
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
selected_items = dialog.checklist(text, items)
exit_code = dialog.exit_code
puts selected_items.class
puts "Exit code: #{exit_code}"
if selected_items
puts "Selected Items:"
selected_items.each do |item|
puts " '#{item}'"
end
end
rescue => e
puts "#{$!}"
t = e.backtrace.join("\n\t")
puts "Error: #{t}"
end