typr 1.8.0 → 1.9.0

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/lib/stack.rb CHANGED
@@ -17,10 +17,25 @@ module Typr
17
17
  # KEY_HOME / KEY_END (jump to first or last pageable row)
18
18
 
19
19
  class Stack < Space
20
- ## Widget configuration. +left+, +top+, +right+, +bottom+ set the viewport; see {Space}.
21
- ## +alternate+ toggles striped rows (+:grey10+ background alternating with the default bg).
20
+ ##
21
+ # Widget configuration and state: +left+/+top+/+right+/+bottom+ set
22
+ # the viewport (see {Space}), +alternate+ toggles striped rows
23
+ # (+:grey10+ against the default bg), +start+ is the scroll offset,
24
+ # +keymap+ maps key sequences to methods, +selected+ holds picked ids
25
+ # per type, and +header+ is the top-bar label.
26
+ #
27
+ # stack.start = 3
28
+ # stack.header = "Title"
22
29
 
23
30
  attr_accessor :start, :keymap, :selected, :header
31
+ ##
32
+ # +separator+ is the gap between columns, +hints+ the hint characters,
33
+ # +hints_start+ the offset of the current hint chunk ({#cycle}), and
34
+ # +modifier+ is +:alt+ after an Alt-digit hint press, +nil+ otherwise.
35
+ #
36
+ # stack.hints = "1234567890"
37
+ # stack.modifier #=> :alt (after picking with Alt+digit)
38
+
24
39
  attr_accessor :separator, :hints, :hints_start, :modifier
25
40
 
26
41
  ##
@@ -174,39 +189,57 @@ module Typr
174
189
  return response
175
190
  end
176
191
 
177
- ## Scroll to the top of the dataset.
192
+ ##
193
+ # Scroll to the top of the dataset.
178
194
  #
179
- # stack.to_top
195
+ # stack.to_top # @start => 0
196
+ #
197
+ # @return [nil]
180
198
 
181
199
  def to_top; @start = 0; return end
182
200
 
183
- ## Scroll to the bottom pageable position (last row minus viewport height).
201
+ ##
202
+ # Scroll to the bottom pageable position (last row minus viewport height).
203
+ #
204
+ # stack.to_bottom # @start => rows - height
184
205
  #
185
- # stack.to_bottom
206
+ # @return [nil]
186
207
 
187
208
  def to_bottom; @start = rows - height; return end
188
209
 
189
- ## Step down by one row.
210
+ ##
211
+ # Step down by one row.
212
+ #
213
+ # stack.down # @start += 1
190
214
  #
191
- # stack.down
215
+ # @return [nil]
192
216
 
193
217
  def down; @start += 1; return end
194
218
 
195
- ## Step up by one row.
219
+ ##
220
+ # Step up by one row.
196
221
  #
197
- # stack.up
222
+ # stack.up # @start -= 1
223
+ #
224
+ # @return [nil]
198
225
 
199
226
  def up; @start -= 1; return end
200
227
 
201
- ## Jump down by one viewport of rows.
228
+ ##
229
+ # Jump down by one viewport of rows.
230
+ #
231
+ # stack.page_down # @start += height
202
232
  #
203
- # stack.page_down
233
+ # @return [nil]
204
234
 
205
235
  def page_down; @start += height; return end
206
236
 
207
- ## Jump up by one viewport of rows.
237
+ ##
238
+ # Jump up by one viewport of rows.
239
+ #
240
+ # stack.page_up # @start -= height
208
241
  #
209
- # stack.page_up
242
+ # @return [nil]
210
243
 
211
244
  def page_up; @start -= height; return end
212
245
 
@@ -230,7 +263,14 @@ module Typr
230
263
  # stack.pick :column, 3 # pick a column in row 3
231
264
  # stack.pick "rows" # multi-select rows
232
265
  #
266
+ # Pressing Alt with a hint digit (ESC + digit) picks that hint row and
267
+ # sets +modifier+ to +:alt+ for the caller.
268
+ #
233
269
  # Mouse: left-click a row to pick it; wheel up/down scrolls the page.
270
+ #
271
+ # @param type [Symbol, String] picker type (table above)
272
+ # @param row [Integer] starting row for column/field hints
273
+ # @return [Integer, Array, nil] picked id(s), selection on confirm, or nil on abort
234
274
 
235
275
  def pick type = :row, row=0 #, key=nil
236
276
  type = type.to_s
@@ -298,6 +338,14 @@ module Typr
298
338
  return
299
339
  end
300
340
 
341
+ ##
342
+ # Walk the hint characters backwards by one chunk (mirror of {#cycle}),
343
+ # wrapping to the last full chunk before the start of the list.
344
+ #
345
+ # stack.cycle_back # hints_start -= hints.size (wraps at 0)
346
+ #
347
+ # @return [nil]
348
+
301
349
  def cycle_back
302
350
  max = [height-1, rows-1+headspace].min
303
351
  @hints_start -= @hints.size