annoy 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +6 -1
- data/annoy.gemspec +1 -1
- data/lib/annoy.rb +41 -2
- metadata +3 -3
data/CHANGES.txt
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
ANNOY, CHANGES
|
2
2
|
|
3
3
|
|
4
|
-
#### 0.5 (2009-
|
4
|
+
#### 0.5.1 (2009-06-03) ###############################
|
5
|
+
|
6
|
+
* ADDED: get_user_input method.
|
7
|
+
|
8
|
+
|
9
|
+
#### 0.5.0 (2009-05-07) ###############################
|
5
10
|
|
6
11
|
* First public release. See commit history for solutious-rudy.
|
7
12
|
|
data/annoy.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
@spec = Gem::Specification.new do |s|
|
2
2
|
s.name = "annoy"
|
3
3
|
s.rubyforge_project = "annoy"
|
4
|
-
s.version = "0.5.
|
4
|
+
s.version = "0.5.1"
|
5
5
|
s.summary = "Annoy: Like your annoying friend that asks you questions all the time."
|
6
6
|
s.description = s.summary
|
7
7
|
s.author = "Delano Mandelbaum"
|
data/lib/annoy.rb
CHANGED
@@ -198,8 +198,47 @@ class Annoy
|
|
198
198
|
false
|
199
199
|
end
|
200
200
|
end
|
201
|
-
|
202
|
-
|
201
|
+
|
202
|
+
# Get a response from the user. Returns the string as typed by the user
|
203
|
+
# with extraneous whitespace removed.
|
204
|
+
#
|
205
|
+
# * +msg+ (required) text to display to user
|
206
|
+
# * +echo+ (optional) character to display as user types. Used for hiding passwords.
|
207
|
+
# * +period+ (optional) amount of time to wait.
|
208
|
+
#
|
209
|
+
# NOTE: Annoy uses Highline to get user responses. If +msg+ ends with a space
|
210
|
+
# character, Highline will not print a new line. If there is no space character
|
211
|
+
# Highline will print a new line.
|
212
|
+
#
|
213
|
+
# Annoy.get_user_input("Password?") # => Password?
|
214
|
+
# # => 'user types here'
|
215
|
+
#
|
216
|
+
# Annoy.get_user_input("Password? ") # => Password? 'user types here'
|
217
|
+
#
|
218
|
+
def Annoy.get_user_input(msg, echo=nil, period=nil)
|
219
|
+
return unless STDIN.tty? # Only ask a question if there's a human
|
220
|
+
return if Annoy.skip?
|
221
|
+
response = nil
|
222
|
+
begin
|
223
|
+
success = Timeout::timeout(period || @@period) do
|
224
|
+
highline = HighLine.new
|
225
|
+
response = highline.ask(msg) { |q|
|
226
|
+
unless echo.nil?
|
227
|
+
q.overwrite = true # Erase the question afterwards
|
228
|
+
q.echo = echo # Don't display response
|
229
|
+
end
|
230
|
+
q.whitespace = :strip # Remove whitespace from the response
|
231
|
+
}
|
232
|
+
end
|
233
|
+
rescue Timeout::Error => ex
|
234
|
+
writer.puts $/, "Times up!"
|
235
|
+
end
|
236
|
+
response
|
237
|
+
end
|
238
|
+
|
239
|
+
# Display +msg+ for +period+ seconds.
|
240
|
+
# NOTE: +msg+ should be a short, single line. This is a naive approach which
|
241
|
+
# simply overwrites the current line.
|
203
242
|
def Annoy.timed_display(msg, writer, period=nil)
|
204
243
|
return true unless STDIN.tty? # Only ask a question if there's a human
|
205
244
|
if Annoy.skip?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: annoy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delano Mandelbaum
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-03 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
requirements: []
|
77
77
|
|
78
78
|
rubyforge_project: annoy
|
79
|
-
rubygems_version: 1.3.
|
79
|
+
rubygems_version: 1.3.3
|
80
80
|
signing_key:
|
81
81
|
specification_version: 2
|
82
82
|
summary: "Annoy: Like your annoying friend that asks you questions all the time."
|