mrdialog 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/ChangeLog.md +61 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +52 -0
- data/Rakefile +62 -0
- data/VERSION +1 -0
- data/lib/mrdialog/mrdialog.rb +1245 -0
- data/lib/mrdialog.rb +3 -0
- data/pkg/mrdialog-1.0.1.gem +0 -0
- data/samples/buildlist.rb +77 -0
- data/samples/calendar.rb +33 -0
- data/samples/checklist.rb +67 -0
- data/samples/editbox.rb +60 -0
- data/samples/form1.rb +90 -0
- data/samples/form2.rb +170 -0
- data/samples/form3.rb +96 -0
- data/samples/fselect.rb +29 -0
- data/samples/gauge.rb +39 -0
- data/samples/infobox.rb +36 -0
- data/samples/inputbox.rb +36 -0
- data/samples/menubox.rb +72 -0
- data/samples/mixedform1.rb +120 -0
- data/samples/msgbox.rb +31 -0
- data/samples/password.rb +32 -0
- data/samples/password2.rb +39 -0
- data/samples/passwordform.rb +91 -0
- data/samples/pause.rb +48 -0
- data/samples/prgbox.rb +34 -0
- data/samples/program.rb +33 -0
- data/samples/progress.rb +32 -0
- data/samples/radiolist.rb +71 -0
- data/samples/shortlist +19 -0
- data/samples/timebox.rb +31 -0
- data/samples/treeview.rb +100 -0
- data/samples/treeview2.rb +80 -0
- data/samples/yesno.rb +39 -0
- data/test/helper.rb +34 -0
- data/test/test_mrdialog.rb +7 -0
- metadata +161 -0
data/samples/inputbox.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# muquit@muquit.com Apr-01-2014
|
4
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
begin
|
8
|
+
ME = File.basename($0)
|
9
|
+
text = <<EOF
|
10
|
+
Hi, this is an input dialog box. You can use
|
11
|
+
this to ask questions that require the user
|
12
|
+
to input a string as the answer. You can
|
13
|
+
input strings of length longer than the
|
14
|
+
width of the input box, in that case, the
|
15
|
+
input field will be automatically scrolled.
|
16
|
+
You can use BACKSPACE to correct errors.
|
17
|
+
Try entering your name below:
|
18
|
+
|
19
|
+
EOF
|
20
|
+
dialog = MRDialog.new
|
21
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
22
|
+
dialog.clear = true
|
23
|
+
dialog.title = "INPUT BOX"
|
24
|
+
|
25
|
+
height = 16
|
26
|
+
width = 51
|
27
|
+
init = "blah"
|
28
|
+
result = dialog.inputbox(text, height, width, init)
|
29
|
+
|
30
|
+
puts "Result is: #{result}"
|
31
|
+
|
32
|
+
rescue => e
|
33
|
+
puts "#{$!}"
|
34
|
+
t = e.backtrace.join("\n\t")
|
35
|
+
puts "Error: #{t}"
|
36
|
+
end
|
data/samples/menubox.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# muquit@muquit.com Apr-01-2014
|
4
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
5
|
+
begin
|
6
|
+
ME = File.basename($0)
|
7
|
+
dialog = MRDialog.new
|
8
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
9
|
+
dialog.clear = true
|
10
|
+
dialog.title = "MENU BOX"
|
11
|
+
|
12
|
+
text = <<EOF
|
13
|
+
This example is taken from dialog/samples/menubox1
|
14
|
+
|
15
|
+
Hi, this is a menu box. You can use this to
|
16
|
+
present a list of choices for the user to
|
17
|
+
choose. If there are more items than can fit
|
18
|
+
on the screen, the menu will be scrolled.
|
19
|
+
You can use the UP/DOWN arrow keys, the first
|
20
|
+
letter of the choice as a hot key, or the
|
21
|
+
number keys 1-9 to choose an option.
|
22
|
+
Try it now!
|
23
|
+
|
24
|
+
Choose the OS you like:
|
25
|
+
|
26
|
+
EOF
|
27
|
+
items = []
|
28
|
+
menu_data = Struct.new(:tag, :item)
|
29
|
+
data = menu_data.new
|
30
|
+
data.tag = "Linux"
|
31
|
+
data.item = "The Great Unix Clone for 386/486"
|
32
|
+
items.push(data.to_a)
|
33
|
+
|
34
|
+
data = menu_data.new
|
35
|
+
data.tag = "NetBSD"
|
36
|
+
data.item = "Another free Unix Clone for 386/486"
|
37
|
+
items.push(data.to_a)
|
38
|
+
|
39
|
+
data = menu_data.new
|
40
|
+
data.tag = "OS/2"
|
41
|
+
data.item = "IBM OS/2"
|
42
|
+
items.push(data.to_a)
|
43
|
+
|
44
|
+
data = menu_data.new
|
45
|
+
data.tag = "WIN NT"
|
46
|
+
data.item = "Microsoft Windows NT"
|
47
|
+
items.push(data.to_a)
|
48
|
+
|
49
|
+
data = menu_data.new
|
50
|
+
data.tag = "PCDOS"
|
51
|
+
data.item = "IBM PC DOS"
|
52
|
+
items.push(data.to_a)
|
53
|
+
|
54
|
+
data = menu_data.new
|
55
|
+
data.tag = "MSDOS"
|
56
|
+
data.item = "Microsoft DOS"
|
57
|
+
items.push(data.to_a)
|
58
|
+
|
59
|
+
|
60
|
+
height = 0
|
61
|
+
width = 0
|
62
|
+
menu_height = 4
|
63
|
+
|
64
|
+
selected_item = dialog.menu(text, items, height, width, menu_height)
|
65
|
+
|
66
|
+
puts "Selected item: #{selected_item}"
|
67
|
+
|
68
|
+
rescue => e
|
69
|
+
puts "#{$!}"
|
70
|
+
t = e.backtrace.join("\n\t")
|
71
|
+
puts "Error: #{t}"
|
72
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# muquit@muquit.com Apr-01-2014
|
4
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
begin
|
8
|
+
ME = File.basename($0)
|
9
|
+
# uid=1000(muquit) gid=1000(muquit)
|
10
|
+
# groups=1000(muquit),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),107(lpadmin),125(sambashare)
|
11
|
+
user = ''
|
12
|
+
uid = ''
|
13
|
+
gid = ''
|
14
|
+
home = ENV["HOME"]
|
15
|
+
|
16
|
+
id = `id`.chomp
|
17
|
+
if id =~ /^uid=(\d+)\((.+)\)\sgid=(\d+)\(.*$/
|
18
|
+
uid = $1
|
19
|
+
user = $2
|
20
|
+
gid = $3
|
21
|
+
end
|
22
|
+
|
23
|
+
dialog = MRDialog.new
|
24
|
+
dialog.clear = true
|
25
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
26
|
+
|
27
|
+
text = <<EOF
|
28
|
+
Example of mixedform. The Username field is editable, The
|
29
|
+
UID, GID and HOME fields are editable and the Password
|
30
|
+
field is hidden. Also the insecure option is set for the
|
31
|
+
dialog which makes every character for the password to
|
32
|
+
echo as an asterisk.
|
33
|
+
EOF
|
34
|
+
items = []
|
35
|
+
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen, :attr)
|
36
|
+
# for :attr 1=hidden 2=read only
|
37
|
+
read_only = 2
|
38
|
+
hidden = 1
|
39
|
+
|
40
|
+
data = form_data.new
|
41
|
+
data.label = "Username:"
|
42
|
+
data.ly = 1
|
43
|
+
data.lx = 1
|
44
|
+
data.item = user
|
45
|
+
data.iy = 1
|
46
|
+
data.ix = 10
|
47
|
+
data.flen = user.length + 10
|
48
|
+
data.ilen = 0
|
49
|
+
data.attr = 0
|
50
|
+
items.push(data.to_a)
|
51
|
+
|
52
|
+
data = form_data.new
|
53
|
+
data.label = "UID:"
|
54
|
+
data.ly = 2
|
55
|
+
data.lx = 1
|
56
|
+
data.item = uid.to_s
|
57
|
+
data.iy = 2
|
58
|
+
data.ix = 10
|
59
|
+
data.flen = uid.length + 10
|
60
|
+
data.ilen = 0
|
61
|
+
data.attr = read_only
|
62
|
+
items.push(data.to_a)
|
63
|
+
|
64
|
+
data = form_data.new
|
65
|
+
data.label = "GID:"
|
66
|
+
data.ly = 3
|
67
|
+
data.lx = 1
|
68
|
+
data.item = gid.to_s
|
69
|
+
data.iy =3
|
70
|
+
data.ix = 10
|
71
|
+
data.flen = gid.length + 2
|
72
|
+
data.ilen = 0
|
73
|
+
data.attr = read_only
|
74
|
+
items.push(data.to_a)
|
75
|
+
|
76
|
+
data = form_data.new
|
77
|
+
data.label = "HOME:"
|
78
|
+
data.ly = 4
|
79
|
+
data.lx = 1
|
80
|
+
data.item = home
|
81
|
+
data.iy = 4
|
82
|
+
data.ix = 10
|
83
|
+
data.flen = home.length + 40
|
84
|
+
data.ilen = 0
|
85
|
+
data.attr = read_only
|
86
|
+
items.push(data.to_a)
|
87
|
+
|
88
|
+
data = form_data.new
|
89
|
+
data.label = "Password:"
|
90
|
+
data.ly = 5
|
91
|
+
data.lx = 1
|
92
|
+
data.item = ""
|
93
|
+
data.iy = 5
|
94
|
+
data.ix = 10
|
95
|
+
data.flen = 16
|
96
|
+
data.ilen = 0
|
97
|
+
data.attr = hidden
|
98
|
+
items.push(data.to_a)
|
99
|
+
|
100
|
+
|
101
|
+
dialog.title = "mixedform"
|
102
|
+
dialog.insecure = true
|
103
|
+
height = 20
|
104
|
+
width = 70
|
105
|
+
result_hash = dialog.mixedform(text, items, height, width, 0)
|
106
|
+
exit_code = dialog.exit_code
|
107
|
+
puts "exit code: #{exit_code}"
|
108
|
+
if result_hash
|
109
|
+
puts "Resulting data:"
|
110
|
+
result_hash.each do |key, val|
|
111
|
+
puts " #{key} = #{val}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
rescue => e
|
117
|
+
puts "#{$!}"
|
118
|
+
t = e.backtrace.join("\n\t")
|
119
|
+
puts "Error: #{t}"
|
120
|
+
end
|
data/samples/msgbox.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# muquit@muquit.com Apr-01-2014
|
4
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
class TestMsgbox
|
8
|
+
ME = File.basename($0)
|
9
|
+
def initialize
|
10
|
+
end
|
11
|
+
|
12
|
+
def doit
|
13
|
+
dialog = MRDialog.new
|
14
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
15
|
+
dialog.clear = true
|
16
|
+
dialog.title = "MESSAGE BOX"
|
17
|
+
|
18
|
+
text = <<EOF
|
19
|
+
Hi, this is a simple message box. You can use this to \
|
20
|
+
display any message you like. The box will remain until \
|
21
|
+
you press the ENTER key.
|
22
|
+
|
23
|
+
EOF
|
24
|
+
result = dialog.msgbox(text, 10, 41)
|
25
|
+
puts "result: #{result}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if __FILE__ == $0
|
30
|
+
TestMsgbox.new.doit
|
31
|
+
end
|
data/samples/password.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# muquit@muquit.com Apr-01-2014
|
3
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
begin
|
7
|
+
ME = File.basename($0)
|
8
|
+
text = <<EOF
|
9
|
+
Hi, this is an password dialog box. You can use
|
10
|
+
this to ask questions that require the user
|
11
|
+
to input a string as the answer. You can
|
12
|
+
input strings of length longer than the
|
13
|
+
width of the input box, in that case, the
|
14
|
+
input field will be automatically scrolled.
|
15
|
+
You can use BACKSPACE to correct errors.
|
16
|
+
Try entering your name below:
|
17
|
+
|
18
|
+
EOF
|
19
|
+
dialog = MRDialog.new
|
20
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
21
|
+
dialog.clear = true
|
22
|
+
dialog.title = "Password box"
|
23
|
+
|
24
|
+
result = dialog.passwordbox(text)
|
25
|
+
|
26
|
+
puts "Result is: #{result}"
|
27
|
+
|
28
|
+
rescue => e
|
29
|
+
puts "#{$!}"
|
30
|
+
t = e.backtrace.join("\n\t")
|
31
|
+
puts "Error: #{t}"
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
########################################################################
|
4
|
+
# Example of password. It takes in the init arg and also set
|
5
|
+
# insecure option to dialog
|
6
|
+
# muquit@muquit.com Apr-02-2014
|
7
|
+
########################################################################
|
8
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
9
|
+
require 'pp'
|
10
|
+
|
11
|
+
begin
|
12
|
+
ME = File.basename($0)
|
13
|
+
text = <<EOF
|
14
|
+
Hi, this is an password dialog box. You can use
|
15
|
+
this to ask questions that require the user
|
16
|
+
to input a string as the answer. You can
|
17
|
+
input strings of length longer than the
|
18
|
+
width of the input box, in that case, the
|
19
|
+
input field will be automatically scrolled.
|
20
|
+
You can use BACKSPACE to correct errors.
|
21
|
+
|
22
|
+
Try entering your name below:
|
23
|
+
|
24
|
+
EOF
|
25
|
+
dialog = MRDialog.new
|
26
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
27
|
+
dialog.clear = true
|
28
|
+
dialog.title = "Password box"
|
29
|
+
dialog.insecure = true
|
30
|
+
|
31
|
+
result = dialog.passwordbox(text, 0, 0, "stupid")
|
32
|
+
|
33
|
+
puts "Result is: #{result}"
|
34
|
+
|
35
|
+
rescue => e
|
36
|
+
puts "#{$!}"
|
37
|
+
t = e.backtrace.join("\n\t")
|
38
|
+
puts "Error: #{t}"
|
39
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# muquit@muquit.com Apr-01-2014
|
4
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
begin
|
8
|
+
ME = File.basename($0)
|
9
|
+
# uid=1000(muquit) gid=1000(muquit)
|
10
|
+
# groups=1000(muquit),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),107(lpadmin),125(sambashare)
|
11
|
+
user = ''
|
12
|
+
uid = ''
|
13
|
+
gid = ''
|
14
|
+
home = ENV["HOME"]
|
15
|
+
|
16
|
+
id = `id`.chomp
|
17
|
+
if id =~ /^uid=(\d+)\((.+)\)\sgid=(\d+)\(.*$/
|
18
|
+
uid = $1
|
19
|
+
user = $2
|
20
|
+
gid = $3
|
21
|
+
end
|
22
|
+
|
23
|
+
dialog = MRDialog.new
|
24
|
+
dialog.clear = true
|
25
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
26
|
+
|
27
|
+
text = <<EOF
|
28
|
+
Here is a possible piece of a configuration program.
|
29
|
+
EOF
|
30
|
+
items = []
|
31
|
+
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen)
|
32
|
+
|
33
|
+
data = form_data.new
|
34
|
+
data.label = "Username:"
|
35
|
+
data.ly = 1
|
36
|
+
data.lx = 1
|
37
|
+
data.item = user
|
38
|
+
data.iy = 1
|
39
|
+
data.ix = 10
|
40
|
+
data.flen = user.length + 10
|
41
|
+
data.ilen = 0
|
42
|
+
items.push(data.to_a)
|
43
|
+
|
44
|
+
data = form_data.new
|
45
|
+
data.label = "UID:"
|
46
|
+
data.ly = 2
|
47
|
+
data.lx = 1
|
48
|
+
data.item = uid.to_s
|
49
|
+
data.iy = 2
|
50
|
+
data.ix = 10
|
51
|
+
data.flen = uid.length + 10
|
52
|
+
data.ilen = 0
|
53
|
+
items.push(data.to_a)
|
54
|
+
|
55
|
+
data = form_data.new
|
56
|
+
data.label = "GID:"
|
57
|
+
data.ly = 3
|
58
|
+
data.lx = 1
|
59
|
+
data.item = gid.to_s
|
60
|
+
data.iy =3
|
61
|
+
data.ix = 10
|
62
|
+
data.flen = gid.length + 2
|
63
|
+
data.ilen = 0
|
64
|
+
items.push(data.to_a)
|
65
|
+
|
66
|
+
data = form_data.new
|
67
|
+
data.label = "HOME:"
|
68
|
+
data.ly = 4
|
69
|
+
data.lx = 1
|
70
|
+
data.item = home
|
71
|
+
data.iy = 4
|
72
|
+
data.ix = 10
|
73
|
+
data.flen = home.length + 40
|
74
|
+
data.ilen = 0
|
75
|
+
items.push(data.to_a)
|
76
|
+
|
77
|
+
dialog.insecure = true
|
78
|
+
result_hash = dialog.passwordform(text, items, 20, 50, 0)
|
79
|
+
if result_hash
|
80
|
+
puts "Resulting data:"
|
81
|
+
result_hash.each do |key, val|
|
82
|
+
puts " #{key} = #{val}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
rescue => e
|
88
|
+
puts "#{$!}"
|
89
|
+
t = e.backtrace.join("\n\t")
|
90
|
+
puts "Error: #{t}"
|
91
|
+
end
|
data/samples/pause.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# muquit@muquit.com Apr-20-2014
|
4
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
class PauseBox
|
8
|
+
ME = File.basename($0)
|
9
|
+
def initialize
|
10
|
+
end
|
11
|
+
|
12
|
+
def doit
|
13
|
+
dialog = MRDialog.new
|
14
|
+
dialog.shadow = false
|
15
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
16
|
+
dialog.clear = true
|
17
|
+
dialog.title = "PAUSE BOX"
|
18
|
+
|
19
|
+
secs = 20
|
20
|
+
text = <<EOF
|
21
|
+
This is an example of pause box.
|
22
|
+
|
23
|
+
A pause box displays a meter along the bottom
|
24
|
+
of the box. The meter indicates how many seconds
|
25
|
+
remain until the end of the pause. The pause exits
|
26
|
+
when timeout is reached or the user presses the
|
27
|
+
OK button (status OK) or the user presses the
|
28
|
+
Cancel button or Esc key.
|
29
|
+
EOF
|
30
|
+
height = 15
|
31
|
+
width = 0
|
32
|
+
dialog.pause(text, height, width, secs)
|
33
|
+
exit_code = dialog.exit_code
|
34
|
+
puts "Exit code: #{exit_code}"
|
35
|
+
case exit_code
|
36
|
+
when 0
|
37
|
+
puts "OK"
|
38
|
+
when 1
|
39
|
+
puts "Cancel button pressed"
|
40
|
+
when 255
|
41
|
+
puts "Error or ESC button pressed"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if __FILE__ == $0
|
47
|
+
PauseBox.new.doit
|
48
|
+
end
|
data/samples/prgbox.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# muquit@muquit.com Apr-01-2014
|
4
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
class TestPrgBox1
|
8
|
+
ME = File.basename($0)
|
9
|
+
def initialize
|
10
|
+
end
|
11
|
+
|
12
|
+
def doit
|
13
|
+
dialog = MRDialog.new
|
14
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
15
|
+
dialog.clear = true
|
16
|
+
dialog.title = "PRGBOX"
|
17
|
+
|
18
|
+
path = File.expand_path(File.dirname(__FILE__))
|
19
|
+
command = path + "/shortlist"
|
20
|
+
height = 20
|
21
|
+
width = 70
|
22
|
+
dialog.prgbox(command, height, width)
|
23
|
+
|
24
|
+
|
25
|
+
text = "Hi, this is prgbox text"
|
26
|
+
command = path + "/shortlist 2"
|
27
|
+
dialog.prgbox(command, height, width, text)
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if __FILE__ == $0
|
33
|
+
TestPrgBox1.new.doit
|
34
|
+
end
|
data/samples/program.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Example for progressbox widget. It is similar to the
|
4
|
+
# one comes with dialog source code.
|
5
|
+
# muquit@muquit.com Apr-02-2014
|
6
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
7
|
+
begin
|
8
|
+
ME = File.basename($0)
|
9
|
+
text = "Hi, this is a gauge widget"
|
10
|
+
|
11
|
+
height = 20
|
12
|
+
width = 70
|
13
|
+
percent = 0
|
14
|
+
|
15
|
+
dialog = MRDialog.new
|
16
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
17
|
+
dialog.clear = true
|
18
|
+
dialog.title = "PROGRAMBOX"
|
19
|
+
|
20
|
+
|
21
|
+
description="Description of progress:"
|
22
|
+
dialog.programbox(description,height, width) do |f|
|
23
|
+
la = `/bin/ls -l1`.split("\n")
|
24
|
+
la.each do |l|
|
25
|
+
f.puts l
|
26
|
+
sleep 0.05
|
27
|
+
end
|
28
|
+
end
|
29
|
+
rescue => e
|
30
|
+
puts "#{$!}"
|
31
|
+
t = e.backtrace.join("\n\t")
|
32
|
+
puts "Error: #{t}"
|
33
|
+
end
|
data/samples/progress.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Example for progressbox widget. It is similar to the
|
4
|
+
# one comes with dialog source code.
|
5
|
+
# muquit@muquit.com Apr-02-2014
|
6
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
7
|
+
begin
|
8
|
+
ME = File.basename($0)
|
9
|
+
text = "Hi, this is a gauge widget"
|
10
|
+
|
11
|
+
height = 20
|
12
|
+
width = 70
|
13
|
+
percent = 0
|
14
|
+
|
15
|
+
dialog = MRDialog.new
|
16
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
17
|
+
dialog.clear = true
|
18
|
+
dialog.title = "PROGRESSBOX"
|
19
|
+
|
20
|
+
|
21
|
+
description="Description of progress:"
|
22
|
+
dialog.progressbox(description,height, width) do |f|
|
23
|
+
la = `/bin/ls -l1`.split("\n")
|
24
|
+
la.each do |l|
|
25
|
+
f.puts l
|
26
|
+
sleep 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
rescue => e
|
30
|
+
t = e.backtrace.join("\n")
|
31
|
+
puts "Error: #{t}"
|
32
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# muquit@muquit.com Apr-01-2014
|
4
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
class TestRadiolist
|
8
|
+
ME = File.basename($0)
|
9
|
+
def initialize
|
10
|
+
end
|
11
|
+
|
12
|
+
def doit
|
13
|
+
dialog = MRDialog.new
|
14
|
+
dialog.clear = true
|
15
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
16
|
+
|
17
|
+
text = <<EOF
|
18
|
+
This example is taken from dialog/samples/radiolist
|
19
|
+
shell script.
|
20
|
+
|
21
|
+
Hi, this is a radiolist box. You can use this to
|
22
|
+
present a list of choices which can be turned on or
|
23
|
+
off. If there are more items than can fit on the
|
24
|
+
screen, the list will be scrolled. You can use the
|
25
|
+
UP/DOWN arrow keys, the first letter of the choice as a
|
26
|
+
hot key, or the number keys 1-9 to choose an option.
|
27
|
+
Press SPACE to toggle an option on/off.
|
28
|
+
|
29
|
+
Which of the following are fruits?
|
30
|
+
|
31
|
+
EOF
|
32
|
+
items = []
|
33
|
+
radiolist_data = Struct.new(:tag, :item, :select)
|
34
|
+
|
35
|
+
data = radiolist_data.new
|
36
|
+
data.tag = "Apple"
|
37
|
+
data.item = "It's an applie"
|
38
|
+
data.select = false
|
39
|
+
items.push(data.to_a)
|
40
|
+
|
41
|
+
data = radiolist_data.new
|
42
|
+
data.tag = "Dog"
|
43
|
+
data.item = "No it's not my dog"
|
44
|
+
data.select = true
|
45
|
+
items.push(data.to_a)
|
46
|
+
|
47
|
+
data = radiolist_data.new
|
48
|
+
data.tag = "Orange"
|
49
|
+
data.item = "Yeah! it is juicy"
|
50
|
+
data.select = false
|
51
|
+
items.push(data.to_a)
|
52
|
+
|
53
|
+
selected_item = dialog.radiolist(text, items)
|
54
|
+
exit_code = dialog.exit_code
|
55
|
+
case exit_code
|
56
|
+
when dialog.dialog_ok
|
57
|
+
puts "OK Pressed"
|
58
|
+
when dialog.dialog_cancel
|
59
|
+
puts "Cancel Pressed"
|
60
|
+
when dialog.dialog_esc
|
61
|
+
puts "Escape Pressed"
|
62
|
+
end
|
63
|
+
|
64
|
+
puts "Selected item: #{selected_item}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
if __FILE__ == $0
|
69
|
+
TestRadiolist.new.doit
|
70
|
+
end
|
71
|
+
|
data/samples/shortlist
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
# $Id: shortlist,v 1.2 2011/03/02 00:11:50 tom Exp $
|
3
|
+
# make a short listing, which writes to both stdout and stderr.
|
4
|
+
|
5
|
+
if test $# != 0
|
6
|
+
then
|
7
|
+
count=$1
|
8
|
+
else
|
9
|
+
count=10
|
10
|
+
fi
|
11
|
+
|
12
|
+
while test $count != 0
|
13
|
+
do
|
14
|
+
echo "** $count -- `date`"
|
15
|
+
w >&2
|
16
|
+
sleep 1
|
17
|
+
count=`expr $count - 1 2>/dev/null`
|
18
|
+
test -z "$count" && count=0
|
19
|
+
done
|
data/samples/timebox.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# muquit@muquit.com Apr-01-2014
|
4
|
+
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
begin
|
8
|
+
ME = File.basename($0)
|
9
|
+
text = <<EOF
|
10
|
+
Please set the time...
|
11
|
+
EOF
|
12
|
+
|
13
|
+
h = 0
|
14
|
+
w = 0
|
15
|
+
t = Time.new
|
16
|
+
|
17
|
+
dialog = MRDialog.new
|
18
|
+
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
|
19
|
+
dialog.clear = true
|
20
|
+
dialog.title = "TIEMBOX"
|
21
|
+
|
22
|
+
# return Time
|
23
|
+
time = dialog.timebox(text, h, w, t)
|
24
|
+
|
25
|
+
puts "time: #{time}"
|
26
|
+
|
27
|
+
rescue => e
|
28
|
+
puts "#{$!}"
|
29
|
+
t = e.backtrace.join("\n\t")
|
30
|
+
puts "Error: #{t}"
|
31
|
+
end
|