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