dialog 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +415 -0
- data/lib/base.rb +346 -0
- data/lib/calendar.rb +31 -0
- data/lib/checklist.rb +33 -0
- data/lib/dialog.rb +17 -0
- data/lib/form.rb +44 -0
- data/lib/fselect.rb +32 -0
- data/lib/gauge.rb +46 -0
- data/lib/infobox.rb +21 -0
- data/lib/inputbox.rb +26 -0
- data/lib/inputmenu.rb +22 -0
- data/lib/menu.rb +46 -0
- data/lib/msgbox.rb +19 -0
- data/lib/passwordbox.rb +20 -0
- data/lib/radiolist.rb +28 -0
- data/lib/tailbox.rb +20 -0
- data/lib/tailboxbg.rb +21 -0
- data/lib/textbox.rb +29 -0
- data/lib/timebox.rb +30 -0
- data/lib/util.rb +74 -0
- data/lib/yesno.rb +19 -0
- metadata +64 -0
data/lib/calendar.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'base'
|
2
|
+
|
3
|
+
module Dialog
|
4
|
+
|
5
|
+
# Displays a calendar.
|
6
|
+
#
|
7
|
+
# Corresponds to the --calendar box option. Use the date method to
|
8
|
+
# set the date being displayed.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# steps = Dialog::calendar do |m|
|
13
|
+
# m.text "Bla bla"
|
14
|
+
# m.date Date.today
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Box option syntax:
|
18
|
+
# --calendar <text> <height> <width> <day> <month> <year>
|
19
|
+
class Calendar < Base
|
20
|
+
|
21
|
+
# Sets the default date to display
|
22
|
+
def date(d)
|
23
|
+
if !d.kind_of?(Date)
|
24
|
+
d = ParseDate::parsedate(d)
|
25
|
+
end
|
26
|
+
@options.box_options[3..5] = [d.day, d.month, d.year]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/checklist.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'base'
|
2
|
+
require 'menu'
|
3
|
+
|
4
|
+
module Dialog
|
5
|
+
|
6
|
+
# Displays a checklist
|
7
|
+
#
|
8
|
+
# Corresponds to the --checklist box option. Use the choice method to
|
9
|
+
# define list items
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
#
|
13
|
+
# steps = Dialog::checklist do |m|
|
14
|
+
# m.text "Bla bla"
|
15
|
+
# m.choice "/dev/hda1", "Backup partition /dev/hda1 using partimage", :on
|
16
|
+
# m.choice "/dev/hda2", "Backup partition /dev/hda2 using dd", :off
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Box option syntax:
|
20
|
+
# --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...
|
21
|
+
#
|
22
|
+
class Checklist < Menu
|
23
|
+
|
24
|
+
# Adds a choice to the checklist
|
25
|
+
def choice(tag, item, status=:on, help=nil)
|
26
|
+
choice = [tag, item, status.to_s]
|
27
|
+
choice << help unless help.nil?
|
28
|
+
@choices << choice
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/dialog.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'calendar'
|
2
|
+
require 'checklist'
|
3
|
+
require 'form'
|
4
|
+
require 'fselect'
|
5
|
+
require 'gauge'
|
6
|
+
require 'infobox'
|
7
|
+
require 'inputbox'
|
8
|
+
require 'inputmenu'
|
9
|
+
require 'menu'
|
10
|
+
require 'msgbox'
|
11
|
+
require 'passwordbox'
|
12
|
+
require 'radiolist'
|
13
|
+
require 'tailbox'
|
14
|
+
require 'tailboxbg'
|
15
|
+
require 'textbox'
|
16
|
+
require 'timebox'
|
17
|
+
require 'yesno'
|
data/lib/form.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'base'
|
2
|
+
|
3
|
+
module Dialog
|
4
|
+
|
5
|
+
# Displays a form
|
6
|
+
#
|
7
|
+
# Corresponds to the --form box option. Use the field method to
|
8
|
+
# define form fields
|
9
|
+
#
|
10
|
+
# Example (TODO)
|
11
|
+
#
|
12
|
+
# steps = Dialog::form do |m|
|
13
|
+
# m.text "Bla bla"
|
14
|
+
# m.field "/dev/hda1", "Backup partition /dev/hda1 using partimage", :on
|
15
|
+
# m.field "/dev/hda2", "Backup partition /dev/hda2 using dd", :off
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# Box option syntax:
|
19
|
+
# --form <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>...
|
20
|
+
#
|
21
|
+
class Form < Base
|
22
|
+
|
23
|
+
def initialize(*options)
|
24
|
+
@fields = []
|
25
|
+
super *options
|
26
|
+
@options.box_options[3] ||= 0 # Default form-height
|
27
|
+
end
|
28
|
+
|
29
|
+
# Adds a field to the form
|
30
|
+
def field(label, ly, lx, item, iy, ix, flen=30, ilen=0)
|
31
|
+
@fields << [label, ly, lx, item, iy, ix, flen, ilen]
|
32
|
+
end
|
33
|
+
|
34
|
+
def box_options
|
35
|
+
super + @fields.flatten
|
36
|
+
end
|
37
|
+
|
38
|
+
def form_height(v)
|
39
|
+
@options.box_options[3] = v
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/fselect.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'base'
|
2
|
+
|
3
|
+
module Dialog
|
4
|
+
|
5
|
+
# Displays a file selection box.
|
6
|
+
#
|
7
|
+
# Corresponds to the --fselect box option. Use the file method
|
8
|
+
# to set the file to be displayed.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# steps = Dialog::fselect do |m|
|
13
|
+
# m.text "Select a device!"
|
14
|
+
# m.file "/dev/null"
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Box option syntax:
|
18
|
+
# --fselect <filepath> <height> <width>
|
19
|
+
#
|
20
|
+
class FSelect < Base
|
21
|
+
|
22
|
+
# Sets the default file to display
|
23
|
+
def file(f)
|
24
|
+
@options.box_options[0] = case f
|
25
|
+
when File: f.path
|
26
|
+
else f.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/gauge.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'base'
|
2
|
+
|
3
|
+
module Dialog
|
4
|
+
|
5
|
+
# Displays a gauge.
|
6
|
+
#
|
7
|
+
# Corresponds to the --gauge box option. Use the complete method
|
8
|
+
# to set the initially completed part of the gauge. TODO How do
|
9
|
+
# we update the gauge??
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
#
|
13
|
+
# steps = Dialog::gauge do |m|
|
14
|
+
# m.text "Please wait"
|
15
|
+
# m.complete 30 # 30% complete, 0.3 works as well
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# Box option syntax:
|
19
|
+
# --gauge <text> <height> <width> [<percent>]
|
20
|
+
#
|
21
|
+
class Gauge < Base
|
22
|
+
|
23
|
+
# Sets the value to display
|
24
|
+
def complete(p)
|
25
|
+
@completed = case p
|
26
|
+
when Fixnum: p
|
27
|
+
when Bignum: p
|
28
|
+
when Float: (p*100).to_i
|
29
|
+
else p
|
30
|
+
end
|
31
|
+
@stdin.puts @completed if @stdin
|
32
|
+
end
|
33
|
+
|
34
|
+
def arguments
|
35
|
+
super << @completed || 0
|
36
|
+
end
|
37
|
+
|
38
|
+
# Make sure wait returns by closing stdin
|
39
|
+
def wait
|
40
|
+
@stdin.close if @stdin
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/lib/infobox.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'base'
|
2
|
+
|
3
|
+
module Dialog
|
4
|
+
|
5
|
+
# Displays an infobox.
|
6
|
+
#
|
7
|
+
# Corresponds to the --infobox box option.
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
#
|
11
|
+
# steps = Dialog::infobox do |b|
|
12
|
+
# b.text "Bla bla"
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# Box option syntax:
|
16
|
+
# --infobox <text> <height> <width>
|
17
|
+
#
|
18
|
+
class Infobox < Base
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/inputbox.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'base'
|
2
|
+
|
3
|
+
module Dialog
|
4
|
+
|
5
|
+
# Displays an inputbox.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
#
|
9
|
+
# steps = Dialog::inputbox do |b|
|
10
|
+
# b.text "Bla bla"
|
11
|
+
# b.value "Initial input"
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# Box option syntax:
|
15
|
+
# --inputbox <text> <height> <width> [<init>]
|
16
|
+
#
|
17
|
+
class Inputbox < Base
|
18
|
+
|
19
|
+
# Sets the intial value for the input box
|
20
|
+
def value(s)
|
21
|
+
@options.box_options[3] = s
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/inputmenu.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'base'
|
2
|
+
require 'menu'
|
3
|
+
|
4
|
+
module Dialog
|
5
|
+
|
6
|
+
# Displays an inputmenu.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# Inputmenu.new do |b|
|
11
|
+
# b.text "Bla bla"
|
12
|
+
# m.choice "/dev/hda1", "Backup partition /dev/hda1 using partimage"
|
13
|
+
# m.choice "/dev/hda2", "Backup partition /dev/hda2 using dd"
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Box option syntax:
|
17
|
+
# --inputmenu <text> <height> <width> <menu height> <tag1> <item1>...
|
18
|
+
#
|
19
|
+
class Inputmenu < Menu
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/menu.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'base'
|
2
|
+
|
3
|
+
module Dialog
|
4
|
+
|
5
|
+
# Displays a menu.
|
6
|
+
#
|
7
|
+
# Corresponds to the --menu box option. Use the choice method to
|
8
|
+
# create menu items.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# steps = Dialog::menu do |m|
|
13
|
+
# m.text "Bla bla"
|
14
|
+
# m.choice "/dev/hda1", "Backup partition /dev/hda1 using partimage"
|
15
|
+
# m.choice "/dev/hda2", "Backup partition /dev/hda2 using dd"
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# Box option syntax:
|
19
|
+
# --menu <text> <height> <width> <menu height> <tag1> <item1>...
|
20
|
+
#
|
21
|
+
class Menu < Base
|
22
|
+
|
23
|
+
def initialize(*options)
|
24
|
+
@choices = []
|
25
|
+
super *options
|
26
|
+
@options.box_options[3] ||= 0 # Default menu-height
|
27
|
+
end
|
28
|
+
|
29
|
+
# Adds a choice to the menu
|
30
|
+
def choice(tag, item, help=nil)
|
31
|
+
choice = [tag, item]
|
32
|
+
choice << help unless help.nil?
|
33
|
+
@choices << choice
|
34
|
+
end
|
35
|
+
|
36
|
+
def box_options
|
37
|
+
super + @choices.flatten
|
38
|
+
end
|
39
|
+
|
40
|
+
def menu_height(v)
|
41
|
+
@options.box_options[3] = v
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/lib/msgbox.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'base'
|
2
|
+
|
3
|
+
module Dialog
|
4
|
+
|
5
|
+
# Displays a msgbox.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
#
|
9
|
+
# steps = Msgbox.new do |b|
|
10
|
+
# b.text "Bla bla"
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# Box option syntax:
|
14
|
+
# --msgbox <text> <height> <width>
|
15
|
+
#
|
16
|
+
class Msgbox < Base
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/passwordbox.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'base'
|
2
|
+
|
3
|
+
module Dialog
|
4
|
+
|
5
|
+
# Displays a passwordbox.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
#
|
9
|
+
# Passwordbox.new do |b|
|
10
|
+
# b.text "Speak friend and enter"
|
11
|
+
# b.value "Mellon"
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# Box option syntax:
|
15
|
+
# --passwordbox <text> <height> <width> [<init>]
|
16
|
+
#
|
17
|
+
class Passwordbox < Inputbox
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/radiolist.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'base'
|
2
|
+
require 'checklist'
|
3
|
+
|
4
|
+
module Dialog
|
5
|
+
|
6
|
+
# Displays a radiolist
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# Radiolist.new do |m|
|
11
|
+
# m.text "Bla bla"
|
12
|
+
# m.choice "/dev/hda1", "Backup partition /dev/hda1 using partimage", :on
|
13
|
+
# m.choice "/dev/hda2", "Backup partition /dev/hda2 using dd"
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Box option syntax:
|
17
|
+
# --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...
|
18
|
+
#
|
19
|
+
class Radiolist < Checklist
|
20
|
+
|
21
|
+
# Adds a choice to the list
|
22
|
+
def choice(tag, item, status=:off, help=nil)
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/tailbox.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'base'
|
2
|
+
require 'textbox'
|
3
|
+
|
4
|
+
module Dialog
|
5
|
+
|
6
|
+
# Displays a tailbox.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# Tailbox.new do |b|
|
11
|
+
# b.text "Bla bla"
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# Box option syntax:
|
15
|
+
# --tailbox <file> <height> <width>
|
16
|
+
#
|
17
|
+
class Tailbox < Textbox
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/tailboxbg.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'base'
|
2
|
+
require 'textbox'
|
3
|
+
|
4
|
+
module Dialog
|
5
|
+
|
6
|
+
# Displays a tailbox in the background.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# Tailboxbg.new do |b|
|
11
|
+
# b.text "Bla bla"
|
12
|
+
# b.file "/var/log/messages"
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# Box option syntax:
|
16
|
+
# --tailboxbg <file> <height> <width>
|
17
|
+
#
|
18
|
+
class Tailboxbg < Textbox
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|