palaver 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ Release notes for Palaver 0.3.0
2
+ ===============================
3
+
4
+ New features:
5
+
6
+ - Support for the "passwordform" dialog (github issue #16)
7
+ - Support foor the "gaugle" dialog (githus issue #5)
8
+ - Support for options affecting multiple dialogs types in the DialogFactory instead of the
9
+ individual dialog classes.
10
+ - Support for the following options has been implemented for all currently support dialog types:
11
+ - ascii-lines
12
+ - no-lines
13
+ - aspect
14
+ - backtitle
15
+ - begin
16
+ - cancel-label
17
+
18
+
19
+ Incompatabilities with previous versions:
20
+
21
+ - The PasswordBox class no longer accepts the 'insecure' option, which has been moved to the
22
+ DialogFactory. See examples/passwordbox.rb.
23
+
24
+
25
+ Release notes for Palaver 0.2.0
26
+ ===============================
27
+
28
+ Despite the version number, this was the first release of Palaver.
@@ -1,12 +1,14 @@
1
1
  require 'palaver'
2
2
  require 'date'
3
3
 
4
- dialog_factory = Palaver::DialogFactory.new
4
+ dialog_factory = Palaver::DialogFactory.new(:begin => [2,2],
5
+ :backtitle => "Defaults to a nasty period",
6
+ :cancel_label => "Forget it...")
5
7
 
6
8
  # Using the hash based API with the calendar dialog
7
9
  start_date = dialog_factory.calendar(:text => "Choose the start date", :date => Date.new(1939,9,1)).show
8
10
 
9
- # Using the block based API with the calendar dialog. This probably doesn'palaver'
11
+ # Using the block based API with the calendar dialog. This probably doesn't make sense for a
10
12
  # simple widget like the calendar.
11
13
  end_date = dialog_factory.calendar { text "Choose the end date"; date Date.new(1945,9,2); }.show
12
14
 
@@ -0,0 +1,24 @@
1
+ require 'palaver'
2
+
3
+ early_finish = ARGV[0] ? ARGV[0].to_i : nil
4
+
5
+ dialog_factory = Palaver::DialogFactory.new(:backtitle => "Waiting for progress")
6
+
7
+ gauge = dialog_factory.gauge {
8
+ text "Gauge, block style"
9
+ inital_percentage 22
10
+ }
11
+
12
+ gauge.show
13
+
14
+ (22..100).each do |p|
15
+ if p == early_finish then
16
+ gauge.close
17
+ break
18
+ end
19
+ sleep_duration = p > 98 ? 10 : 0.1
20
+ sleep sleep_duration
21
+ gauge.percentage(p)
22
+ end
23
+
24
+
@@ -1,16 +1,17 @@
1
1
  require 'palaver'
2
2
 
3
- dialog_factory = Palaver::DialogFactory.new
3
+ dialog_factory =
4
+ if ARGV[0] == "secure" then
5
+ Palaver::DialogFactory.new(:ascii_lines)
6
+ else
7
+ Palaver::DialogFactory.new(:insecure, :no_lines)
8
+ end
4
9
 
5
10
  # Using the hash based API to ask for a password
6
11
  hash_pw = dialog_factory.passwordbox(:text => "Please enter password, hash style").show
7
- hash_pw_insec = dialog_factory.passwordbox(:text => "Please enter password, more usable hash style", :insecure => true).show
8
12
  # Using the block based API to ask for a password
9
- block_pw = dialog_factory.passwordbox{ text "Please enter passwrod, block style" }.show
10
- block_pw_insec = dialog_factory.passwordbox{ insecure; text "Please enter passwrod, more usable block style" }.show
13
+ block_pw = dialog_factory.passwordbox{ text "Please enter password, block style" }.show
11
14
 
12
15
  puts "Hash password: #{hash_pw}"
13
- puts "Hash password (entered in less secure way): #{hash_pw_insec}"
14
16
  puts "Block password: #{block_pw}"
15
- puts "Block parssword (entered ien less secure way): #{block_pw_insec}"
16
17
 
@@ -0,0 +1,22 @@
1
+ require 'palaver'
2
+
3
+
4
+ dialog_factory =
5
+ if ARGV[0] == "secure" then
6
+ Palaver::DialogFactory.new
7
+ else
8
+ Palaver::DialogFactory.new(:insecure)
9
+ end
10
+
11
+ answers = dialog_factory.passwordform {
12
+ text "Foos and their secret texts"
13
+ height 10
14
+ form_height 5
15
+ entry :first, "First foo", 1, 0, "", 1, 15, 20, 200
16
+ entry :second, "Second foo", 1, 40, "", 1, 55, 20, 200
17
+ entry :third, "Third foo", 3, 0, "", 3, 15, 20, 200
18
+ }.show
19
+
20
+ answers.keys.each do |k|
21
+ puts "#{k}: #{answers[k]}"
22
+ end
@@ -1,6 +1,6 @@
1
1
  require 'palaver'
2
2
 
3
- dialog_factory = Palaver::DialogFactory.new
3
+ dialog_factory = Palaver::DialogFactory.new(:backtitle => "Yes/No questions R us", :aspect => 40)
4
4
 
5
5
  # Using the hash based API, which makes most sense for this kind of dialog
6
6
  likes_hash_based_api = dialog_factory.yesno(:text => "Do you like the hash based API?").show
@@ -15,4 +15,6 @@ require 'palaver/passwordbox.rb'
15
15
  require 'palaver/dselect.rb'
16
16
  require 'palaver/fselect.rb'
17
17
  require 'palaver/form.rb'
18
+ require 'palaver/passwordform.rb'
19
+ require 'palaver/gauge.rb'
18
20
  require 'palaver/dialog_factory.rb'
@@ -2,6 +2,8 @@
2
2
  # See LICENSE file for licensing information.
3
3
 
4
4
  module Palaver
5
+ attr_reader :common_options
6
+
5
7
  class Base
6
8
  def initialize(options)
7
9
  @text = nil
@@ -10,6 +12,7 @@ module Palaver
10
12
 
11
13
  options.each do |option,value|
12
14
  case option
15
+ when :common_options then @common_options = value
13
16
  when :width then self.width(value)
14
17
  when :height then self.height(value)
15
18
  when :text then self.text(value)
@@ -0,0 +1,96 @@
1
+ # Copyright (c) 2012, Peter Allin <peter@peca.dk> All rights reserved.
2
+ # See LICENSE file for licensing information.
3
+
4
+ module Palaver
5
+
6
+ class BaseForm < Palaver::Base
7
+ def initialize(dialogcmd, options)
8
+ super(options)
9
+ @dialogcmd = dialogcmd
10
+ @entries = []
11
+ @form_height = nil
12
+ @simple_display_width = nil
13
+ @simple_text_length = nil
14
+ end
15
+
16
+ def show
17
+ text_width = @entries.map { |e| e.text_width }.max
18
+ @entries.each { |e| e.update_value_x text_width }
19
+
20
+ cmd_intro = "dialog #@common_options --#@dialogcmd '#@text' #@height #@width #@form_height "
21
+ cmd_entries = @entries.map { |e| e.to_cmd_s }.join(' ')
22
+
23
+ result = nil
24
+ with_tempfile do |tfpath|
25
+ cmd = "#{cmd_intro} #{cmd_entries} 2> #{tfpath}"
26
+ success = system cmd
27
+ result = read_dialog_output tfpath
28
+ end
29
+
30
+ return result
31
+ end
32
+
33
+ private
34
+
35
+ class Entry
36
+ attr_reader :field_id, :text
37
+
38
+ def initialize(id, text, text_y, text_x, default_value, value_y, value_x, field_length, input_length)
39
+ @field_id = id
40
+ @text = text
41
+ @text_y = text_y
42
+ @text_x = text_x
43
+ @default_value = default_value
44
+ @value_y = value_y
45
+ @value_x = value_x
46
+ @field_length = field_length
47
+ @input_length = input_length
48
+ end
49
+
50
+ def text_width
51
+ @text.length + 2
52
+ end
53
+
54
+ def update_value_x(min)
55
+ @value_x = [ @value_x ? @value_x : 0, min ].max
56
+ end
57
+
58
+ def to_cmd_s
59
+ "'#@text' #@text_y #@text_x '#@default_value' #@value_y #@value_x #@field_length #@input_length"
60
+ end
61
+ end
62
+
63
+ def read_dialog_output(fname)
64
+ lines = File.read(fname).split("\n")
65
+ result = {}
66
+ lines.each_with_index { |l,i| result[@entries[i].field_id] = l }
67
+ return result
68
+ end
69
+
70
+ def form_height(val)
71
+ @form_height = val
72
+ end
73
+
74
+ def entry(id, title, text_y, text_x, default_value, value_y, value_x, field_length, input_length)
75
+ newentry = Entry.new(id, title, text_y, text_x, default_value, value_y, value_x, field_length, input_length)
76
+ @entries.push newentry
77
+ end
78
+
79
+ def simple_display_width(width)
80
+ @simple_display_width = width
81
+ end
82
+
83
+ def simple_text_length(length)
84
+ @simple_text_length = length
85
+ end
86
+
87
+ def simple_entry(id, title, default_value)
88
+ @simple_next_y = 1 if not @simple_next_y
89
+ newentry = Entry.new(id, title, @simple_next_y, 0, default_value, @simple_next_y, nil, @simple_display_width, @simple_text_length)
90
+ @entries.push newentry
91
+ @simple_next_y = @simple_next_y + 1
92
+ end
93
+
94
+ end
95
+
96
+ end
@@ -30,10 +30,10 @@ module Palaver
30
30
  end
31
31
  chosen_date = nil
32
32
  with_tempfile do |tfpath|
33
- cmd = 'dialog --calendar "%s" %d %d %d %d %d 2> %s' % [ @text,
34
- @height, @width,
35
- day, month, year,
36
- tfpath ]
33
+ cmd = "dialog #@common_options --calendar '%s' %d %d %d %d %d 2> %s" % [ @text,
34
+ @height, @width,
35
+ day, month, year,
36
+ tfpath ]
37
37
  success = system cmd
38
38
  chosen_date = Date.strptime(File.read(tfpath), "%d/%m/%Y") if success
39
39
  end
@@ -12,7 +12,7 @@ module Palaver
12
12
  def show
13
13
  choices = nil
14
14
  with_tempfile do |fname|
15
- cmd = "dialog --checklist '#@text' #@height #@width #@list_height #{options_string_with_status} 2> #{fname}"
15
+ cmd = "dialog #@common_options --checklist '#@text' #@height #@width #@list_height #{options_string_with_status} 2> #{fname}"
16
16
  success = system cmd
17
17
  if success then
18
18
  choices = File.read(fname).split(" ").map { |s| s[1..-2] }
@@ -17,15 +17,51 @@ module Palaver
17
17
  :passwordbox => PasswordBox,
18
18
  :dselect => DSelect,
19
19
  :fselect => FSelect,
20
- :form => Form
20
+ :form => Form,
21
+ :passwordform => PasswordForm,
22
+ :gauge => Gauge
21
23
  }
22
24
 
25
+ def initialize(*options)
26
+ options.each do |option|
27
+ case option
28
+ when :insecure then @insecure = true
29
+ when :ascii_lines then @ascii_lines = true
30
+ when :no_lines then @no_lines = true
31
+ end
32
+
33
+ if option.class == Hash then
34
+ option.each do |k,v|
35
+ case k
36
+ when :aspect then @aspect = v
37
+ when :backtitle then @backtitle = v
38
+ when :begin then @begin = v
39
+ when :cancel_label then @cancel_label = v
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def common_options
47
+ options = []
48
+ options.push("--insecure") if @insecure
49
+ options.push("--ascii-lines") if @ascii_lines
50
+ options.push("--no-lines") if @no_lines
51
+ options.push("--aspect #@aspect") if @aspect
52
+ options.push("--backtitle '#@backtitle'") if @backtitle
53
+ options.push("--begin #{@begin[0]} #{@begin[1]}") if @begin
54
+ options.push("--cancel-label '#@cancel_label'") if @cancel_label
55
+ return options.join(" ")
56
+ end
57
+
23
58
  private
24
59
 
25
60
  def method_missing(methodsym, *args, &block)
26
61
  if @@dialog_types.has_key? methodsym then
27
62
  c = @@dialog_types[methodsym]
28
63
  options = args.size == 1 ? args[0] : {}
64
+ options[:common_options] = common_options
29
65
  return make_dialog(c, options, &block)
30
66
  else
31
67
  raise NoMethodError.new("Undefined method: #{methodsym} for #{self}", methodsym)
@@ -1,95 +1,14 @@
1
1
  # Copyright (c) 2012, Peter Allin <peter@peca.dk> All rights reserved.
2
2
  # See LICENSE file for licensing information.
3
3
 
4
+ require 'palaver/baseform.rb'
5
+
4
6
  module Palaver
5
7
 
6
- class Form < Palaver::Base
8
+ class Form < Palaver::BaseForm
7
9
  def initialize(options)
8
- super(options)
9
- @entries = []
10
- @form_height = nil
11
- @simple_display_width = nil
12
- @simple_text_length = nil
13
- end
14
-
15
- def show
16
- text_width = @entries.map { |e| e.text_width }.max
17
- @entries.each { |e| e.update_value_x text_width }
18
-
19
- cmd_intro = "dialog --form '#@text' #@height #@width #@form_height "
20
- cmd_entries = @entries.map { |e| e.to_cmd_s }.join(' ')
21
-
22
- result = nil
23
- with_tempfile do |tfpath|
24
- cmd = "#{cmd_intro} #{cmd_entries} 2> #{tfpath}"
25
- success = system cmd
26
- result = read_dialog_output tfpath
27
- end
28
-
29
- return result
30
- end
31
-
32
- private
33
-
34
- class Entry
35
- attr_reader :field_id, :text
36
-
37
- def initialize(id, text, text_y, text_x, default_value, value_y, value_x, field_length, input_length)
38
- @field_id = id
39
- @text = text
40
- @text_y = text_y
41
- @text_x = text_x
42
- @default_value = default_value
43
- @value_y = value_y
44
- @value_x = value_x
45
- @field_length = field_length
46
- @input_length = input_length
47
- end
48
-
49
- def text_width
50
- @text.length + 2
51
- end
52
-
53
- def update_value_x(min)
54
- @value_x = [ @value_x ? @value_x : 0, min ].max
55
- end
56
-
57
- def to_cmd_s
58
- "'#@text' #@text_y #@text_x '#@default_value' #@value_y #@value_x #@field_length #@input_length"
59
- end
60
- end
61
-
62
- def read_dialog_output(fname)
63
- lines = File.read(fname).split("\n")
64
- result = {}
65
- lines.each_with_index { |l,i| result[@entries[i].field_id] = l }
66
- return result
10
+ super("form", options)
67
11
  end
68
-
69
- def form_height(val)
70
- @form_height = val
71
- end
72
-
73
- def entry(id, title, text_y, text_x, default_value, value_y, value_x, field_length, input_length)
74
- newentry = Entry.new(id, title, text_y, text_x, default_value, value_y, value_x, field_length, input_length)
75
- @entries.push newentry
76
- end
77
-
78
- def simple_display_width(width)
79
- @simple_display_width = width
80
- end
81
-
82
- def simple_text_length(length)
83
- @simple_text_length = length
84
- end
85
-
86
- def simple_entry(id, title, default_value)
87
- @simple_next_y = 1 if not @simple_next_y
88
- newentry = Entry.new(id, title, @simple_next_y, 0, default_value, @simple_next_y, nil, @simple_display_width, @simple_text_length)
89
- @entries.push newentry
90
- @simple_next_y = @simple_next_y + 1
91
- end
92
-
93
12
  end
94
13
 
95
14
  end
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2012, Peter Allin <peter@peca.dk> All rights reserved.
2
+ # See LICENSE file for licensing information.
3
+
4
+ module Palaver
5
+ class Gauge < Palaver::Base
6
+
7
+ def initialize(options)
8
+ @inital_percentage = 0
9
+ super(options)
10
+ end
11
+
12
+ def show
13
+ cmd = "dialog #@common_options --gauge '#@text' #@height #@width #@inital_percentage"
14
+ @pipe = IO.popen(cmd,"w")
15
+ end
16
+
17
+ def percentage(p)
18
+ if @pipe then
19
+ @pipe.puts p
20
+ else
21
+ @inital_percentage = p
22
+ end
23
+ end
24
+
25
+ def close
26
+ @pipe.close
27
+ end
28
+
29
+ private
30
+
31
+ def inital_percentage(percentage)
32
+ @inital_percentage = percentage
33
+ end
34
+ end
35
+ end
@@ -8,7 +8,7 @@ module Palaver
8
8
  end
9
9
 
10
10
  def show
11
- cmd = "dialog --infobox '#@text' #@height #@width"
11
+ cmd = "dialog #@common_options --infobox '#@text' #@height #@width"
12
12
  system cmd
13
13
  end
14
14
  end
@@ -22,7 +22,7 @@ module Palaver
22
22
  def show
23
23
  answer = nil
24
24
  with_tempfile do |fname|
25
- cmd = "dialog --inputbox '#@text' #@height #@width '#@initial' 2> #{fname}"
25
+ cmd = "dialog #@common_options --inputbox '#@text' #@height #@width '#@initial' 2> #{fname}"
26
26
  success = system cmd
27
27
  if success then
28
28
  answer = File.read(fname)
@@ -12,7 +12,7 @@ module Palaver
12
12
  def show
13
13
  chosen = nil
14
14
  with_tempfile do |fname|
15
- cmd = "dialog --menu '#@text' #@height #@width #@list_height #{options_string_no_status} 2> #{fname}"
15
+ cmd = "dialog #@common_options --menu '#@text' #@height #@width #@list_height #{options_string_no_status} 2> #{fname}"
16
16
  sucess = system cmd
17
17
  if sucess then
18
18
  chosen = File.read(fname)
@@ -8,7 +8,7 @@ module Palaver
8
8
  end
9
9
 
10
10
  def show
11
- cmd = "dialog --msgbox '#@text' #@height #@width"
11
+ cmd = "dialog #@common_options --msgbox '#@text' #@height #@width"
12
12
  system cmd
13
13
  end
14
14
  end
@@ -5,26 +5,12 @@ module Palaver
5
5
  class PasswordBox < Palaver::Base
6
6
  def initialize(options)
7
7
  super(options)
8
- @insecure = false
9
-
10
- options.each do |option,value|
11
- case option
12
- when :insecure then self.insecure(value)
13
- end
14
- end
15
- end
16
-
17
- def insecure(should_be_insecure=true)
18
- @insecure = should_be_insecure
19
8
  end
20
9
 
21
-
22
10
  def show
23
11
  answer = nil
24
12
  with_tempfile do |fname|
25
- insecure = @insecure ? "--insecure" : ""
26
- cmd = "dialog #{insecure} --passwordbox '#@text' #@height #@width 2> #{fname}"
27
- #puts cmd
13
+ cmd = "dialog #@common_options --passwordbox '#@text' #@height #@width 2> #{fname}"
28
14
  success = system cmd
29
15
  if success then
30
16
  answer = File.read(fname)
@@ -0,0 +1,10 @@
1
+ # Copyright (c) 2012, Peter Allin <peter@peca.dk> All rights reserved.
2
+ # See LICENSE file for licensing information.
3
+
4
+ module Palaver
5
+ class PasswordForm < Palaver::BaseForm
6
+ def initialize(options)
7
+ super("passwordform", options)
8
+ end
9
+ end
10
+ end
@@ -20,10 +20,10 @@ module Palaver
20
20
  end
21
21
 
22
22
  def show
23
- raise "CAn't open a #{dialog_name} dialog with a path" if not @path
23
+ raise "Can't open a #{dialog_name} dialog with a path" if not @path
24
24
  chosen_file = nil
25
25
  with_tempfile do |tfpath|
26
- cmd = "dialog --#{dialog_name} '#@path' #@height #@width 2> #{tfpath}"
26
+ cmd = "dialog #@common_options --#{dialog_name} '#@path' #@height #@width 2> #{tfpath}"
27
27
  puts cmd
28
28
  success = system cmd
29
29
  chosen_file = File.read(tfpath) if success
@@ -18,7 +18,7 @@ module Palaver
18
18
  end
19
19
 
20
20
  def show
21
- cmd = "dialog --pause '#@text' #@height #@width #@seconds"
21
+ cmd = "dialog #@common_options --pause '#@text' #@height #@width #@seconds"
22
22
  rc = system cmd
23
23
  return rc
24
24
  end
@@ -12,7 +12,7 @@ module Palaver
12
12
  def show
13
13
  chosen = nil
14
14
  with_tempfile do |fname|
15
- cmd = "dialog --radiolist '#@text' #@height #@width #@list_height #{options_string_with_status} 2> #{fname}"
15
+ cmd = "dialog #@common_options --radiolist '#@text' #@height #@width #@list_height #{options_string_with_status} 2> #{fname}"
16
16
  sucess = system cmd
17
17
  if sucess then
18
18
  chosen = File.read(fname)
@@ -13,7 +13,7 @@ module Palaver
13
13
  end
14
14
 
15
15
  def show
16
- cmd = "dialog --textbox '#@filename' #@height #@width"
16
+ cmd = "dialog #@common_options --textbox '#@filename' #@height #@width"
17
17
  system cmd
18
18
  end
19
19
 
@@ -8,7 +8,7 @@ module Palaver
8
8
  end
9
9
 
10
10
  def show
11
- cmd = "dialog --yesno '#@text' #@height #@width"
11
+ cmd = "dialog #@common_options --yesno '#@text' #@height #@width"
12
12
  rc = system cmd
13
13
  return rc
14
14
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "palaver"
3
- s.version = "0.2.0"
3
+ s.version = "0.3.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = [ "Peter Allin" ]
6
6
  s.email = [ "peter@peca.dk" ]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: palaver
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter Allin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-10 00:00:00 Z
18
+ date: 2012-09-23 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Uses the 'dialog' program to create Ruby applications with text based user interfaces
@@ -32,35 +32,41 @@ files:
32
32
  - LICENSE
33
33
  - README.md
34
34
  - Rakefile
35
+ - ReleaseNotes
35
36
  - examples/calendar.rb
36
37
  - examples/checklist.rb
37
38
  - examples/dselect.rb
38
39
  - examples/form.rb
39
40
  - examples/form_simple.rb
40
41
  - examples/fselect.rb
42
+ - examples/gauge.rb
41
43
  - examples/infobox.rb
42
44
  - examples/inputbox.rb
43
45
  - examples/menu.rb
44
46
  - examples/msgbox.rb
45
47
  - examples/passwordbox.rb
48
+ - examples/passwordform.rb
46
49
  - examples/pause.rb
47
50
  - examples/radiolist.rb
48
51
  - examples/textbox.rb
49
52
  - examples/yesno.rb
50
53
  - lib/palaver.rb
51
54
  - lib/palaver/base.rb
55
+ - lib/palaver/baseform.rb
52
56
  - lib/palaver/calendar.rb
53
57
  - lib/palaver/checklist.rb
54
58
  - lib/palaver/dialog_factory.rb
55
59
  - lib/palaver/dselect.rb
56
60
  - lib/palaver/form.rb
57
61
  - lib/palaver/fselect.rb
62
+ - lib/palaver/gauge.rb
58
63
  - lib/palaver/infobox.rb
59
64
  - lib/palaver/inputbox.rb
60
65
  - lib/palaver/list_with_options.rb
61
66
  - lib/palaver/menu.rb
62
67
  - lib/palaver/msgbox.rb
63
68
  - lib/palaver/passwordbox.rb
69
+ - lib/palaver/passwordform.rb
64
70
  - lib/palaver/pathselect.rb
65
71
  - lib/palaver/pause.rb
66
72
  - lib/palaver/radiolist.rb