rdialogy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/Manifest.txt +47 -0
- data/README.txt +60 -0
- data/Rakefile +19 -0
- data/examples/calendar.rb +5 -0
- data/examples/checklist.rb +8 -0
- data/examples/dselect.rb +5 -0
- data/examples/form.rb +11 -0
- data/examples/gauge.rb +17 -0
- data/examples/inputmenu.rb +9 -0
- data/examples/menu.rb +9 -0
- data/examples/message_box.rb +5 -0
- data/examples/mixedgauge.rb +21 -0
- data/examples/passwordbox.rb +0 -0
- data/lib/rdialogy/base.rb +67 -0
- data/lib/rdialogy/calendar.rb +46 -0
- data/lib/rdialogy/checklist.rb +56 -0
- data/lib/rdialogy/dselect.rb +39 -0
- data/lib/rdialogy/editbox.rb +31 -0
- data/lib/rdialogy/filepath_widget.rb +30 -0
- data/lib/rdialogy/form.rb +67 -0
- data/lib/rdialogy/form_field.rb +8 -0
- data/lib/rdialogy/fselect.rb +35 -0
- data/lib/rdialogy/gauge.rb +56 -0
- data/lib/rdialogy/infobox.rb +10 -0
- data/lib/rdialogy/inputbox.rb +16 -0
- data/lib/rdialogy/inputmenu.rb +41 -0
- data/lib/rdialogy/menu.rb +22 -0
- data/lib/rdialogy/menu_item.rb +2 -0
- data/lib/rdialogy/message_box.rb +10 -0
- data/lib/rdialogy/mixedgauge.rb +32 -0
- data/lib/rdialogy/passwordbox.rb +15 -0
- data/lib/rdialogy.rb +21 -0
- data/spec/base_spec.rb +30 -0
- data/spec/calendar_spec.rb +41 -0
- data/spec/checklist_spec.rb +41 -0
- data/spec/dselect_spec.rb +38 -0
- data/spec/form_spec.rb +47 -0
- data/spec/fselect_spec.rb +11 -0
- data/spec/infobox_spec.rb +18 -0
- data/spec/inputbox_spec.rb +30 -0
- data/spec/inputmenu_spec.rb +56 -0
- data/spec/menu_spec.rb +41 -0
- data/spec/message_box_spec.rb +18 -0
- data/spec/mixedgauge_spec.rb +0 -0
- data/spec/passwordbox_spec.rb +29 -0
- data/spec/spec_helper.rb +6 -0
- metadata +139 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
Rakefile
|
4
|
+
README.txt
|
5
|
+
examples/calendar.rb
|
6
|
+
examples/checklist.rb
|
7
|
+
examples/dselect.rb
|
8
|
+
examples/form.rb
|
9
|
+
examples/gauge.rb
|
10
|
+
examples/inputmenu.rb
|
11
|
+
examples/menu.rb
|
12
|
+
examples/message_box.rb
|
13
|
+
examples/mixedgauge.rb
|
14
|
+
examples/passwordbox.rb
|
15
|
+
lib/rdialogy/base.rb
|
16
|
+
lib/rdialogy/calendar.rb
|
17
|
+
lib/rdialogy/checklist.rb
|
18
|
+
lib/rdialogy/dselect.rb
|
19
|
+
lib/rdialogy/editbox.rb
|
20
|
+
lib/rdialogy/filepath_widget.rb
|
21
|
+
lib/rdialogy/form_field.rb
|
22
|
+
lib/rdialogy/form.rb
|
23
|
+
lib/rdialogy/fselect.rb
|
24
|
+
lib/rdialogy/gauge.rb
|
25
|
+
lib/rdialogy/infobox.rb
|
26
|
+
lib/rdialogy/inputbox.rb
|
27
|
+
lib/rdialogy/inputmenu.rb
|
28
|
+
lib/rdialogy/menu_item.rb
|
29
|
+
lib/rdialogy/menu.rb
|
30
|
+
lib/rdialogy/message_box.rb
|
31
|
+
lib/rdialogy/mixedgauge.rb
|
32
|
+
lib/rdialogy/passwordbox.rb
|
33
|
+
lib/rdialogy.rb
|
34
|
+
spec/base_spec.rb
|
35
|
+
spec/calendar_spec.rb
|
36
|
+
spec/checklist_spec.rb
|
37
|
+
spec/dselect_spec.rb
|
38
|
+
spec/form_spec.rb
|
39
|
+
spec/fselect_spec.rb
|
40
|
+
spec/infobox_spec.rb
|
41
|
+
spec/inputbox_spec.rb
|
42
|
+
spec/inputmenu_spec.rb
|
43
|
+
spec/menu_spec.rb
|
44
|
+
spec/message_box_spec.rb
|
45
|
+
spec/mixedgauge_spec.rb
|
46
|
+
spec/passwordbox_spec.rb
|
47
|
+
spec/spec_helper.rb
|
data/README.txt
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
= rdialogy
|
2
|
+
|
3
|
+
* http://rdialogy.rubyforge.com
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A wrapper for dialog
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Missing a bunch of stuff
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
MessageBox.run(:text => "Hello World!")
|
16
|
+
Calendar.run(:text => "Choose a date!", :month => 11, :day => 17)
|
17
|
+
Checklist.run(:text => "Select some stuff!", :items => %w(grapes lemons tomatos).map{|e| MenuItem.new(e, e)}).inspect
|
18
|
+
DSelect.run(:path => Dir.pwd)
|
19
|
+
|
20
|
+
== REQUIREMENTS:
|
21
|
+
|
22
|
+
* dialog
|
23
|
+
|
24
|
+
== INSTALL:
|
25
|
+
|
26
|
+
* gem install rdialogy
|
27
|
+
|
28
|
+
== DEVELOPERS:
|
29
|
+
|
30
|
+
After checking out the source, run:
|
31
|
+
|
32
|
+
$ rake newb
|
33
|
+
|
34
|
+
This task will install any missing dependencies, run the tests/specs,
|
35
|
+
and generate the RDoc.
|
36
|
+
|
37
|
+
== LICENSE:
|
38
|
+
|
39
|
+
(The MIT License)
|
40
|
+
|
41
|
+
Copyright (c) 2010
|
42
|
+
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
44
|
+
a copy of this software and associated documentation files (the
|
45
|
+
'Software'), to deal in the Software without restriction, including
|
46
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
47
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
48
|
+
permit persons to whom the Software is furnished to do so, subject to
|
49
|
+
the following conditions:
|
50
|
+
|
51
|
+
The above copyright notice and this permission notice shall be
|
52
|
+
included in all copies or substantial portions of the Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
55
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
56
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
57
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
58
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
59
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
60
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
Hoe.spec 'rdialogy' do
|
7
|
+
developer('Ross Paine', 'paine@bur.st')
|
8
|
+
|
9
|
+
# self.rubyforge_name = 'rdialogyx' # if different than 'rdialogy'
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Run all examples with RCov"
|
13
|
+
Spec::Rake::SpecTask.new('rcov') do |t|
|
14
|
+
t.spec_files = FileList['spec/*.rb']
|
15
|
+
t.rcov = true
|
16
|
+
t.rcov_opts = ['--exclude', 'examples', '-p']
|
17
|
+
end
|
18
|
+
|
19
|
+
# vim: syntax=ruby
|
data/examples/dselect.rb
ADDED
data/examples/form.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require [File.dirname(__FILE__), '..', 'lib', 'rdialogy'].join('/')
|
2
|
+
|
3
|
+
include RDialogy
|
4
|
+
|
5
|
+
puts Form.run(:text => "Enter some details",
|
6
|
+
:items =>
|
7
|
+
[
|
8
|
+
FormField.new('name', 1, 1, '', 1, 5, 10, 10),
|
9
|
+
FormField.new('age', 2, 1, '', 2, 5, 10, 10)
|
10
|
+
]
|
11
|
+
).inspect
|
data/examples/gauge.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require [File.dirname(__FILE__), '..', 'lib', 'rdialogy'].join('/')
|
2
|
+
|
3
|
+
include RDialogy
|
4
|
+
|
5
|
+
Gauge.run(:text => "Hi!", :width => 90) do |progress|
|
6
|
+
0.upto(50).each do |p|
|
7
|
+
progress.update p
|
8
|
+
sleep 0.01
|
9
|
+
end
|
10
|
+
|
11
|
+
progress.set_prompt(51, "Updating some other thing..")
|
12
|
+
|
13
|
+
51.upto(100).each do |p|
|
14
|
+
progress.update p
|
15
|
+
sleep 0.02
|
16
|
+
end
|
17
|
+
end
|
data/examples/menu.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require [File.dirname(__FILE__), '..', 'lib', 'rdialogy'].join('/')
|
2
|
+
|
3
|
+
include RDialogy
|
4
|
+
|
5
|
+
|
6
|
+
@p = 0
|
7
|
+
@all_tasks = [
|
8
|
+
'Updating the master baffle record',
|
9
|
+
'Inverting the Ukraine tupple',
|
10
|
+
'Restoring the donkey\'s fire mode'
|
11
|
+
]
|
12
|
+
|
13
|
+
@processed = []
|
14
|
+
|
15
|
+
@all_tasks.each do |tag|
|
16
|
+
this_item = MenuItem.new(tag, 'OK')
|
17
|
+
@processed << this_item
|
18
|
+
progress = (@processed.count / @all_tasks.count.to_f) * 100
|
19
|
+
MixedGauge.run(:text => "Working", :percent => progress, :items => @processed)
|
20
|
+
sleep 1
|
21
|
+
end
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module RDialogy
|
4
|
+
class Base
|
5
|
+
|
6
|
+
# assembles the arguments for dialog and executes them,
|
7
|
+
# if std_err is true STDERR is captured and returned, optionally formatted
|
8
|
+
# by supplied block.
|
9
|
+
|
10
|
+
def self.run(options={}, std_err = false)
|
11
|
+
cmd = dialog_string options
|
12
|
+
|
13
|
+
if std_err
|
14
|
+
begin
|
15
|
+
tmp = Tempfile.new('tmp')
|
16
|
+
cmd += ' 2> ' + tmp.path
|
17
|
+
|
18
|
+
system cmd
|
19
|
+
|
20
|
+
output = String.new
|
21
|
+
while true
|
22
|
+
output += tmp.readline
|
23
|
+
end
|
24
|
+
rescue EOFError
|
25
|
+
if block_given?
|
26
|
+
return yield output
|
27
|
+
else
|
28
|
+
return output
|
29
|
+
end
|
30
|
+
ensure
|
31
|
+
tmp.close
|
32
|
+
end
|
33
|
+
else
|
34
|
+
system cmd
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
# Template method to be overloaded in child classes
|
40
|
+
|
41
|
+
def self.command
|
42
|
+
raise "Template method called, must overload command in child class"
|
43
|
+
end
|
44
|
+
|
45
|
+
# expands the options out into the full dialog command string
|
46
|
+
|
47
|
+
def self.dialog_string(options={})
|
48
|
+
(['dialog', '--' + command] + add_quotes(args(options))).join ' '
|
49
|
+
end
|
50
|
+
# Returns a correctly ordered list from the input hash,
|
51
|
+
# also provides defaults for elements that are not supplied
|
52
|
+
|
53
|
+
def self.args(options={})
|
54
|
+
options[:text] ||= 'default title'
|
55
|
+
options[:height] ||= 0
|
56
|
+
options[:width] ||=0
|
57
|
+
|
58
|
+
[:text, :height, :width].map { |e| options[e] }
|
59
|
+
end
|
60
|
+
|
61
|
+
# Adds single quotes around all of the elements in the array returned by _args_
|
62
|
+
|
63
|
+
def self.add_quotes(args)
|
64
|
+
args.map{|e| "'#{e.to_s.gsub(/'/, "'\\\\''")}'"}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
|
3
|
+
module RDialogy
|
4
|
+
class Calendar < Base
|
5
|
+
|
6
|
+
# Valid options are:
|
7
|
+
# * :text - Title of widget
|
8
|
+
# * :width
|
9
|
+
# * :height
|
10
|
+
# * :year
|
11
|
+
# * :month
|
12
|
+
# * :day
|
13
|
+
#
|
14
|
+
# From the dialog man page:
|
15
|
+
# A calendar box displays month, day and year in separately adjustable windows. If the values for day, month
|
16
|
+
# or year are missing or negative, the current date's corresponding values are used. You can increment or
|
17
|
+
# decrement any of those using the left-, up-, right- and down-arrows. Use vi-style h, j, k and l for moving
|
18
|
+
# around the array of days in a month. Use tab or backtab to move between windows. If the year is given as
|
19
|
+
# zero, the current date is used as an initial value.
|
20
|
+
# On exit, the date is printed in the form day/month/year.
|
21
|
+
|
22
|
+
|
23
|
+
def self.run(options={})
|
24
|
+
super options, true do |input|
|
25
|
+
Time.mktime *input.chomp.split('/').reverse
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def self.args(options={})
|
32
|
+
options[:year] ||= -1
|
33
|
+
options[:month] ||= -1
|
34
|
+
options[:day] ||= -1
|
35
|
+
|
36
|
+
super + [:day, :month, :year].map{|e| options[e]}
|
37
|
+
end
|
38
|
+
|
39
|
+
# Maps to the appropriate dialog argument
|
40
|
+
|
41
|
+
def self.command
|
42
|
+
'calendar'
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
require File.dirname(__FILE__) + '/menu_item'
|
3
|
+
|
4
|
+
module RDialogy
|
5
|
+
class Checklist < Base
|
6
|
+
|
7
|
+
# Valid options are:
|
8
|
+
# * :text - Title of the widget
|
9
|
+
# * :width
|
10
|
+
# * :height
|
11
|
+
# * :list_height - Number of items to display in the list
|
12
|
+
# * :items - Array of MenuItem
|
13
|
+
#
|
14
|
+
# Returns <b>Array</b>
|
15
|
+
#
|
16
|
+
# From the man page:
|
17
|
+
#
|
18
|
+
# A checklist box is similar to a menu box; there are multiple entries presented in the form of a menu.
|
19
|
+
# Instead of choosing one entry among the entries, each entry can be turned on or off by the user. The initial
|
20
|
+
# on/off state of each entry is specified by status.
|
21
|
+
|
22
|
+
|
23
|
+
def self.run(options={})
|
24
|
+
super options, true do |input|
|
25
|
+
items = input.split(' ')
|
26
|
+
items.map{|e| e.scan(/^"(.*)"$/).flatten.first }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Formats the hash into an ordered list, valid options are:
|
33
|
+
# * :text - Title of the widget
|
34
|
+
# * :width
|
35
|
+
# * :height
|
36
|
+
# * :list_height - Number of items to display in the list
|
37
|
+
# * :items - Array of MenuItem
|
38
|
+
|
39
|
+
def self.args(options={})
|
40
|
+
options[:items] ||= []
|
41
|
+
options[:list_height] ||= options[:items].count
|
42
|
+
|
43
|
+
options[:items].map! do |item|
|
44
|
+
[item.tag, item.item, item.status ? 'on' : 'off']
|
45
|
+
end
|
46
|
+
|
47
|
+
super + [options[:list_height]] + options[:items].flatten
|
48
|
+
end
|
49
|
+
|
50
|
+
# Maps to the appropriate dialog argument
|
51
|
+
def self.command
|
52
|
+
'checklist'
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/filepath_widget'
|
2
|
+
|
3
|
+
module RDialogy
|
4
|
+
class DSelect < FilePathWidget
|
5
|
+
|
6
|
+
# Valid options are:
|
7
|
+
# * :path - Initial directory to display
|
8
|
+
# * :width
|
9
|
+
# * :height
|
10
|
+
# From the man page:
|
11
|
+
#
|
12
|
+
# The directory-selection dialog displays a text-entry window in which you can type a directory, and above
|
13
|
+
# that a windows with directory names.
|
14
|
+
#
|
15
|
+
# Here filepath can be a filepath in which case the directory window will display the contents of the path
|
16
|
+
# and the text-entry window will contain the preselected directory.
|
17
|
+
#
|
18
|
+
# Use tab or arrow keys to move between the windows. Within the directory window, use the up/down arrow keys
|
19
|
+
# to scroll the current selection. Use the space-bar to copy the current selection into the text-entry window.
|
20
|
+
#
|
21
|
+
# Typing any printable characters switches focus to the text-entry window, entering that character as well as
|
22
|
+
# scrolling the directory window to the closest match.
|
23
|
+
#
|
24
|
+
# Use a carriage return or the "OK" button to accept the current value in the text-entry window and exit.
|
25
|
+
|
26
|
+
|
27
|
+
def self.run(options={})
|
28
|
+
super options
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# Maps to the appropriate dialog argument
|
34
|
+
|
35
|
+
def self.command
|
36
|
+
'dselect'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/filepath_widget'
|
2
|
+
|
3
|
+
module RDialogy
|
4
|
+
class Editbox < FilePathWidget
|
5
|
+
|
6
|
+
# Valid options are:
|
7
|
+
# * :path - Path to file to display
|
8
|
+
# * :width
|
9
|
+
# * :height
|
10
|
+
#
|
11
|
+
# From the man page:
|
12
|
+
#
|
13
|
+
# The edit-box dialog displays a copy of the file. You may edit it using the backspace, delete and cursor
|
14
|
+
# keys to correct typing errors. It also recognizes pageup/pagedown. Unlike the --inputbox, you must tab to
|
15
|
+
# the "OK" or "Cancel" buttons to close the dialog. Pressing the "Enter" key within the box will split the
|
16
|
+
# corresponding line.
|
17
|
+
|
18
|
+
def self.run(options={})
|
19
|
+
super options
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Maps to the dialog argument
|
25
|
+
|
26
|
+
def self.command
|
27
|
+
'editbox'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
|
3
|
+
module RDialogy
|
4
|
+
class FilePathWidget < Base
|
5
|
+
# Valid options are:
|
6
|
+
# * :path - Initial directory to display
|
7
|
+
# * :width
|
8
|
+
# * :height
|
9
|
+
|
10
|
+
def self.run(options={})
|
11
|
+
super options, true
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# Maps the options hash to an ordered list, valid options are:
|
17
|
+
# * :path
|
18
|
+
# * :width
|
19
|
+
# * :height
|
20
|
+
|
21
|
+
def self.args(options={})
|
22
|
+
options[:path] ||= Dir.pwd
|
23
|
+
options[:width] ||= 0
|
24
|
+
options[:height] ||= 0
|
25
|
+
|
26
|
+
[:path, :height, :width].map{|e| options[e]}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
require File.dirname(__FILE__) + '/form_field'
|
3
|
+
|
4
|
+
module RDialogy
|
5
|
+
class Form < Base
|
6
|
+
# Valid options are:
|
7
|
+
# * :text - Title of the widget
|
8
|
+
# * :width
|
9
|
+
# * :height
|
10
|
+
# * :form_height - Number of items to display in the list
|
11
|
+
# * :items - Array of FormField
|
12
|
+
#
|
13
|
+
# Returns <b>Hash</b>
|
14
|
+
#
|
15
|
+
# From the man page
|
16
|
+
#
|
17
|
+
# The form dialog displays a form consisting of labels and fields, which are positioned on a scrollable window
|
18
|
+
# by coordinates given in the script. The field length flen and input-length ilen tell how long the
|
19
|
+
# field can be. The former defines the length shown for a selected field, while the latter defines the per‐
|
20
|
+
# missible length of the data entered in the field.
|
21
|
+
#
|
22
|
+
# - If flen is zero, the corresponding field cannot be altered. and the contents of the field determine the
|
23
|
+
# displayed-length.
|
24
|
+
#
|
25
|
+
# - If flen is negative, the corresponding field cannot be altered, and the negated value of flen is used as
|
26
|
+
# the displayed-length.
|
27
|
+
#
|
28
|
+
# - If ilen is zero, it is set to flen.
|
29
|
+
#
|
30
|
+
# Use up/down arrows (or control/N, control/P) to move between fields. Use tab to move between windows.
|
31
|
+
|
32
|
+
def self.run(options={})
|
33
|
+
keys = options[:items].map(&:label_text)
|
34
|
+
super options, true do |input|
|
35
|
+
result = Hash.new
|
36
|
+
input.split("\n").each do |item|
|
37
|
+
result[keys.shift] = item
|
38
|
+
end
|
39
|
+
result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def self.args(options={})
|
46
|
+
options[:items] ||= []
|
47
|
+
options[:form_height] ||= options[:items].count
|
48
|
+
options[:items].map! do |item|
|
49
|
+
[
|
50
|
+
:label_text, :label_x, :label_y,
|
51
|
+
:item_text, :item_x, :item_y,
|
52
|
+
:label_length, :item_length
|
53
|
+
].map do |m|
|
54
|
+
item.send(m)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
super + [options[:form_height]] + options[:items].flatten
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# Maps to the appropriate dialog argument
|
63
|
+
def self.command
|
64
|
+
'form'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/filepath_widget'
|
2
|
+
|
3
|
+
module RDialogy
|
4
|
+
class FSelect < FilePathWidget
|
5
|
+
|
6
|
+
# From the man page:
|
7
|
+
#
|
8
|
+
# The fselect (file-selection) dialog displays a text-entry window in which you can type a filename (or
|
9
|
+
# directory), and above that two windows with directory names and filenames.
|
10
|
+
#
|
11
|
+
# Here filepath can be a filepath in which case the file and directory windows will display the contents of
|
12
|
+
# the path and the text-entry window will contain the preselected filename.
|
13
|
+
#
|
14
|
+
# Use tab or arrow keys to move between the windows. Within the directory or filename windows, use the
|
15
|
+
# up/down arrow keys to scroll the current selection. Use the space-bar to copy the current selection into
|
16
|
+
# the text-entry window.
|
17
|
+
#
|
18
|
+
# Typing any printable characters switches focus to the text-entry window, entering that character as well as
|
19
|
+
# scrolling the directory and filename windows to the closest match.
|
20
|
+
#
|
21
|
+
# Typing the space character forces dialog to complete the current name (up to the point where there may be a
|
22
|
+
# match against more than one entry).
|
23
|
+
#
|
24
|
+
# Use a carriage return or the "OK" button to accept the current value in the text-entry window and exit.
|
25
|
+
|
26
|
+
def self.run(options={}); super options; end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def self.command
|
31
|
+
'fselect'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base'
|
2
|
+
|
3
|
+
module RDialogy
|
4
|
+
class Gauge < Base
|
5
|
+
# Valid options are:
|
6
|
+
# * :text
|
7
|
+
# * :width
|
8
|
+
# * :height
|
9
|
+
# * :percent - initial percentage, default 0
|
10
|
+
#
|
11
|
+
# From the man page:
|
12
|
+
# A gauge box displays a meter along the bottom of the box. The
|
13
|
+
# meter indicates the percentage.
|
14
|
+
# New percentages are read by calling
|
15
|
+
# .update(new percentage) inside the block supplied to run().
|
16
|
+
# Calling .set_prompt(percentage, new_prompt) inside the block sets
|
17
|
+
# a new prompt on the progress bar.
|
18
|
+
|
19
|
+
def self.run(options={})
|
20
|
+
begin
|
21
|
+
fifo = "/tmp/dialog_gauge.#{$$}"
|
22
|
+
system "mkfifo #{fifo}"
|
23
|
+
system "( #{dialog_string options} < #{fifo} ) &"
|
24
|
+
@@fifo = File.open fifo, 'w'
|
25
|
+
yield self
|
26
|
+
ensure
|
27
|
+
@@fifo.close
|
28
|
+
@@fifo = nil
|
29
|
+
system "rm #{fifo}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.command
|
34
|
+
'gauge'
|
35
|
+
end
|
36
|
+
|
37
|
+
# sends the new percentage to the running gauge
|
38
|
+
|
39
|
+
def self.update(percentage)
|
40
|
+
raise "Can't update gauge as it is not running." if @@fifo.nil?
|
41
|
+
@@fifo.puts percentage.to_i
|
42
|
+
@@fifo.flush
|
43
|
+
end
|
44
|
+
|
45
|
+
# sends the percentage to the running gauge and sets a new prompt
|
46
|
+
|
47
|
+
def self.set_prompt(percentage, new_prompt)
|
48
|
+
raise "Can't update gauge as it is not running." if @@fifo.nil?
|
49
|
+
@@fifo.puts "XXX"
|
50
|
+
@@fifo.puts percentage.to_i
|
51
|
+
@@fifo.puts new_prompt
|
52
|
+
@@fifo.puts "XXX"
|
53
|
+
@@fifo.flush
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|