fancy_gets 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 71e6d543b0daf8b20b20b1989906a112a880d23d
4
- data.tar.gz: 94b96b2bc2ffdd3f58c8adadbb0dd85bab7ecbc4
2
+ SHA256:
3
+ metadata.gz: 51c96b67bf9c4b86e5a928042a1ef0923d720cedc3e75dc659bd58910c284e8c
4
+ data.tar.gz: 222b64256299e56e23c0829b2fb7a855d6d4f38cd158926040d661deb0121583
5
5
  SHA512:
6
- metadata.gz: cf666cb9f9b1dc866dcfa2f451c975ae83814b7d156afa912b0f39a20c92adb4bcd772c929329d996470d92261a6fb1b1ff86f6ee81574a86cc5f12b0674bbd3
7
- data.tar.gz: 0724abbfc5585e79ba86337726f4c3c7380074376b2e12f7ee7bf109890e6f902fbdf5affe87ff63112ef22d3dc47ecac421663cf892770cc3e1597b9b0cd093
6
+ metadata.gz: 573430996f606e869215ceb26ed019753192d9344d5c182027e22a9b9b09167eedc8938d994a0cdfbc64f8e3f6f1c9d4c57ff6eb1dc50d216632270c79ad78da
7
+ data.tar.gz: ece58b484fcf7fbf88c16f94d00a3868743c9218f5b0069cb9eaf12fb29d252aa0259945e3e8cf61641053a033829918d99be835a0c499336e73887dc5fd038e
@@ -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", "~> 10.0"
38
+ spec.add_development_dependency "rake", "~> 12.3.3"
39
39
  spec.add_development_dependency "rspec", "~> 3.0"
40
40
  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
- unless word_objects.nil? || is_list
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.nil? ? [] : word_objects.map(&:to_s)
46
+ words = word_objects&.map(&:to_s) || []
47
47
  if is_multiple
48
48
  chosen ||= [0] unless is_multiple
49
49
  else
@@ -56,8 +56,8 @@ module FancyGets
56
56
  end
57
57
  position = 0
58
58
  # Up and down arrows break with height of 3 or less
59
- height = words.length unless !height.nil? && height.is_a?(Numeric) && height >= 4
60
- winheight = IO.console.winsize.first - 3
59
+ height = words.length unless height&.is_a?(Numeric) && height >= 4
60
+ winheight = (IO.console || STDOUT).winsize.first - 3
61
61
  height = words.length if height > words.length
62
62
  height = winheight if height > winheight
63
63
  offset = 0
@@ -109,7 +109,7 @@ module FancyGets
109
109
  # Put the response into the info line, as long as it's short enough!
110
110
  new_info.gsub!("\n", " ")
111
111
  new_info_length = uncolor.call(new_info).length
112
- console_width = IO.console.winsize.last
112
+ console_width = (IO.console || STDOUT).winsize.last
113
113
  # Might have to trim if it's a little too wide
114
114
  new_info = new_info[0...console_width] if console_width < new_info_length
115
115
  # Arrow down to the info line
@@ -131,9 +131,9 @@ module FancyGets
131
131
  print (new_info_length > word_length ? "\b" : (27.chr + 91.chr + 67.chr)) * (new_info_length - word_length).abs
132
132
  end
133
133
 
134
- handle_on_select = lambda do |focused|
134
+ handle_on_select = lambda do |selected|
135
135
  if on_select.is_a? Proc
136
- response = on_select.call({chosen: chosen, focused: focused})
136
+ response = on_select.call({chosen: chosen, selected: selected})
137
137
  new_info = nil
138
138
  if response.is_a? Hash
139
139
  chosen = response[:chosen] || chosen
@@ -141,9 +141,7 @@ module FancyGets
141
141
  elsif response.is_a? String
142
142
  new_info = response
143
143
  end
144
- unless new_info.nil?
145
- write_info.call(new_info)
146
- end
144
+ write_info.call(new_info) if new_info
147
145
  end
148
146
  end
149
147
 
@@ -256,7 +254,7 @@ module FancyGets
256
254
  chosen[i] = word_objects.index(item)
257
255
  end
258
256
  end
259
- chosen.select{|item| !item.nil?}.uniq
257
+ chosen.compact.uniq
260
258
  else
261
259
  if word_objects.include?(chosen)
262
260
  chosen = [word_objects.index(chosen)]
@@ -356,7 +354,18 @@ module FancyGets
356
354
  arrow_down.call if is_list
357
355
  when 65 # - up
358
356
  arrow_up.call if is_list
359
- when 51 # - Delete forwards?
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
368
+ end
360
369
  else
361
370
  # puts "ESC 91 #{ch}"
362
371
  end
@@ -376,16 +385,6 @@ module FancyGets
376
385
  print "\b#{string[position..-1]}#{write_sugg.call}"
377
386
  end
378
387
  end
379
- when 126 # Delete (forwards)
380
- if !is_list && position < string.length
381
- string = string[0...position] + string[position + 1..-1]
382
- if words.empty?
383
- print "#{is_password ? "*" * (string.length - position) : string[position..-1]} #{"\b" * (string.length - position + 1)}"
384
- else
385
- prev_sugg = sugg
386
- print "#{string[position..-1]}#{write_sugg.call}"
387
- end
388
- end
389
388
  else # Insert character
390
389
  if is_list
391
390
  case ch
@@ -407,7 +406,7 @@ module FancyGets
407
406
  if response.is_a? Hash
408
407
  is_rejected = response[:is_rejected]
409
408
  # If they told us exactly what the choices should now be, make that happen
410
- if !response.nil? && response[:chosen].is_a?(Enumerable)
409
+ if response && response[:chosen].is_a?(Enumerable)
411
410
  chosen = response[:chosen].map {|choice| word_objects.index(choice)}
412
411
  is_rejected = true
413
412
  end
@@ -415,9 +414,7 @@ module FancyGets
415
414
  elsif response.is_a? String
416
415
  new_info = response
417
416
  end
418
- unless new_info.nil?
419
- write_info.call(new_info)
420
- end
417
+ write_info.call(new_info) if new_info
421
418
  end
422
419
  unless is_rejected
423
420
  if does_include
@@ -1,3 +1,3 @@
1
1
  module FancyGets
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
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.9
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: 2017-05-17 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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
- rubyforge_project:
104
- rubygems_version: 2.6.7
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: []