fancy_gets 0.1.7 → 0.1.8

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
2
  SHA1:
3
- metadata.gz: 7b272606703927506851d9c9025118cbbbc58474
4
- data.tar.gz: 0c822de7e9d818be0f98b568adc05bc45130c082
3
+ metadata.gz: 274606db5f52db34b0cf2a30e93e937d35f2318f
4
+ data.tar.gz: 713e3c90a53dba4072454091db98d7172f93f589
5
5
  SHA512:
6
- metadata.gz: 0659e47c8b0cd86d194d452097865729e7951aaeaf9eb49eacc81d1bc4aadbf57557c18b5897703955efbc365ee0f48967729e14ab7d797e3dc8b8be5e75e19b
7
- data.tar.gz: e29eb11a5b04806c20935a61060b2445ce16fa8fdffe9abd545fc871deaaff6bb01c9968060dde835ecaf8d7193c04a7532e79859fb8338fde2c62c4833cc612
6
+ metadata.gz: 5c435f2ee2daae5308f6a454f75e8094922866567a877e559d8500a1823a99f2358d581762ba422da17676a47990b5ed371ee8eea802abc66e11860f0f2bf47c
7
+ data.tar.gz: 423eec52b1efabfc1c025b023c41312b9a7ca946aa369cd7ab3878aba2e12edd69adc47cae5f43ce6a830363b62c9d4c3e877ef32ef25334d24daafd7e1f73db
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
@@ -55,7 +55,7 @@ module FancyGets
55
55
  end
56
56
  end
57
57
  position = 0
58
- # After tweaking the down arrow code, might work OK with 3 things
58
+ # Up and down arrows break with height of 3 or less
59
59
  height = words.length unless !height.nil? && height.is_a?(Numeric) && height >= 4
60
60
  winheight = IO.console.winsize.first - 3
61
61
  height = words.length if height > words.length
@@ -150,7 +150,6 @@ module FancyGets
150
150
  # **********************************************
151
151
  # ******************** DOWN ********************
152
152
  # Doesn't work with a height of 3 when there's more than 3 in the list
153
- # (somehow up arrow can work OK with this)
154
153
  arrow_down = lambda do
155
154
  if position < words.length - 1
156
155
  is_shift = false
@@ -162,7 +161,7 @@ module FancyGets
162
161
  print (27.chr + 91.chr + 65.chr) * (height - 3)
163
162
  if offset == 0
164
163
  print (27.chr + 91.chr + 65.chr)
165
- puts "#{" " * pre_length}#{"↑" * max_word_length}"
164
+ puts "#{" " * pre_length}#{"↑" * max_word_length}#{" " * post_length}"
166
165
  end
167
166
  offset += 1
168
167
  ((offset + 1)..(offset + (height - 4))).each do |i|
@@ -212,7 +211,7 @@ module FancyGets
212
211
  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)}"
213
212
  end
214
213
  if offset == words.length - height - 1
215
- puts "#{" " * pre_length}#{"↓" * max_word_length}"
214
+ puts "#{" " * pre_length}#{"↓" * max_word_length}#{" " * post_length}"
216
215
  print (27.chr + 91.chr + 65.chr)
217
216
  end
218
217
  print (27.chr + 91.chr + 65.chr) * (height - 2)
@@ -273,6 +272,7 @@ module FancyGets
273
272
  # ... put the chosen one a third of the way down the screen
274
273
  offset = position - (height / 3)
275
274
  offset = words.length - height if offset > words.length - height
275
+ offset = 0 if offset < 0
276
276
  end
277
277
 
278
278
  # **********************************************
@@ -353,13 +353,9 @@ module FancyGets
353
353
  position += 1
354
354
  end
355
355
  when 66 # - down
356
- if is_list
357
- arrow_down.call
358
- end
356
+ arrow_down.call if is_list
359
357
  when 65 # - up
360
- if is_list
361
- arrow_up.call
362
- end
358
+ arrow_up.call if is_list
363
359
  when 51 # - Delete forwards?
364
360
  else
365
361
  # puts "ESC 91 #{ch}"
@@ -1,3 +1,3 @@
1
1
  module FancyGets
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fancy_gets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits