@socketsecurity/cli-with-sentry 0.14.137 → 0.14.139

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.
Files changed (109) hide show
  1. package/dist/blessed/LICENSE +20 -0
  2. package/dist/blessed/lib/alias.js +519 -0
  3. package/dist/blessed/lib/blessed.js +32 -0
  4. package/dist/blessed/lib/colors.js +490 -0
  5. package/dist/blessed/lib/events.js +195 -0
  6. package/dist/blessed/lib/gpmclient.js +245 -0
  7. package/dist/blessed/lib/helpers.js +170 -0
  8. package/dist/blessed/lib/keys.js +512 -0
  9. package/dist/blessed/lib/program.js +4530 -0
  10. package/dist/blessed/lib/tput.js +3111 -0
  11. package/dist/blessed/lib/unicode.js +912 -0
  12. package/dist/blessed/lib/widget.js +60 -0
  13. package/dist/blessed/lib/widgets/ansiimage.js +173 -0
  14. package/dist/blessed/lib/widgets/bigtext.js +170 -0
  15. package/dist/blessed/lib/widgets/box.js +34 -0
  16. package/dist/blessed/lib/widgets/button.js +62 -0
  17. package/dist/blessed/lib/widgets/checkbox.js +95 -0
  18. package/dist/blessed/lib/widgets/element.js +2871 -0
  19. package/dist/blessed/lib/widgets/filemanager.js +223 -0
  20. package/dist/blessed/lib/widgets/form.js +301 -0
  21. package/dist/blessed/lib/widgets/image.js +71 -0
  22. package/dist/blessed/lib/widgets/input.js +34 -0
  23. package/dist/blessed/lib/widgets/layout.js +249 -0
  24. package/dist/blessed/lib/widgets/line.js +59 -0
  25. package/dist/blessed/lib/widgets/list.js +652 -0
  26. package/dist/blessed/lib/widgets/listbar.js +452 -0
  27. package/dist/blessed/lib/widgets/listtable.js +265 -0
  28. package/dist/blessed/lib/widgets/loading.js +88 -0
  29. package/dist/blessed/lib/widgets/log.js +82 -0
  30. package/dist/blessed/lib/widgets/message.js +145 -0
  31. package/dist/blessed/lib/widgets/node.js +314 -0
  32. package/dist/blessed/lib/widgets/overlayimage.js +794 -0
  33. package/dist/blessed/lib/widgets/progressbar.js +166 -0
  34. package/dist/blessed/lib/widgets/prompt.js +127 -0
  35. package/dist/blessed/lib/widgets/question.js +129 -0
  36. package/dist/blessed/lib/widgets/radiobutton.js +62 -0
  37. package/dist/blessed/lib/widgets/radioset.js +36 -0
  38. package/dist/blessed/lib/widgets/screen.js +2485 -0
  39. package/dist/blessed/lib/widgets/scrollablebox.js +415 -0
  40. package/dist/blessed/lib/widgets/scrollabletext.js +35 -0
  41. package/dist/blessed/lib/widgets/table.js +383 -0
  42. package/dist/blessed/lib/widgets/terminal.js +452 -0
  43. package/dist/blessed/lib/widgets/text.js +35 -0
  44. package/dist/blessed/lib/widgets/textarea.js +376 -0
  45. package/dist/blessed/lib/widgets/textbox.js +79 -0
  46. package/dist/blessed/lib/widgets/video.js +130 -0
  47. package/dist/blessed/usr/fonts/AUTHORS +1 -0
  48. package/dist/blessed/usr/fonts/LICENSE +94 -0
  49. package/dist/blessed/usr/fonts/README +340 -0
  50. package/dist/blessed/usr/fonts/ter-u14b.json +17826 -0
  51. package/dist/blessed/usr/fonts/ter-u14n.json +17826 -0
  52. package/dist/blessed/usr/linux +0 -0
  53. package/dist/blessed/usr/windows-ansi +0 -0
  54. package/dist/blessed/usr/xterm +0 -0
  55. package/dist/blessed/usr/xterm-256color +0 -0
  56. package/dist/blessed/usr/xterm.termcap +243 -0
  57. package/dist/blessed/usr/xterm.terminfo +1977 -0
  58. package/dist/blessed/vendor/tng.js +1876 -0
  59. package/dist/blessed-contrib/LICENSE.md +21 -0
  60. package/dist/blessed-contrib/lib/layout/carousel.js +82 -0
  61. package/dist/blessed-contrib/lib/layout/grid.js +46 -0
  62. package/dist/blessed-contrib/lib/server-utils.js +83 -0
  63. package/dist/blessed-contrib/lib/utils.js +73 -0
  64. package/dist/blessed-contrib/lib/widget/canvas.js +52 -0
  65. package/dist/blessed-contrib/lib/widget/charts/bar.js +99 -0
  66. package/dist/blessed-contrib/lib/widget/charts/line.js +311 -0
  67. package/dist/blessed-contrib/lib/widget/charts/stacked-bar.js +245 -0
  68. package/dist/blessed-contrib/lib/widget/donut.js +183 -0
  69. package/dist/blessed-contrib/lib/widget/gauge-list.js +111 -0
  70. package/dist/blessed-contrib/lib/widget/gauge.js +127 -0
  71. package/dist/blessed-contrib/lib/widget/lcd.js +497 -0
  72. package/dist/blessed-contrib/lib/widget/log.js +32 -0
  73. package/dist/blessed-contrib/lib/widget/map.js +97 -0
  74. package/dist/blessed-contrib/lib/widget/markdown.js +68 -0
  75. package/dist/blessed-contrib/lib/widget/picture.js +61 -0
  76. package/dist/blessed-contrib/lib/widget/sparkline.js +66 -0
  77. package/dist/blessed-contrib/lib/widget/table.js +141 -0
  78. package/dist/blessed-contrib/lib/widget/tree.js +179 -0
  79. package/dist/blessed-contrib/node_modules/ansi-regex/index.js +6 -0
  80. package/dist/blessed-contrib/node_modules/ansi-regex/license +21 -0
  81. package/dist/blessed-contrib/node_modules/ansi-regex/package.json +64 -0
  82. package/dist/blessed-contrib/node_modules/ansi-regex/readme.md +39 -0
  83. package/dist/blessed-contrib/node_modules/ansi-styles/index.js +67 -0
  84. package/dist/blessed-contrib/node_modules/ansi-styles/license +21 -0
  85. package/dist/blessed-contrib/node_modules/ansi-styles/package.json +50 -0
  86. package/dist/blessed-contrib/node_modules/ansi-styles/readme.md +86 -0
  87. package/dist/blessed-contrib/node_modules/chalk/index.js +118 -0
  88. package/dist/blessed-contrib/node_modules/chalk/license +21 -0
  89. package/dist/blessed-contrib/node_modules/chalk/package.json +70 -0
  90. package/dist/blessed-contrib/node_modules/chalk/readme.md +213 -0
  91. package/dist/blessed-contrib/node_modules/escape-string-regexp/index.js +13 -0
  92. package/dist/blessed-contrib/node_modules/escape-string-regexp/license +21 -0
  93. package/dist/blessed-contrib/node_modules/escape-string-regexp/package.json +41 -0
  94. package/dist/blessed-contrib/node_modules/escape-string-regexp/readme.md +27 -0
  95. package/dist/blessed-contrib/node_modules/strip-ansi/index.js +8 -0
  96. package/dist/blessed-contrib/node_modules/strip-ansi/license +21 -0
  97. package/dist/blessed-contrib/node_modules/strip-ansi/package.json +57 -0
  98. package/dist/blessed-contrib/node_modules/strip-ansi/readme.md +33 -0
  99. package/dist/blessed-contrib/node_modules/supports-color/index.js +52 -0
  100. package/dist/blessed-contrib/node_modules/supports-color/license +21 -0
  101. package/dist/blessed-contrib/node_modules/supports-color/package.json +49 -0
  102. package/dist/blessed-contrib/node_modules/supports-color/readme.md +36 -0
  103. package/dist/cli.js +9 -8
  104. package/dist/cli.js.map +1 -1
  105. package/dist/instrument-with-sentry.js +2 -2
  106. package/dist/instrument-with-sentry.js.map +1 -1
  107. package/dist/shadow-npm-inject.js +2 -2
  108. package/dist/shadow-npm-inject.js.map +1 -1
  109. package/package.json +4 -4
@@ -0,0 +1,652 @@
1
+ /**
2
+ * list.js - list element for blessed
3
+ * Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
4
+ * https://github.com/chjj/blessed
5
+ */
6
+
7
+ /**
8
+ * Modules
9
+ */
10
+
11
+ const helpers = require('../helpers')
12
+
13
+ const Node = require('./node')
14
+ const Box = require('./box')
15
+
16
+ /**
17
+ * List
18
+ */
19
+
20
+ function List(options) {
21
+ const self = this
22
+
23
+ if (!(this instanceof Node)) {
24
+ return new List(options)
25
+ }
26
+
27
+ options = options || {}
28
+
29
+ options.ignoreKeys = true
30
+ // Possibly put this here: this.items = [];
31
+ options.scrollable = true
32
+ Box.call(this, options)
33
+
34
+ this.value = ''
35
+ this.items = []
36
+ this.ritems = []
37
+ this.selected = 0
38
+ this._isList = true
39
+
40
+ if (!this.style.selected) {
41
+ this.style.selected = {}
42
+ this.style.selected.bg = options.selectedBg
43
+ this.style.selected.fg = options.selectedFg
44
+ this.style.selected.bold = options.selectedBold
45
+ this.style.selected.underline = options.selectedUnderline
46
+ this.style.selected.blink = options.selectedBlink
47
+ this.style.selected.inverse = options.selectedInverse
48
+ this.style.selected.invisible = options.selectedInvisible
49
+ }
50
+
51
+ if (!this.style.item) {
52
+ this.style.item = {}
53
+ this.style.item.bg = options.itemBg
54
+ this.style.item.fg = options.itemFg
55
+ this.style.item.bold = options.itemBold
56
+ this.style.item.underline = options.itemUnderline
57
+ this.style.item.blink = options.itemBlink
58
+ this.style.item.inverse = options.itemInverse
59
+ this.style.item.invisible = options.itemInvisible
60
+ }
61
+
62
+ // Legacy: for apps written before the addition of item attributes.
63
+ ;['bg', 'fg', 'bold', 'underline', 'blink', 'inverse', 'invisible'].forEach(
64
+ function (name) {
65
+ if (self.style[name] != null && self.style.item[name] == null) {
66
+ self.style.item[name] = self.style[name]
67
+ }
68
+ }
69
+ )
70
+
71
+ if (this.options.itemHoverBg) {
72
+ this.options.itemHoverEffects = { bg: this.options.itemHoverBg }
73
+ }
74
+
75
+ if (this.options.itemHoverEffects) {
76
+ this.style.item.hover = this.options.itemHoverEffects
77
+ }
78
+
79
+ if (this.options.itemFocusEffects) {
80
+ this.style.item.focus = this.options.itemFocusEffects
81
+ }
82
+
83
+ this.interactive = options.interactive !== false
84
+
85
+ this.mouse = options.mouse || false
86
+
87
+ if (options.items) {
88
+ this.ritems = options.items
89
+ options.items.forEach(this.add.bind(this))
90
+ }
91
+
92
+ this.select(0)
93
+
94
+ if (options.mouse) {
95
+ this.screen._listenMouse(this)
96
+ this.on('element wheeldown', function () {
97
+ self.select(self.selected + 2)
98
+ self.screen.render()
99
+ })
100
+ this.on('element wheelup', function () {
101
+ self.select(self.selected - 2)
102
+ self.screen.render()
103
+ })
104
+ }
105
+
106
+ if (options.keys) {
107
+ this.on('keypress', function (ch, key) {
108
+ if (key.name === 'up' || (options.vi && key.name === 'k')) {
109
+ self.up()
110
+ self.screen.render()
111
+ return
112
+ }
113
+ if (key.name === 'down' || (options.vi && key.name === 'j')) {
114
+ self.down()
115
+ self.screen.render()
116
+ return
117
+ }
118
+ if (
119
+ key.name === 'enter' ||
120
+ (options.vi && key.name === 'l' && !key.shift)
121
+ ) {
122
+ self.enterSelected()
123
+ return
124
+ }
125
+ if (key.name === 'escape' || (options.vi && key.name === 'q')) {
126
+ self.cancelSelected()
127
+ return
128
+ }
129
+ if (options.vi && key.name === 'u' && key.ctrl) {
130
+ self.move(-((self.height - self.iheight) / 2) | 0)
131
+ self.screen.render()
132
+ return
133
+ }
134
+ if (options.vi && key.name === 'd' && key.ctrl) {
135
+ self.move(((self.height - self.iheight) / 2) | 0)
136
+ self.screen.render()
137
+ return
138
+ }
139
+ if (options.vi && key.name === 'b' && key.ctrl) {
140
+ self.move(-(self.height - self.iheight))
141
+ self.screen.render()
142
+ return
143
+ }
144
+ if (options.vi && key.name === 'f' && key.ctrl) {
145
+ self.move(self.height - self.iheight)
146
+ self.screen.render()
147
+ return
148
+ }
149
+ if (options.vi && key.name === 'h' && key.shift) {
150
+ self.move(self.childBase - self.selected)
151
+ self.screen.render()
152
+ return
153
+ }
154
+ if (options.vi && key.name === 'm' && key.shift) {
155
+ // TODO: Maybe use Math.min(this.items.length,
156
+ // ... for calculating visible items elsewhere.
157
+ const visible =
158
+ (Math.min(self.height - self.iheight, self.items.length) / 2) | 0
159
+ self.move(self.childBase + visible - self.selected)
160
+ self.screen.render()
161
+ return
162
+ }
163
+ if (options.vi && key.name === 'l' && key.shift) {
164
+ // XXX This goes one too far on lists with an odd number of items.
165
+ self.down(
166
+ self.childBase +
167
+ Math.min(self.height - self.iheight, self.items.length) -
168
+ self.selected
169
+ )
170
+ self.screen.render()
171
+ return
172
+ }
173
+ if (options.vi && key.name === 'g' && !key.shift) {
174
+ self.select(0)
175
+ self.screen.render()
176
+ return
177
+ }
178
+ if (options.vi && key.name === 'g' && key.shift) {
179
+ self.select(self.items.length - 1)
180
+ self.screen.render()
181
+ return
182
+ }
183
+
184
+ if (options.vi && (key.ch === '/' || key.ch === '?')) {
185
+ if (typeof self.options.search !== 'function') {
186
+ return
187
+ }
188
+ return self.options.search(function (err, value) {
189
+ if (
190
+ typeof err === 'string' ||
191
+ typeof err === 'function' ||
192
+ typeof err === 'number' ||
193
+ (err && err.test)
194
+ ) {
195
+ value = err
196
+ err = null
197
+ }
198
+ if (err || !value) {
199
+ return self.screen.render()
200
+ }
201
+ self.select(self.fuzzyFind(value, key.ch === '?'))
202
+ self.screen.render()
203
+ })
204
+ }
205
+ })
206
+ }
207
+
208
+ this.on('resize', function () {
209
+ const visible = self.height - self.iheight
210
+ // if (self.selected < visible - 1) {
211
+ if (visible >= self.selected + 1) {
212
+ self.childBase = 0
213
+ self.childOffset = self.selected
214
+ } else {
215
+ // Is this supposed to be: self.childBase = visible - self.selected + 1; ?
216
+ self.childBase = self.selected - visible + 1
217
+ self.childOffset = visible - 1
218
+ }
219
+ })
220
+
221
+ this.on('adopt', function (el) {
222
+ if (!~self.items.indexOf(el)) {
223
+ el.fixed = true
224
+ }
225
+ })
226
+
227
+ // Ensure children are removed from the
228
+ // item list if they are items.
229
+ this.on('remove', function (el) {
230
+ self.removeItem(el)
231
+ })
232
+ }
233
+
234
+ Object.setPrototypeOf(List.prototype, Box.prototype)
235
+
236
+ List.prototype.type = 'list'
237
+
238
+ List.prototype.createItem = function (content) {
239
+ const self = this
240
+
241
+ // Note: Could potentially use Button here.
242
+ const options = {
243
+ screen: this.screen,
244
+ content: content,
245
+ align: this.align || 'left',
246
+ top: 0,
247
+ left: 0,
248
+ right: this.scrollbar ? 1 : 0,
249
+ tags: this.parseTags,
250
+ height: 1,
251
+ hoverEffects: this.mouse ? this.style.item.hover : null,
252
+ focusEffects: this.mouse ? this.style.item.focus : null,
253
+ autoFocus: false
254
+ }
255
+
256
+ if (!this.screen.autoPadding) {
257
+ options.top = 1
258
+ options.left = this.ileft
259
+ options.right = this.iright + (this.scrollbar ? 1 : 0)
260
+ }
261
+
262
+ // if (this.shrink) {
263
+ // XXX NOTE: Maybe just do this on all shrinkage once autoPadding is default?
264
+ if (this.shrink && this.options.normalShrink) {
265
+ delete options.right
266
+ options.width = 'shrink'
267
+ }
268
+
269
+ ;['bg', 'fg', 'bold', 'underline', 'blink', 'inverse', 'invisible'].forEach(
270
+ function (name) {
271
+ options[name] = function () {
272
+ let attr =
273
+ self.items[self.selected] === item && self.interactive
274
+ ? self.style.selected[name]
275
+ : self.style.item[name]
276
+ if (typeof attr === 'function') {
277
+ attr = attr(item)
278
+ }
279
+ return attr
280
+ }
281
+ }
282
+ )
283
+
284
+ if (this.style.transparent) {
285
+ options.transparent = true
286
+ }
287
+
288
+ const item = new Box(options)
289
+
290
+ if (this.mouse) {
291
+ item.on('click', function () {
292
+ self.focus()
293
+ if (self.items[self.selected] === item) {
294
+ self.emit('action', item, self.selected)
295
+ self.emit('select', item, self.selected)
296
+ return
297
+ }
298
+ self.select(item)
299
+ self.screen.render()
300
+ })
301
+ }
302
+
303
+ this.emit('create item')
304
+
305
+ return item
306
+ }
307
+
308
+ List.prototype.add =
309
+ List.prototype.addItem =
310
+ List.prototype.appendItem =
311
+ function (content) {
312
+ content = typeof content === 'string' ? content : content.getContent()
313
+
314
+ const item = this.createItem(content)
315
+ item.position.top = this.items.length
316
+ if (!this.screen.autoPadding) {
317
+ item.position.top = this.itop + this.items.length
318
+ }
319
+
320
+ this.ritems.push(content)
321
+ this.items.push(item)
322
+ this.append(item)
323
+
324
+ if (this.items.length === 1) {
325
+ this.select(0)
326
+ }
327
+
328
+ this.emit('add item')
329
+
330
+ return item
331
+ }
332
+
333
+ List.prototype.removeItem = function (child) {
334
+ const i = this.getItemIndex(child)
335
+ if (~i && this.items[i]) {
336
+ child = this.items.splice(i, 1)[0]
337
+ this.ritems.splice(i, 1)
338
+ this.remove(child)
339
+ for (let j = i; j < this.items.length; j++) {
340
+ this.items[j].position.top--
341
+ }
342
+ if (i === this.selected) {
343
+ this.select(i - 1)
344
+ }
345
+ }
346
+ this.emit('remove item')
347
+ return child
348
+ }
349
+
350
+ List.prototype.insertItem = function (child, content) {
351
+ content = typeof content === 'string' ? content : content.getContent()
352
+ const i = this.getItemIndex(child)
353
+ if (!~i) {
354
+ return
355
+ }
356
+ if (i >= this.items.length) {
357
+ return this.appendItem(content)
358
+ }
359
+ const item = this.createItem(content)
360
+ for (let j = i; j < this.items.length; j++) {
361
+ this.items[j].position.top++
362
+ }
363
+ item.position.top = i + (!this.screen.autoPadding ? 1 : 0)
364
+ this.ritems.splice(i, 0, content)
365
+ this.items.splice(i, 0, item)
366
+ this.append(item)
367
+ if (i === this.selected) {
368
+ this.select(i + 1)
369
+ }
370
+ this.emit('insert item')
371
+ }
372
+
373
+ List.prototype.getItem = function (child) {
374
+ return this.items[this.getItemIndex(child)]
375
+ }
376
+
377
+ List.prototype.setItem = function (child, content) {
378
+ content = typeof content === 'string' ? content : content.getContent()
379
+ const i = this.getItemIndex(child)
380
+ if (!~i) {
381
+ return
382
+ }
383
+ this.items[i].setContent(content)
384
+ this.ritems[i] = content
385
+ }
386
+
387
+ List.prototype.clearItems = function () {
388
+ return this.setItems([])
389
+ }
390
+
391
+ List.prototype.setItems = function (items) {
392
+ let original = this.items.slice(),
393
+ selected = this.selected,
394
+ sel = this.ritems[this.selected],
395
+ i = 0
396
+
397
+ items = items.slice()
398
+
399
+ this.select(0)
400
+
401
+ for (; i < items.length; i++) {
402
+ if (this.items[i]) {
403
+ this.items[i].setContent(items[i])
404
+ } else {
405
+ this.add(items[i])
406
+ }
407
+ }
408
+
409
+ for (; i < original.length; i++) {
410
+ this.remove(original[i])
411
+ }
412
+
413
+ this.ritems = items
414
+
415
+ // Try to find our old item if it still exists.
416
+ sel = items.indexOf(sel)
417
+ if (~sel) {
418
+ this.select(sel)
419
+ } else if (items.length === original.length) {
420
+ this.select(selected)
421
+ } else {
422
+ this.select(Math.min(selected, items.length - 1))
423
+ }
424
+
425
+ this.emit('set items')
426
+ }
427
+
428
+ List.prototype.pushItem = function (content) {
429
+ this.appendItem(content)
430
+ return this.items.length
431
+ }
432
+
433
+ List.prototype.popItem = function () {
434
+ return this.removeItem(this.items.length - 1)
435
+ }
436
+
437
+ List.prototype.unshiftItem = function (content) {
438
+ this.insertItem(0, content)
439
+ return this.items.length
440
+ }
441
+
442
+ List.prototype.shiftItem = function () {
443
+ return this.removeItem(0)
444
+ }
445
+
446
+ List.prototype.spliceItem = function (child, n) {
447
+ const self = this
448
+ let i = this.getItemIndex(child)
449
+ if (!~i) {
450
+ return
451
+ }
452
+ const items = Array.prototype.slice.call(arguments, 2)
453
+ const removed = []
454
+ while (n--) {
455
+ removed.push(this.removeItem(i))
456
+ }
457
+ items.forEach(function (item) {
458
+ self.insertItem(i++, item)
459
+ })
460
+ return removed
461
+ }
462
+
463
+ List.prototype.find = List.prototype.fuzzyFind = function (search, back) {
464
+ let start = this.selected + (back ? -1 : 1),
465
+ i
466
+
467
+ if (typeof search === 'number') {
468
+ search += ''
469
+ }
470
+
471
+ if (search && search[0] === '/' && search[search.length - 1] === '/') {
472
+ try {
473
+ search = new RegExp(search.slice(1, -1))
474
+ } catch (e) {}
475
+ }
476
+
477
+ const test =
478
+ typeof search === 'string'
479
+ ? function (item) {
480
+ return !!~item.indexOf(search)
481
+ }
482
+ : search.test
483
+ ? search.test.bind(search)
484
+ : search
485
+
486
+ if (typeof test !== 'function') {
487
+ if (this.screen.options.debug) {
488
+ throw new Error('fuzzyFind(): `test` is not a function.')
489
+ }
490
+ return this.selected
491
+ }
492
+
493
+ if (!back) {
494
+ for (i = start; i < this.ritems.length; i++) {
495
+ if (test(helpers.cleanTags(this.ritems[i]))) {
496
+ return i
497
+ }
498
+ }
499
+ for (i = 0; i < start; i++) {
500
+ if (test(helpers.cleanTags(this.ritems[i]))) {
501
+ return i
502
+ }
503
+ }
504
+ } else {
505
+ for (i = start; i >= 0; i--) {
506
+ if (test(helpers.cleanTags(this.ritems[i]))) {
507
+ return i
508
+ }
509
+ }
510
+ for (i = this.ritems.length - 1; i > start; i--) {
511
+ if (test(helpers.cleanTags(this.ritems[i]))) {
512
+ return i
513
+ }
514
+ }
515
+ }
516
+
517
+ return this.selected
518
+ }
519
+
520
+ List.prototype.getItemIndex = function (child) {
521
+ if (typeof child === 'number') {
522
+ return child
523
+ } else if (typeof child === 'string') {
524
+ let i = this.ritems.indexOf(child)
525
+ if (~i) {
526
+ return i
527
+ }
528
+ for (i = 0; i < this.ritems.length; i++) {
529
+ if (helpers.cleanTags(this.ritems[i]) === child) {
530
+ return i
531
+ }
532
+ }
533
+ return -1
534
+ } else {
535
+ return this.items.indexOf(child)
536
+ }
537
+ }
538
+
539
+ List.prototype.select = function (index) {
540
+ if (!this.interactive) {
541
+ return
542
+ }
543
+
544
+ if (!this.items.length) {
545
+ this.selected = 0
546
+ this.value = ''
547
+ this.scrollTo(0)
548
+ return
549
+ }
550
+
551
+ if (typeof index === 'object') {
552
+ index = this.items.indexOf(index)
553
+ }
554
+
555
+ if (index < 0) {
556
+ index = 0
557
+ } else if (index >= this.items.length) {
558
+ index = this.items.length - 1
559
+ }
560
+
561
+ if (this.selected === index && this._listInitialized) {
562
+ return
563
+ }
564
+ this._listInitialized = true
565
+
566
+ this.selected = index
567
+ this.value = helpers.cleanTags(this.ritems[this.selected])
568
+ if (!this.parent) {
569
+ return
570
+ }
571
+ this.scrollTo(this.selected)
572
+
573
+ // XXX Move `action` and `select` events here.
574
+ this.emit('select item', this.items[this.selected], this.selected)
575
+ }
576
+
577
+ List.prototype.move = function (offset) {
578
+ this.select(this.selected + offset)
579
+ }
580
+
581
+ List.prototype.up = function (offset) {
582
+ this.move(-(offset || 1))
583
+ }
584
+
585
+ List.prototype.down = function (offset) {
586
+ this.move(offset || 1)
587
+ }
588
+
589
+ List.prototype.pick = function (label, callback) {
590
+ if (!callback) {
591
+ callback = label
592
+ label = null
593
+ }
594
+
595
+ if (!this.interactive) {
596
+ return callback()
597
+ }
598
+
599
+ const self = this
600
+ const focused = this.screen.focused
601
+ if (focused && focused._done) {
602
+ focused._done('stop')
603
+ }
604
+ this.screen.saveFocus()
605
+
606
+ // XXX Keep above:
607
+ // var parent = this.parent;
608
+ // this.detach();
609
+ // parent.append(this);
610
+
611
+ this.focus()
612
+ this.show()
613
+ this.select(0)
614
+ if (label) {
615
+ this.setLabel(label)
616
+ }
617
+ this.screen.render()
618
+ this.once('action', function (el, selected) {
619
+ if (label) {
620
+ self.removeLabel()
621
+ }
622
+ self.screen.restoreFocus()
623
+ self.hide()
624
+ self.screen.render()
625
+ if (!el) {
626
+ return callback()
627
+ }
628
+ return callback(null, helpers.cleanTags(self.ritems[selected]))
629
+ })
630
+ }
631
+
632
+ List.prototype.enterSelected = function (i) {
633
+ if (i != null) {
634
+ this.select(i)
635
+ }
636
+ this.emit('action', this.items[this.selected], this.selected)
637
+ this.emit('select', this.items[this.selected], this.selected)
638
+ }
639
+
640
+ List.prototype.cancelSelected = function (i) {
641
+ if (i != null) {
642
+ this.select(i)
643
+ }
644
+ this.emit('action')
645
+ this.emit('cancel')
646
+ }
647
+
648
+ /**
649
+ * Expose
650
+ */
651
+
652
+ module.exports = List