prompter 0.1.1 → 0.1.2
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/README.rdoc +2 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/prompter.rb +16 -9
- data/prompter.gemspec +1 -1
- data/test/ask.irt +0 -4
- data/test/say.irt +0 -1
- metadata +9 -9
data/README.rdoc
CHANGED
@@ -43,7 +43,8 @@ Methods are callable directly on the Prompter class, on a Prompter object, inclu
|
|
43
43
|
|
44
44
|
Some methods yield the block with the returned value, so you can use them as an easy way to construct hierarchical wizards.
|
45
45
|
|
46
|
-
|
46
|
+
The Prompter.dye_styles keys are passable as the :style option to the called method and will override the default styles,
|
47
|
+
They can also be redefined by setting the Prompter.dye_styles. (see the 'dye' gem for more info)
|
47
48
|
|
48
49
|
== Documentation and Example
|
49
50
|
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ task :install, :force do |t, args|
|
|
20
20
|
File.open('VERSION', 'w') {|f| f.puts version }
|
21
21
|
gem_name = "#{name}-#{version}.gem"
|
22
22
|
sh %(gem build #{name}.gemspec)
|
23
|
-
sh %(gem install #{gem_name} --local)
|
23
|
+
sh %(gem install #{gem_name} --local --no-rdoc --no-ri)
|
24
24
|
puts <<-EOS.gsub(/^ {6}/, '')
|
25
25
|
|
26
26
|
*******************************************************************************
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/prompter.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'dye'
|
2
2
|
|
3
3
|
# @author Domizio Demichelis
|
4
4
|
#
|
@@ -6,12 +6,14 @@ class Prompter
|
|
6
6
|
|
7
7
|
VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
class << self ; attr_accessor :dye_styles ; end
|
10
|
+
|
11
|
+
@dye_styles = { :say_style => nil,
|
12
|
+
:say_echo_style => nil,
|
13
|
+
:say_notice_style => :yellow,
|
14
|
+
:say_warning_style => :red,
|
15
|
+
:ask_style => :magenta,
|
16
|
+
:hint_style => :green }
|
15
17
|
|
16
18
|
# Standard constructor, also accepts a block
|
17
19
|
#
|
@@ -19,6 +21,9 @@ class Prompter
|
|
19
21
|
# @option opts [String] :prefix The prefix string
|
20
22
|
# @option opts [Boolean] :echo when true adds a line with the result
|
21
23
|
#
|
24
|
+
# @yield yields the block with self
|
25
|
+
# @yieldparam [Prompter]
|
26
|
+
#
|
22
27
|
def initialize(opts={})
|
23
28
|
@prefix = opts[:prefix]
|
24
29
|
@echo = opts[:echo] || true
|
@@ -27,6 +32,8 @@ class Prompter
|
|
27
32
|
|
28
33
|
module Methods
|
29
34
|
|
35
|
+
define_dye_method Prompter.dye_styles
|
36
|
+
|
30
37
|
attr_writer :echo, :prefix
|
31
38
|
|
32
39
|
# The echo instance option (true by default)
|
@@ -47,7 +54,7 @@ class Prompter
|
|
47
54
|
# @option opts [String] :prefix The prefix string
|
48
55
|
# @option opts [Boolean] :echo Adds a line showing the input (=> input)
|
49
56
|
# @option opts [String] :hint A string to show the available choices
|
50
|
-
# @option opts [Symbol] :style The
|
57
|
+
# @option opts [Symbol] :style The Dye style name to use for this prompt
|
51
58
|
# @option opts [Boolean] :force_new_line Forces the addition of a new line (otherwise determined by the end of the prompt string)
|
52
59
|
#
|
53
60
|
def say(message="", opts={})
|
@@ -55,7 +62,7 @@ class Prompter
|
|
55
62
|
opts = { :force_new_line => (message !~ /( |\t)$/),
|
56
63
|
:style => :say_style,
|
57
64
|
:prefix => prefix }.merge opts
|
58
|
-
message = message
|
65
|
+
message = dye(message, *opts[:style]) unless opts[:style].nil?
|
59
66
|
message = (opts[:prefix]||'') + message
|
60
67
|
$stdout.send((opts[:force_new_line] ? :puts : :print), message)
|
61
68
|
$stdout.flush
|
data/prompter.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.summary = 'Makes your prompts easier to build and prettier to look'
|
11
11
|
s.description = 'A few helpers to create colored, multistep and hierarchical wizards'
|
12
12
|
|
13
|
-
s.add_runtime_dependency('
|
13
|
+
s.add_runtime_dependency('dye', [">= 0.1.1"])
|
14
14
|
s.add_runtime_dependency('yard', [">= 0.6.3"])
|
15
15
|
s.add_development_dependency('irt', [">= 1.0.9"])
|
16
16
|
|
data/test/ask.irt
CHANGED
@@ -5,7 +5,6 @@ say "You should see the next line in :ask_style"
|
|
5
5
|
ask "Please, write the word 'pippo':"
|
6
6
|
_eql?( "pippo" )
|
7
7
|
|
8
|
-
Colorer.def_basic_styles :red, true
|
9
8
|
desc "intaractive default ask"
|
10
9
|
say "You should see the next line in :red, and padded with 4 spaces"
|
11
10
|
ask "Please, type <enter>:", :default => 'default', :style => :red, :prefix => ' '
|
@@ -33,6 +32,3 @@ ml = ask_multiline "Add your data below...",
|
|
33
32
|
_eql?( ml )
|
34
33
|
say "<START-INPUT>#{ml}<END-INPUT>"
|
35
34
|
|
36
|
-
|
37
|
-
irt
|
38
|
-
|
data/test/say.irt
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prompter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Domizio Demichelis
|
@@ -15,23 +15,23 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01
|
18
|
+
date: 2011-02-01 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: dye
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 25
|
30
30
|
segments:
|
31
31
|
- 0
|
32
|
-
-
|
33
|
-
-
|
34
|
-
version: 0.
|
32
|
+
- 1
|
33
|
+
- 1
|
34
|
+
version: 0.1.1
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|