fancy_gets 0.1.5 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +20 -0
- data/fancy_gets.gemspec +1 -1
- data/lib/fancy_gets.rb +126 -81
- data/lib/fancy_gets/version.rb +1 -1
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51c96b67bf9c4b86e5a928042a1ef0923d720cedc3e75dc659bd58910c284e8c
|
4
|
+
data.tar.gz: 222b64256299e56e23c0829b2fb7a855d6d4f38cd158926040d661deb0121583
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 573430996f606e869215ceb26ed019753192d9344d5c182027e22a9b9b09167eedc8938d994a0cdfbc64f8e3f6f1c9d4c57ff6eb1dc50d216632270c79ad78da
|
7
|
+
data.tar.gz: ece58b484fcf7fbf88c16f94d00a3868743c9218f5b0069cb9eaf12fb29d252aa0259945e3e8cf61641053a033829918d99be835a0c499336e73887dc5fd038e
|
data/README.md
CHANGED
@@ -75,6 +75,26 @@ picked_toys = gets_list(toys, true, ["Kite", "Water Gun"])
|
|
75
75
|
puts "\nYou've picked #{picked_toys.join(", ")}."
|
76
76
|
```
|
77
77
|
|
78
|
+
You can also pass in parameters as a hash, which brings even more possibility because you can pass in callbacks! Here's how to dynamically update the info line at the bottom to indicate how many things have been chosen so far:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
picked_toys = gets_list(
|
82
|
+
list: toys,
|
83
|
+
is_multiple: true,
|
84
|
+
chosen: [],
|
85
|
+
prefix: "\033[1;32m>\033[1;35m> \033[0m",
|
86
|
+
postfix: "\033[1;35m <\033[1;32m<\033[0m",
|
87
|
+
height: 4,
|
88
|
+
on_change: proc{ |data|
|
89
|
+
"You have chosen #{data[:chosen].count} items"
|
90
|
+
}
|
91
|
+
)
|
92
|
+
puts "\nAren't callbacks cool?"
|
93
|
+
```
|
94
|
+
|
95
|
+
You can also set a callback for on_select, which responds when people are arrowing around through the list. With the blocks in both on_change and on_select if a string is returned, it will update what is shown in the info line at the bottom.
|
96
|
+
|
97
|
+
|
78
98
|
## gets_auto_suggest
|
79
99
|
|
80
100
|
Still using the same cool array of things, let's have the user see auto-suggest text
|
data/fancy_gets.gemspec
CHANGED
@@ -35,6 +35,6 @@ It's all here. Enjoy!}
|
|
35
35
|
spec.require_paths = ["lib"]
|
36
36
|
|
37
37
|
spec.add_development_dependency "bundler", "~> 1.12"
|
38
|
-
spec.add_development_dependency "rake", "~>
|
38
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
39
39
|
spec.add_development_dependency "rspec", "~> 3.0"
|
40
40
|
end
|
data/lib/fancy_gets.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative "fancy_gets/version"
|
2
2
|
require 'io/console'
|
3
3
|
|
4
4
|
module FancyGets
|
@@ -26,7 +26,7 @@ module FancyGets
|
|
26
26
|
words = words[:list]
|
27
27
|
else
|
28
28
|
# Trying to supply parameters but left out a "true" for is_multiple?
|
29
|
-
if is_multiple.is_a?(Enumerable) || is_multiple.is_a?(String) || is_multiple.is_a?(
|
29
|
+
if is_multiple.is_a?(Enumerable) || is_multiple.is_a?(String) || is_multiple.is_a?(Numeric)
|
30
30
|
chosen = is_multiple
|
31
31
|
is_multiple = false
|
32
32
|
end
|
@@ -40,10 +40,10 @@ module FancyGets
|
|
40
40
|
def self.gets_internal_core(is_list, is_password, word_objects = nil, chosen = nil, prefix = "> ", postfix = " <", info = nil, height = nil, on_change = nil, on_select = nil)
|
41
41
|
# OK -- second parameter, is_password, means is_multiple when is_list is true
|
42
42
|
is_multiple = is_list & is_password
|
43
|
-
|
43
|
+
if word_objects && !is_list
|
44
44
|
word_objects.sort! {|wo1, wo2| wo1.to_s <=> wo2.to_s}
|
45
45
|
end
|
46
|
-
words = word_objects
|
46
|
+
words = word_objects&.map(&:to_s) || []
|
47
47
|
if is_multiple
|
48
48
|
chosen ||= [0] unless is_multiple
|
49
49
|
else
|
@@ -55,10 +55,12 @@ module FancyGets
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
position = 0
|
58
|
-
|
59
|
-
|
58
|
+
# Up and down arrows break with height of 3 or less
|
59
|
+
height = words.length unless height&.is_a?(Numeric) && height >= 4
|
60
|
+
winheight = (IO.console || STDOUT).winsize.first - 3
|
61
|
+
height = words.length if height > words.length
|
60
62
|
height = winheight if height > winheight
|
61
|
-
offset =
|
63
|
+
offset = 0
|
62
64
|
sugg = ""
|
63
65
|
prev_sugg = ""
|
64
66
|
|
@@ -79,12 +81,14 @@ module FancyGets
|
|
79
81
|
" - #{sugg}#{" " * extra_spaces} #{"\b" * ((uncolor.call(sugg).length + 4 + extra_spaces) + string.length - position)}"
|
80
82
|
end
|
81
83
|
|
82
|
-
|
84
|
+
pre_length = uncolor.call(prefix).length
|
85
|
+
post_length = uncolor.call(postfix).length
|
86
|
+
pre_post_length = pre_length + post_length
|
83
87
|
|
84
88
|
# Used for dropdown select / deselect
|
85
89
|
clear_dropdown_info = lambda do
|
86
90
|
print "\b" * (uncolor.call(words[position]).length + pre_post_length)
|
87
|
-
print (27.chr + 91.chr + 66.chr) * (height
|
91
|
+
print (27.chr + 91.chr + 66.chr) * ((height + offset) - position)
|
88
92
|
info_length = uncolor.call(info).length
|
89
93
|
print " " * info_length + "\b" * info_length
|
90
94
|
end
|
@@ -94,7 +98,7 @@ module FancyGets
|
|
94
98
|
if is_select
|
95
99
|
print "#{prefix}#{word}#{postfix}"
|
96
100
|
else
|
97
|
-
print "#{" " *
|
101
|
+
print "#{" " * pre_length}#{word}#{" " * post_length}"
|
98
102
|
end
|
99
103
|
print " " * (max_word_length - uncolor.call(words[position]).length)
|
100
104
|
print "\b" * (max_word_length - uncolor.call(words[position]).length)
|
@@ -105,11 +109,12 @@ module FancyGets
|
|
105
109
|
# Put the response into the info line, as long as it's short enough!
|
106
110
|
new_info.gsub!("\n", " ")
|
107
111
|
new_info_length = uncolor.call(new_info).length
|
108
|
-
console_width = IO.console.winsize.last
|
112
|
+
console_width = (IO.console || STDOUT).winsize.last
|
109
113
|
# Might have to trim if it's a little too wide
|
110
114
|
new_info = new_info[0...console_width] if console_width < new_info_length
|
111
115
|
# Arrow down to the info line
|
112
|
-
|
116
|
+
distance_down = (height + offset) - position
|
117
|
+
print (27.chr + 91.chr + 66.chr) * distance_down
|
113
118
|
# To start of info line
|
114
119
|
word_length = uncolor.call(words[position]).length + pre_post_length
|
115
120
|
print "\b" * word_length
|
@@ -120,15 +125,15 @@ module FancyGets
|
|
120
125
|
print new_info + " " * difference
|
121
126
|
info = new_info
|
122
127
|
# Go up to where we originated
|
123
|
-
print (27.chr + 91.chr + 65.chr) *
|
128
|
+
print (27.chr + 91.chr + 65.chr) * distance_down
|
124
129
|
# Arrow left or right to get to the right spot again
|
125
130
|
new_info_length += difference
|
126
131
|
print (new_info_length > word_length ? "\b" : (27.chr + 91.chr + 67.chr)) * (new_info_length - word_length).abs
|
127
132
|
end
|
128
133
|
|
129
|
-
handle_on_select = lambda do |
|
134
|
+
handle_on_select = lambda do |selected|
|
130
135
|
if on_select.is_a? Proc
|
131
|
-
response = on_select.call({chosen: chosen,
|
136
|
+
response = on_select.call({chosen: chosen, selected: selected})
|
132
137
|
new_info = nil
|
133
138
|
if response.is_a? Hash
|
134
139
|
chosen = response[:chosen] || chosen
|
@@ -136,25 +141,30 @@ module FancyGets
|
|
136
141
|
elsif response.is_a? String
|
137
142
|
new_info = response
|
138
143
|
end
|
139
|
-
|
140
|
-
write_info.call(new_info)
|
141
|
-
end
|
144
|
+
write_info.call(new_info) if new_info
|
142
145
|
end
|
143
146
|
end
|
144
147
|
|
148
|
+
# **********************************************
|
149
|
+
# ******************** DOWN ********************
|
150
|
+
# Doesn't work with a height of 3 when there's more than 3 in the list
|
145
151
|
arrow_down = lambda do
|
146
152
|
if position < words.length - 1
|
147
|
-
handle_on_select.call(word_objects[position + 1])
|
148
153
|
is_shift = false
|
154
|
+
handle_on_select.call(word_objects[position + 1])
|
149
155
|
# Now moving down past the bottom of the shown window?
|
150
|
-
|
156
|
+
is_before_end = height + offset < words.length
|
157
|
+
if is_before_end && position == (height - 2) + offset
|
151
158
|
print "\b" * (uncolor.call(words[position]).length + pre_post_length)
|
152
|
-
print (27.chr + 91.chr + 65.chr) * (height -
|
159
|
+
print (27.chr + 91.chr + 65.chr) * (height - 3)
|
160
|
+
if offset == 0
|
161
|
+
print (27.chr + 91.chr + 65.chr)
|
162
|
+
puts "#{" " * pre_length}#{"↑" * max_word_length}#{" " * post_length}"
|
163
|
+
end
|
153
164
|
offset += 1
|
154
|
-
|
155
|
-
(offset...(offset + height - 4)).each do |i|
|
165
|
+
((offset + 1)..(offset + (height - 4))).each do |i|
|
156
166
|
end_fill = max_word_length - uncolor.call(words[i]).length
|
157
|
-
puts (is_multiple && chosen.include?(i)) ? "#{prefix}#{words[i]}#{postfix}#{" " * end_fill}" : "#{" " *
|
167
|
+
puts (is_multiple && chosen.include?(i)) ? "#{prefix}#{words[i]}#{postfix}#{" " * end_fill}" : "#{" " * pre_length}#{words[i]}#{" " * (end_fill + post_length)}"
|
158
168
|
end
|
159
169
|
is_shift = true
|
160
170
|
end
|
@@ -163,6 +173,13 @@ module FancyGets
|
|
163
173
|
position += 1
|
164
174
|
print 27.chr + 91.chr + 66.chr
|
165
175
|
if is_shift || !is_multiple
|
176
|
+
if is_shift && height + offset == words.length # Go down and write the last one
|
177
|
+
print 27.chr + 91.chr + 66.chr
|
178
|
+
position += 1
|
179
|
+
make_select.call(is_shift && chosen.include?(position), false, true)
|
180
|
+
print 27.chr + 91.chr + 65.chr # And back up
|
181
|
+
position -= 1
|
182
|
+
end
|
166
183
|
make_select.call((chosen.include?(position) && is_shift) || !is_multiple)
|
167
184
|
else
|
168
185
|
w2 = uncolor.call(words[position]).length
|
@@ -171,28 +188,42 @@ module FancyGets
|
|
171
188
|
end
|
172
189
|
end
|
173
190
|
|
191
|
+
# **********************************************
|
192
|
+
# ********************** UP ********************
|
174
193
|
arrow_up = lambda do
|
175
194
|
if position > 0
|
176
|
-
handle_on_select.call(word_objects[position - 1])
|
177
195
|
is_shift = false
|
196
|
+
handle_on_select.call(word_objects[position - 1])
|
178
197
|
# Now moving up past the top of the shown window?
|
179
|
-
if position <= (offset
|
198
|
+
if position > 1 && position <= offset + 1 # - (offset > 1 ? 0 : -1)
|
180
199
|
print "\b" * (uncolor.call(words[position]).length + pre_post_length)
|
181
200
|
offset -= 1
|
182
|
-
#
|
183
|
-
|
201
|
+
# Up next to the top, and write the first word over the up arrows
|
202
|
+
if offset == 0
|
203
|
+
print (27.chr + 91.chr + 65.chr)
|
204
|
+
end_fill = max_word_length - uncolor.call(words[0]).length
|
205
|
+
puts (is_multiple && chosen.include?(0)) ? "#{prefix}#{words[0]}#{postfix}#{" " * end_fill}" : "#{" " * pre_length}#{words[0]}#{" " * (end_fill + post_length)}"
|
206
|
+
end
|
207
|
+
((offset + 1)..(offset + height - 2)).each do |i|
|
184
208
|
end_fill = max_word_length - uncolor.call(words[i]).length
|
185
|
-
puts (is_multiple && chosen.include?(i)) ? "#{prefix}#{words[i]}#{postfix}#{" " * end_fill}" : "#{" " *
|
209
|
+
puts ((!is_multiple && i == (offset + 1)) || (is_multiple && chosen.include?(i))) ? "#{prefix}#{words[i]}#{postfix}#{" " * end_fill}" : "#{" " * pre_length}#{words[i]}#{" " * (end_fill + post_length)}"
|
186
210
|
end
|
187
|
-
|
211
|
+
if offset == words.length - height - 1
|
212
|
+
puts "#{" " * pre_length}#{"↓" * max_word_length}#{" " * post_length}"
|
213
|
+
print (27.chr + 91.chr + 65.chr)
|
214
|
+
end
|
215
|
+
print (27.chr + 91.chr + 65.chr) * (height - 2)
|
188
216
|
is_shift = true
|
217
|
+
position -= 1
|
218
|
+
w1 = -pre_post_length
|
219
|
+
else
|
220
|
+
make_select.call(chosen.include?(position) && is_shift && is_multiple, true, true) if is_shift || !is_multiple
|
221
|
+
w1 = uncolor.call(words[position]).length
|
222
|
+
position -= 1
|
223
|
+
print 27.chr + 91.chr + 65.chr
|
189
224
|
end
|
190
|
-
|
191
|
-
|
192
|
-
position -= 1
|
193
|
-
print 27.chr + 91.chr + 65.chr
|
194
|
-
if is_shift || !is_multiple
|
195
|
-
make_select.call((chosen.include?(position) && is_shift) || !is_multiple)
|
225
|
+
if !is_shift && !is_multiple
|
226
|
+
make_select.call(chosen.include?(position) || !is_multiple)
|
196
227
|
else
|
197
228
|
w2 = uncolor.call(words[position]).length
|
198
229
|
print (w1 > w2 ? "\b" : (27.chr + 91.chr + 67.chr)) * (w1 - w2).abs
|
@@ -200,29 +231,30 @@ module FancyGets
|
|
200
231
|
end
|
201
232
|
end
|
202
233
|
|
234
|
+
# Initialize everything
|
203
235
|
if is_list
|
204
236
|
# Maybe confirm the height is adequate by checking out IO.console.winsize
|
205
|
-
case
|
206
|
-
when
|
237
|
+
case
|
238
|
+
when chosen.is_a?(Numeric)
|
207
239
|
chosen = [chosen]
|
208
|
-
when
|
240
|
+
when chosen.is_a?(String)
|
209
241
|
if words.include?(chosen)
|
210
242
|
chosen = [words.index(chosen)]
|
211
243
|
else
|
212
244
|
chosen = []
|
213
245
|
end
|
214
|
-
when
|
246
|
+
when chosen.is_a?(Array)
|
215
247
|
chosen.each_with_index do |item, i|
|
216
|
-
case
|
217
|
-
when
|
248
|
+
case
|
249
|
+
when item.is_a?(String)
|
218
250
|
chosen[i] = words.index(item)
|
219
|
-
when
|
251
|
+
when item.is_a?(Numeric)
|
220
252
|
chosen[i] = nil if item < 0 || item >= words.length
|
221
253
|
else
|
222
254
|
chosen[i] = word_objects.index(item)
|
223
255
|
end
|
224
256
|
end
|
225
|
-
chosen.
|
257
|
+
chosen.compact.uniq
|
226
258
|
else
|
227
259
|
if word_objects.include?(chosen)
|
228
260
|
chosen = [word_objects.index(chosen)]
|
@@ -234,28 +266,30 @@ module FancyGets
|
|
234
266
|
chosen = [0] if chosen == [] && !is_multiple
|
235
267
|
position = chosen.first if chosen.length > 0
|
236
268
|
# If there's more options than we can fit at once
|
237
|
-
|
269
|
+
if height < words.length
|
238
270
|
# ... put the chosen one a third of the way down the screen
|
239
271
|
offset = position - (height / 3)
|
272
|
+
offset = words.length - height if offset > words.length - height
|
240
273
|
offset = 0 if offset < 0
|
241
274
|
end
|
275
|
+
|
276
|
+
# **********************************************
|
277
|
+
# **********************************************
|
278
|
+
# **********************************************
|
279
|
+
# **********************************************
|
280
|
+
# **********************************************
|
281
|
+
|
242
282
|
# Scrolled any amount downwards?
|
243
|
-
# was: if
|
244
|
-
puts "#{" " *
|
245
|
-
|
246
|
-
top_bottom_reserved = offset.nil? ? 0 : 2
|
247
|
-
last_word = (offset || 0) + height - top_bottom_reserved
|
248
|
-
# Maybe we can fit it all
|
249
|
-
last_word = words.length if last_word > words.length
|
283
|
+
# was: if height < words.length
|
284
|
+
puts "#{" " * pre_length}#{"↑" * max_word_length}" if offset > 0
|
285
|
+
last_word = (height - 2) + offset + (height + offset < words.length ? 0 : 1)
|
250
286
|
# Write all the visible words
|
251
|
-
((offset
|
287
|
+
((offset + (offset > 0 ? 1 : 0))..last_word).each { |i| puts chosen.include?(i) ? "#{prefix}#{words[i]}#{postfix}" : "#{" " * pre_length}#{words[i]}" }
|
252
288
|
# Can't fit it all?
|
253
|
-
#
|
254
|
-
puts "#{" " * uncolor.call(prefix).length}#{"↓" * max_word_length}" if height < words.length
|
289
|
+
puts "#{" " * pre_length}#{"↓" * max_word_length}" if height + offset < words.length
|
255
290
|
|
256
291
|
info ||= "Use arrow keys#{is_multiple ? ", spacebar to toggle, and ENTER to save" : " and ENTER to make a choice"}"
|
257
|
-
|
258
|
-
print info + (27.chr + 91.chr + 65.chr) * (height - (position - (offset || 0)) - (height < words.length ? 1 : 0))
|
292
|
+
print info + (27.chr + 91.chr + 65.chr) * ((last_word - position) + (height + offset < words.length ? 2 : 1))
|
259
293
|
# To end of text on starting line
|
260
294
|
info_length = uncolor.call(info).length
|
261
295
|
word_length = uncolor.call(words[position]).length + pre_post_length
|
@@ -274,6 +308,7 @@ module FancyGets
|
|
274
308
|
case code
|
275
309
|
when 3 # CTRL-C
|
276
310
|
clear_dropdown_info.call if is_list
|
311
|
+
# puts "o: #{offset} p: #{position} h: #{height} wl: #{words.length}"
|
277
312
|
exit
|
278
313
|
when 13 # ENTER
|
279
314
|
if is_list
|
@@ -316,14 +351,21 @@ module FancyGets
|
|
316
351
|
position += 1
|
317
352
|
end
|
318
353
|
when 66 # - down
|
319
|
-
if is_list
|
320
|
-
arrow_down.call
|
321
|
-
end
|
354
|
+
arrow_down.call if is_list
|
322
355
|
when 65 # - up
|
323
|
-
if is_list
|
324
|
-
|
356
|
+
arrow_up.call if is_list
|
357
|
+
when 51 # - Start of a possible delete forwards?
|
358
|
+
if STDIN.getch.ord == 126 # - Delete (forwards)
|
359
|
+
if !is_list && position < string.length
|
360
|
+
string = string[0...position] + string[position + 1..-1]
|
361
|
+
if words.empty?
|
362
|
+
print "#{is_password ? "*" * (string.length - position) : string[position..-1]} #{"\b" * (string.length - position + 1)}"
|
363
|
+
else
|
364
|
+
prev_sugg = sugg
|
365
|
+
print "#{string[position..-1]}#{write_sugg.call}"
|
366
|
+
end
|
367
|
+
end
|
325
368
|
end
|
326
|
-
when 51 # - Delete forwards?
|
327
369
|
else
|
328
370
|
# puts "ESC 91 #{ch}"
|
329
371
|
end
|
@@ -334,7 +376,7 @@ module FancyGets
|
|
334
376
|
when 127 # Backspace
|
335
377
|
if !is_list && position > 0
|
336
378
|
string = string[0...position - 1] + string[position..-1]
|
337
|
-
if words.
|
379
|
+
if words.empty?
|
338
380
|
position -= 1
|
339
381
|
print "\b#{is_password ? "*" * (string.length - position) : string[position..-1]} #{"\b" * (string.length - position + 1)}"
|
340
382
|
else
|
@@ -343,16 +385,6 @@ module FancyGets
|
|
343
385
|
print "\b#{string[position..-1]}#{write_sugg.call}"
|
344
386
|
end
|
345
387
|
end
|
346
|
-
when 126 # Delete (forwards)
|
347
|
-
if !is_list && position < string.length
|
348
|
-
string = string[0...position] + string[position + 1..-1]
|
349
|
-
if words.nil?
|
350
|
-
print "#{is_password ? "*" * (string.length - position) : string[position..-1]} #{"\b" * (string.length - position + 1)}"
|
351
|
-
else
|
352
|
-
prev_sugg = sugg
|
353
|
-
print "#{string[position..-1]}#{write_sugg.call}"
|
354
|
-
end
|
355
|
-
end
|
356
388
|
else # Insert character
|
357
389
|
if is_list
|
358
390
|
case ch
|
@@ -362,18 +394,27 @@ module FancyGets
|
|
362
394
|
does_include = chosen.include?(position)
|
363
395
|
is_rejected = false
|
364
396
|
if on_change.is_a? Proc
|
365
|
-
|
397
|
+
# Generate what would happen if this change goes through
|
398
|
+
if does_include
|
399
|
+
new_chosen = chosen - [position]
|
400
|
+
else
|
401
|
+
new_chosen = chosen + [position]
|
402
|
+
end
|
403
|
+
chosen_objects = new_chosen.sort.map{|choice| word_objects[choice]}
|
404
|
+
response = on_change.call({chosen: chosen_objects, changed: word_objects[position], is_chosen: !does_include})
|
366
405
|
new_info = nil
|
367
406
|
if response.is_a? Hash
|
368
407
|
is_rejected = response[:is_rejected]
|
369
|
-
|
408
|
+
# If they told us exactly what the choices should now be, make that happen
|
409
|
+
if response && response[:chosen].is_a?(Enumerable)
|
410
|
+
chosen = response[:chosen].map {|choice| word_objects.index(choice)}
|
411
|
+
is_rejected = true
|
412
|
+
end
|
370
413
|
new_info = response[:info]
|
371
414
|
elsif response.is_a? String
|
372
415
|
new_info = response
|
373
416
|
end
|
374
|
-
|
375
|
-
write_info.call(new_info)
|
376
|
-
end
|
417
|
+
write_info.call(new_info) if new_info
|
377
418
|
end
|
378
419
|
unless is_rejected
|
379
420
|
if does_include
|
@@ -383,6 +424,10 @@ module FancyGets
|
|
383
424
|
end
|
384
425
|
make_select.call(!does_include, true)
|
385
426
|
end
|
427
|
+
else
|
428
|
+
# Allows Windows to have a way to at least use single-select lists
|
429
|
+
clear_dropdown_info.call
|
430
|
+
break
|
386
431
|
end
|
387
432
|
when "j" # Down
|
388
433
|
arrow_down.call
|
@@ -391,7 +436,7 @@ module FancyGets
|
|
391
436
|
end
|
392
437
|
else
|
393
438
|
string = string[0...position] + ch + string[position..-1]
|
394
|
-
if words.
|
439
|
+
if words.empty?
|
395
440
|
ch = "*" if is_password
|
396
441
|
position += 1
|
397
442
|
print "#{ch}#{is_password ? "*" * (string.length - position) : string[position..-1]}#{"\b" * (string.length - position)}"
|
@@ -406,7 +451,7 @@ module FancyGets
|
|
406
451
|
|
407
452
|
if is_list
|
408
453
|
# Put chosen stuff in same order as it's listed in the words array
|
409
|
-
is_multiple ? chosen.map {|c| word_objects[c] } : word_objects[position]
|
454
|
+
is_multiple ? chosen.sort.map {|c| word_objects[c] } : word_objects[position]
|
410
455
|
else
|
411
456
|
sugg.empty? ? string : word_objects[words.index(sugg)]
|
412
457
|
end
|
data/lib/fancy_gets/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fancy_gets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorin Thwaits
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,7 +85,7 @@ licenses:
|
|
85
85
|
- MIT
|
86
86
|
metadata:
|
87
87
|
allowed_push_host: https://rubygems.org
|
88
|
-
post_install_message:
|
88
|
+
post_install_message:
|
89
89
|
rdoc_options: []
|
90
90
|
require_paths:
|
91
91
|
- lib
|
@@ -100,9 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
|
-
|
104
|
-
|
105
|
-
signing_key:
|
103
|
+
rubygems_version: 3.2.3
|
104
|
+
signing_key:
|
106
105
|
specification_version: 4
|
107
106
|
summary: Enhanced gets with listbox, auto-complete, and password support
|
108
107
|
test_files: []
|