-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathchecklist.rb
More file actions
executable file
·91 lines (78 loc) · 2.4 KB
/
checklist.rb
File metadata and controls
executable file
·91 lines (78 loc) · 2.4 KB
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
86
87
88
89
90
91
#!/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 One"
data.item = "It's an applie"
data.select = false
items.push(data.to_a)
data = checklist_data.new
data.tag = "Dog Two"
data.item = "No it's not my dog"
data.select = true
items.push(data.to_a)
data = checklist_data.new
data.tag = "Orange Three"
data.item = "Yeah! it is juicy"
data.select = false
items.push(data.to_a)
data = checklist_data.new
data.tag = "Chicken Four"
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.dialog_options = "--separator '|' --single-quoted"
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
# selected_items is an array with 1 element the array looks something
# like '|'Dog Two'|'Chicken Four''
# convert the output to an array with selected items
x = selected_items.join() # a string
a = []
aa = x.split('|')
aa.each do |e|
e = e.gsub(/\'/,'')
next if e.length == 0
a << e
end
a.each do |item|
puts " '#{item}'"
end
end
rescue => e
puts "#{$!}"
t = e.backtrace.join("\n\t")
puts "Error: #{t}"
end