@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.
- package/dist/blessed/LICENSE +20 -0
- package/dist/blessed/lib/alias.js +519 -0
- package/dist/blessed/lib/blessed.js +32 -0
- package/dist/blessed/lib/colors.js +490 -0
- package/dist/blessed/lib/events.js +195 -0
- package/dist/blessed/lib/gpmclient.js +245 -0
- package/dist/blessed/lib/helpers.js +170 -0
- package/dist/blessed/lib/keys.js +512 -0
- package/dist/blessed/lib/program.js +4530 -0
- package/dist/blessed/lib/tput.js +3111 -0
- package/dist/blessed/lib/unicode.js +912 -0
- package/dist/blessed/lib/widget.js +60 -0
- package/dist/blessed/lib/widgets/ansiimage.js +173 -0
- package/dist/blessed/lib/widgets/bigtext.js +170 -0
- package/dist/blessed/lib/widgets/box.js +34 -0
- package/dist/blessed/lib/widgets/button.js +62 -0
- package/dist/blessed/lib/widgets/checkbox.js +95 -0
- package/dist/blessed/lib/widgets/element.js +2871 -0
- package/dist/blessed/lib/widgets/filemanager.js +223 -0
- package/dist/blessed/lib/widgets/form.js +301 -0
- package/dist/blessed/lib/widgets/image.js +71 -0
- package/dist/blessed/lib/widgets/input.js +34 -0
- package/dist/blessed/lib/widgets/layout.js +249 -0
- package/dist/blessed/lib/widgets/line.js +59 -0
- package/dist/blessed/lib/widgets/list.js +652 -0
- package/dist/blessed/lib/widgets/listbar.js +452 -0
- package/dist/blessed/lib/widgets/listtable.js +265 -0
- package/dist/blessed/lib/widgets/loading.js +88 -0
- package/dist/blessed/lib/widgets/log.js +82 -0
- package/dist/blessed/lib/widgets/message.js +145 -0
- package/dist/blessed/lib/widgets/node.js +314 -0
- package/dist/blessed/lib/widgets/overlayimage.js +794 -0
- package/dist/blessed/lib/widgets/progressbar.js +166 -0
- package/dist/blessed/lib/widgets/prompt.js +127 -0
- package/dist/blessed/lib/widgets/question.js +129 -0
- package/dist/blessed/lib/widgets/radiobutton.js +62 -0
- package/dist/blessed/lib/widgets/radioset.js +36 -0
- package/dist/blessed/lib/widgets/screen.js +2485 -0
- package/dist/blessed/lib/widgets/scrollablebox.js +415 -0
- package/dist/blessed/lib/widgets/scrollabletext.js +35 -0
- package/dist/blessed/lib/widgets/table.js +383 -0
- package/dist/blessed/lib/widgets/terminal.js +452 -0
- package/dist/blessed/lib/widgets/text.js +35 -0
- package/dist/blessed/lib/widgets/textarea.js +376 -0
- package/dist/blessed/lib/widgets/textbox.js +79 -0
- package/dist/blessed/lib/widgets/video.js +130 -0
- package/dist/blessed/usr/fonts/AUTHORS +1 -0
- package/dist/blessed/usr/fonts/LICENSE +94 -0
- package/dist/blessed/usr/fonts/README +340 -0
- package/dist/blessed/usr/fonts/ter-u14b.json +17826 -0
- package/dist/blessed/usr/fonts/ter-u14n.json +17826 -0
- 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 +243 -0
- package/dist/blessed/usr/xterm.terminfo +1977 -0
- package/dist/blessed/vendor/tng.js +1876 -0
- package/dist/blessed-contrib/LICENSE.md +21 -0
- package/dist/blessed-contrib/lib/layout/carousel.js +82 -0
- package/dist/blessed-contrib/lib/layout/grid.js +46 -0
- package/dist/blessed-contrib/lib/server-utils.js +83 -0
- package/dist/blessed-contrib/lib/utils.js +73 -0
- package/dist/blessed-contrib/lib/widget/canvas.js +52 -0
- package/dist/blessed-contrib/lib/widget/charts/bar.js +99 -0
- package/dist/blessed-contrib/lib/widget/charts/line.js +311 -0
- package/dist/blessed-contrib/lib/widget/charts/stacked-bar.js +245 -0
- package/dist/blessed-contrib/lib/widget/donut.js +183 -0
- package/dist/blessed-contrib/lib/widget/gauge-list.js +111 -0
- package/dist/blessed-contrib/lib/widget/gauge.js +127 -0
- package/dist/blessed-contrib/lib/widget/lcd.js +497 -0
- package/dist/blessed-contrib/lib/widget/log.js +32 -0
- package/dist/blessed-contrib/lib/widget/map.js +97 -0
- package/dist/blessed-contrib/lib/widget/markdown.js +68 -0
- package/dist/blessed-contrib/lib/widget/picture.js +61 -0
- package/dist/blessed-contrib/lib/widget/sparkline.js +66 -0
- package/dist/blessed-contrib/lib/widget/table.js +141 -0
- package/dist/blessed-contrib/lib/widget/tree.js +179 -0
- package/dist/blessed-contrib/node_modules/ansi-regex/index.js +6 -0
- package/dist/blessed-contrib/node_modules/ansi-regex/license +21 -0
- package/dist/blessed-contrib/node_modules/ansi-regex/package.json +64 -0
- package/dist/blessed-contrib/node_modules/ansi-regex/readme.md +39 -0
- package/dist/blessed-contrib/node_modules/ansi-styles/index.js +67 -0
- package/dist/blessed-contrib/node_modules/ansi-styles/license +21 -0
- package/dist/blessed-contrib/node_modules/ansi-styles/package.json +50 -0
- package/dist/blessed-contrib/node_modules/ansi-styles/readme.md +86 -0
- package/dist/blessed-contrib/node_modules/chalk/index.js +118 -0
- package/dist/blessed-contrib/node_modules/chalk/license +21 -0
- package/dist/blessed-contrib/node_modules/chalk/package.json +70 -0
- package/dist/blessed-contrib/node_modules/chalk/readme.md +213 -0
- package/dist/blessed-contrib/node_modules/escape-string-regexp/index.js +13 -0
- package/dist/blessed-contrib/node_modules/escape-string-regexp/license +21 -0
- package/dist/blessed-contrib/node_modules/escape-string-regexp/package.json +41 -0
- package/dist/blessed-contrib/node_modules/escape-string-regexp/readme.md +27 -0
- package/dist/blessed-contrib/node_modules/strip-ansi/index.js +8 -0
- package/dist/blessed-contrib/node_modules/strip-ansi/license +21 -0
- package/dist/blessed-contrib/node_modules/strip-ansi/package.json +57 -0
- package/dist/blessed-contrib/node_modules/strip-ansi/readme.md +33 -0
- package/dist/blessed-contrib/node_modules/supports-color/index.js +52 -0
- package/dist/blessed-contrib/node_modules/supports-color/license +21 -0
- package/dist/blessed-contrib/node_modules/supports-color/package.json +49 -0
- package/dist/blessed-contrib/node_modules/supports-color/readme.md +36 -0
- package/dist/cli.js +9 -8
- package/dist/cli.js.map +1 -1
- package/dist/instrument-with-sentry.js +2 -2
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/shadow-npm-inject.js +2 -2
- package/dist/shadow-npm-inject.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,794 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* overlayimage.js - w3m image 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 fs = require('node:fs'),
|
|
12
|
+
cp = require('node:child_process')
|
|
13
|
+
|
|
14
|
+
const helpers = require('../helpers')
|
|
15
|
+
|
|
16
|
+
const Node = require('./node')
|
|
17
|
+
const Box = require('./box')
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* OverlayImage
|
|
21
|
+
* Good example of w3mimgdisplay commands:
|
|
22
|
+
* https://github.com/hut/ranger/blob/master/ranger/ext/img_display.py
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
function OverlayImage(options) {
|
|
26
|
+
const self = this
|
|
27
|
+
|
|
28
|
+
if (!(this instanceof Node)) {
|
|
29
|
+
return new OverlayImage(options)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
options = options || {}
|
|
33
|
+
|
|
34
|
+
Box.call(this, options)
|
|
35
|
+
|
|
36
|
+
if (options.w3m) {
|
|
37
|
+
OverlayImage.w3mdisplay = options.w3m
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (OverlayImage.hasW3MDisplay == null) {
|
|
41
|
+
if (fs.existsSync(OverlayImage.w3mdisplay)) {
|
|
42
|
+
OverlayImage.hasW3MDisplay = true
|
|
43
|
+
} else if (options.search !== false) {
|
|
44
|
+
const file =
|
|
45
|
+
helpers.findFile('/usr', 'w3mimgdisplay') ||
|
|
46
|
+
helpers.findFile('/lib', 'w3mimgdisplay') ||
|
|
47
|
+
helpers.findFile('/bin', 'w3mimgdisplay')
|
|
48
|
+
if (file) {
|
|
49
|
+
OverlayImage.hasW3MDisplay = true
|
|
50
|
+
OverlayImage.w3mdisplay = file
|
|
51
|
+
} else {
|
|
52
|
+
OverlayImage.hasW3MDisplay = false
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.on('hide', function () {
|
|
58
|
+
self._lastFile = self.file
|
|
59
|
+
self.clearImage()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
this.on('show', function () {
|
|
63
|
+
if (!self._lastFile) {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
self.setImage(self._lastFile)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
this.on('detach', function () {
|
|
70
|
+
self._lastFile = self.file
|
|
71
|
+
self.clearImage()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
this.on('attach', function () {
|
|
75
|
+
if (!self._lastFile) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
self.setImage(self._lastFile)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
this.onScreenEvent('resize', function () {
|
|
82
|
+
self._needsRatio = true
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// Get images to overlap properly. Maybe not worth it:
|
|
86
|
+
// this.onScreenEvent('render', function() {
|
|
87
|
+
// self.screen.program.flush();
|
|
88
|
+
// if (!self._noImage) return;
|
|
89
|
+
// function display(el, next) {
|
|
90
|
+
// if (el.type === 'w3mimage' && el.file) {
|
|
91
|
+
// el.setImage(el.file, next);
|
|
92
|
+
// } else {
|
|
93
|
+
// next();
|
|
94
|
+
// }
|
|
95
|
+
// }
|
|
96
|
+
// function done(el) {
|
|
97
|
+
// el.children.forEach(recurse);
|
|
98
|
+
// }
|
|
99
|
+
// function recurse(el) {
|
|
100
|
+
// display(el, function() {
|
|
101
|
+
// var pending = el.children.length;
|
|
102
|
+
// el.children.forEach(function(el) {
|
|
103
|
+
// display(el, function() {
|
|
104
|
+
// if (!--pending) done(el);
|
|
105
|
+
// });
|
|
106
|
+
// });
|
|
107
|
+
// });
|
|
108
|
+
// }
|
|
109
|
+
// recurse(self.screen);
|
|
110
|
+
// });
|
|
111
|
+
|
|
112
|
+
this.onScreenEvent('render', function () {
|
|
113
|
+
self.screen.program.flush()
|
|
114
|
+
if (!self._noImage) {
|
|
115
|
+
self.setImage(self.file)
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
if (this.options.file || this.options.img) {
|
|
120
|
+
this.setImage(this.options.file || this.options.img)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
Object.setPrototypeOf(OverlayImage.prototype, Box.prototype)
|
|
125
|
+
|
|
126
|
+
OverlayImage.prototype.type = 'overlayimage'
|
|
127
|
+
|
|
128
|
+
OverlayImage.w3mdisplay = '/usr/lib/w3m/w3mimgdisplay'
|
|
129
|
+
|
|
130
|
+
OverlayImage.prototype.spawn = function (file, args, opt, callback) {
|
|
131
|
+
let spawn = require('node:child_process').spawn,
|
|
132
|
+
ps
|
|
133
|
+
|
|
134
|
+
opt = opt || {}
|
|
135
|
+
ps = spawn(file, args, opt)
|
|
136
|
+
|
|
137
|
+
ps.on('error', function (err) {
|
|
138
|
+
if (!callback) {
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
return callback(err)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
ps.on('exit', function (code) {
|
|
145
|
+
if (!callback) {
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
if (code !== 0) {
|
|
149
|
+
return callback(new Error('Exit Code: ' + code))
|
|
150
|
+
}
|
|
151
|
+
return callback(null, code === 0)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
return ps
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
OverlayImage.prototype.setImage = function (img, callback) {
|
|
158
|
+
const self = this
|
|
159
|
+
|
|
160
|
+
if (this._settingImage) {
|
|
161
|
+
this._queue = this._queue || []
|
|
162
|
+
this._queue.push([img, callback])
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
this._settingImage = true
|
|
166
|
+
|
|
167
|
+
const reset = function () {
|
|
168
|
+
self._settingImage = false
|
|
169
|
+
self._queue = self._queue || []
|
|
170
|
+
const item = self._queue.shift()
|
|
171
|
+
if (item) {
|
|
172
|
+
self.setImage(item[0], item[1])
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (OverlayImage.hasW3MDisplay === false) {
|
|
177
|
+
reset()
|
|
178
|
+
if (!callback) {
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
return callback(new Error('W3M Image Display not available.'))
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!img) {
|
|
185
|
+
reset()
|
|
186
|
+
if (!callback) {
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
return callback(new Error('No image.'))
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.file = img
|
|
193
|
+
|
|
194
|
+
return this.getPixelRatio(function (err, ratio) {
|
|
195
|
+
if (err) {
|
|
196
|
+
reset()
|
|
197
|
+
if (!callback) {
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
return callback(err)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return self.renderImage(img, ratio, function (err, success) {
|
|
204
|
+
if (err) {
|
|
205
|
+
reset()
|
|
206
|
+
if (!callback) {
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
return callback(err)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (self.shrink || self.options.autofit) {
|
|
213
|
+
delete self.shrink
|
|
214
|
+
delete self.options.shrink
|
|
215
|
+
self.options.autofit = true
|
|
216
|
+
return self.imageSize(function (err, size) {
|
|
217
|
+
if (err) {
|
|
218
|
+
reset()
|
|
219
|
+
if (!callback) {
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
return callback(err)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (
|
|
226
|
+
self._lastSize &&
|
|
227
|
+
ratio.tw === self._lastSize.tw &&
|
|
228
|
+
ratio.th === self._lastSize.th &&
|
|
229
|
+
size.width === self._lastSize.width &&
|
|
230
|
+
size.height === self._lastSize.height &&
|
|
231
|
+
self.aleft === self._lastSize.aleft &&
|
|
232
|
+
self.atop === self._lastSize.atop
|
|
233
|
+
) {
|
|
234
|
+
reset()
|
|
235
|
+
if (!callback) {
|
|
236
|
+
return
|
|
237
|
+
}
|
|
238
|
+
return callback(null, success)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
self._lastSize = {
|
|
242
|
+
tw: ratio.tw,
|
|
243
|
+
th: ratio.th,
|
|
244
|
+
width: size.width,
|
|
245
|
+
height: size.height,
|
|
246
|
+
aleft: self.aleft,
|
|
247
|
+
atop: self.atop
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
self.position.width = (size.width / ratio.tw) | 0
|
|
251
|
+
self.position.height = (size.height / ratio.th) | 0
|
|
252
|
+
|
|
253
|
+
self._noImage = true
|
|
254
|
+
self.screen.render()
|
|
255
|
+
self._noImage = false
|
|
256
|
+
|
|
257
|
+
reset()
|
|
258
|
+
return self.renderImage(img, ratio, callback)
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
reset()
|
|
263
|
+
if (!callback) {
|
|
264
|
+
return
|
|
265
|
+
}
|
|
266
|
+
return callback(null, success)
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
OverlayImage.prototype.renderImage = function (img, ratio, callback) {
|
|
272
|
+
const self = this
|
|
273
|
+
|
|
274
|
+
if (cp.execSync) {
|
|
275
|
+
callback =
|
|
276
|
+
callback ||
|
|
277
|
+
function (err, result) {
|
|
278
|
+
return result
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
return callback(null, this.renderImageSync(img, ratio))
|
|
282
|
+
} catch (e) {
|
|
283
|
+
return callback(e)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (OverlayImage.hasW3MDisplay === false) {
|
|
288
|
+
if (!callback) {
|
|
289
|
+
return
|
|
290
|
+
}
|
|
291
|
+
return callback(new Error('W3M Image Display not available.'))
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (!ratio) {
|
|
295
|
+
if (!callback) {
|
|
296
|
+
return
|
|
297
|
+
}
|
|
298
|
+
return callback(new Error('No ratio.'))
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// clearImage unsets these:
|
|
302
|
+
const _file = self.file
|
|
303
|
+
const _lastSize = self._lastSize
|
|
304
|
+
return self.clearImage(function (err) {
|
|
305
|
+
if (err) {
|
|
306
|
+
return callback(err)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
self.file = _file
|
|
310
|
+
self._lastSize = _lastSize
|
|
311
|
+
|
|
312
|
+
const opt = {
|
|
313
|
+
stdio: 'pipe',
|
|
314
|
+
env: process.env,
|
|
315
|
+
cwd: process.env.HOME
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const ps = self.spawn(
|
|
319
|
+
OverlayImage.w3mdisplay,
|
|
320
|
+
[],
|
|
321
|
+
opt,
|
|
322
|
+
function (err, success) {
|
|
323
|
+
if (!callback) {
|
|
324
|
+
return
|
|
325
|
+
}
|
|
326
|
+
return err ? callback(err) : callback(null, success)
|
|
327
|
+
}
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
const width = (self.width * ratio.tw) | 0,
|
|
331
|
+
height = (self.height * ratio.th) | 0,
|
|
332
|
+
aleft = (self.aleft * ratio.tw) | 0,
|
|
333
|
+
atop = (self.atop * ratio.th) | 0
|
|
334
|
+
|
|
335
|
+
const input =
|
|
336
|
+
'0;1;' +
|
|
337
|
+
aleft +
|
|
338
|
+
';' +
|
|
339
|
+
atop +
|
|
340
|
+
';' +
|
|
341
|
+
width +
|
|
342
|
+
';' +
|
|
343
|
+
height +
|
|
344
|
+
';;;;;' +
|
|
345
|
+
img +
|
|
346
|
+
'\n4;\n3;\n'
|
|
347
|
+
|
|
348
|
+
self._props = {
|
|
349
|
+
aleft: aleft,
|
|
350
|
+
atop: atop,
|
|
351
|
+
width: width,
|
|
352
|
+
height: height
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
ps.stdin.write(input)
|
|
356
|
+
ps.stdin.end()
|
|
357
|
+
})
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
OverlayImage.prototype.clearImage = function (callback) {
|
|
361
|
+
if (cp.execSync) {
|
|
362
|
+
callback =
|
|
363
|
+
callback ||
|
|
364
|
+
function (err, result) {
|
|
365
|
+
return result
|
|
366
|
+
}
|
|
367
|
+
try {
|
|
368
|
+
return callback(null, this.clearImageSync())
|
|
369
|
+
} catch (e) {
|
|
370
|
+
return callback(e)
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (OverlayImage.hasW3MDisplay === false) {
|
|
375
|
+
if (!callback) {
|
|
376
|
+
return
|
|
377
|
+
}
|
|
378
|
+
return callback(new Error('W3M Image Display not available.'))
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (!this._props) {
|
|
382
|
+
if (!callback) {
|
|
383
|
+
return
|
|
384
|
+
}
|
|
385
|
+
return callback(null)
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const opt = {
|
|
389
|
+
stdio: 'pipe',
|
|
390
|
+
env: process.env,
|
|
391
|
+
cwd: process.env.HOME
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const ps = this.spawn(
|
|
395
|
+
OverlayImage.w3mdisplay,
|
|
396
|
+
[],
|
|
397
|
+
opt,
|
|
398
|
+
function (err, success) {
|
|
399
|
+
if (!callback) {
|
|
400
|
+
return
|
|
401
|
+
}
|
|
402
|
+
return err ? callback(err) : callback(null, success)
|
|
403
|
+
}
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
let width = this._props.width + 2,
|
|
407
|
+
height = this._props.height + 2,
|
|
408
|
+
aleft = this._props.aleft,
|
|
409
|
+
atop = this._props.atop
|
|
410
|
+
|
|
411
|
+
if (this._drag) {
|
|
412
|
+
aleft -= 10
|
|
413
|
+
atop -= 10
|
|
414
|
+
width += 10
|
|
415
|
+
height += 10
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const input =
|
|
419
|
+
'6;' + aleft + ';' + atop + ';' + width + ';' + height + '\n4;\n3;\n'
|
|
420
|
+
|
|
421
|
+
delete this.file
|
|
422
|
+
delete this._props
|
|
423
|
+
delete this._lastSize
|
|
424
|
+
|
|
425
|
+
ps.stdin.write(input)
|
|
426
|
+
ps.stdin.end()
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
OverlayImage.prototype.imageSize = function (callback) {
|
|
430
|
+
const img = this.file
|
|
431
|
+
|
|
432
|
+
if (cp.execSync) {
|
|
433
|
+
callback =
|
|
434
|
+
callback ||
|
|
435
|
+
function (err, result) {
|
|
436
|
+
return result
|
|
437
|
+
}
|
|
438
|
+
try {
|
|
439
|
+
return callback(null, this.imageSizeSync())
|
|
440
|
+
} catch (e) {
|
|
441
|
+
return callback(e)
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (OverlayImage.hasW3MDisplay === false) {
|
|
446
|
+
if (!callback) {
|
|
447
|
+
return
|
|
448
|
+
}
|
|
449
|
+
return callback(new Error('W3M Image Display not available.'))
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (!img) {
|
|
453
|
+
if (!callback) {
|
|
454
|
+
return
|
|
455
|
+
}
|
|
456
|
+
return callback(new Error('No image.'))
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const opt = {
|
|
460
|
+
stdio: 'pipe',
|
|
461
|
+
env: process.env,
|
|
462
|
+
cwd: process.env.HOME
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const ps = this.spawn(OverlayImage.w3mdisplay, [], opt)
|
|
466
|
+
|
|
467
|
+
let buf = ''
|
|
468
|
+
|
|
469
|
+
ps.stdout.setEncoding('utf8')
|
|
470
|
+
|
|
471
|
+
ps.stdout.on('data', function (data) {
|
|
472
|
+
buf += data
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
ps.on('error', function (err) {
|
|
476
|
+
if (!callback) {
|
|
477
|
+
return
|
|
478
|
+
}
|
|
479
|
+
return callback(err)
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
ps.on('exit', function () {
|
|
483
|
+
if (!callback) {
|
|
484
|
+
return
|
|
485
|
+
}
|
|
486
|
+
const size = buf.trim().split(/\s+/)
|
|
487
|
+
return callback(null, {
|
|
488
|
+
raw: buf.trim(),
|
|
489
|
+
width: +size[0],
|
|
490
|
+
height: +size[1]
|
|
491
|
+
})
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
const input = '5;' + img + '\n'
|
|
495
|
+
|
|
496
|
+
ps.stdin.write(input)
|
|
497
|
+
ps.stdin.end()
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
OverlayImage.prototype.termSize = function (callback) {
|
|
501
|
+
const self = this
|
|
502
|
+
|
|
503
|
+
if (cp.execSync) {
|
|
504
|
+
callback =
|
|
505
|
+
callback ||
|
|
506
|
+
function (err, result) {
|
|
507
|
+
return result
|
|
508
|
+
}
|
|
509
|
+
try {
|
|
510
|
+
return callback(null, this.termSizeSync())
|
|
511
|
+
} catch (e) {
|
|
512
|
+
return callback(e)
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (OverlayImage.hasW3MDisplay === false) {
|
|
517
|
+
if (!callback) {
|
|
518
|
+
return
|
|
519
|
+
}
|
|
520
|
+
return callback(new Error('W3M Image Display not available.'))
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const opt = {
|
|
524
|
+
stdio: 'pipe',
|
|
525
|
+
env: process.env,
|
|
526
|
+
cwd: process.env.HOME
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const ps = this.spawn(OverlayImage.w3mdisplay, ['-test'], opt)
|
|
530
|
+
|
|
531
|
+
let buf = ''
|
|
532
|
+
|
|
533
|
+
ps.stdout.setEncoding('utf8')
|
|
534
|
+
|
|
535
|
+
ps.stdout.on('data', function (data) {
|
|
536
|
+
buf += data
|
|
537
|
+
})
|
|
538
|
+
|
|
539
|
+
ps.on('error', function (err) {
|
|
540
|
+
if (!callback) {
|
|
541
|
+
return
|
|
542
|
+
}
|
|
543
|
+
return callback(err)
|
|
544
|
+
})
|
|
545
|
+
|
|
546
|
+
ps.on('exit', function () {
|
|
547
|
+
if (!callback) {
|
|
548
|
+
return
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (!buf.trim()) {
|
|
552
|
+
// Bug: w3mimgdisplay will sometimes
|
|
553
|
+
// output nothing. Try again:
|
|
554
|
+
return self.termSize(callback)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const size = buf.trim().split(/\s+/)
|
|
558
|
+
|
|
559
|
+
return callback(null, {
|
|
560
|
+
raw: buf.trim(),
|
|
561
|
+
width: +size[0],
|
|
562
|
+
height: +size[1]
|
|
563
|
+
})
|
|
564
|
+
})
|
|
565
|
+
|
|
566
|
+
ps.stdin.end()
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
OverlayImage.prototype.getPixelRatio = function (callback) {
|
|
570
|
+
const self = this
|
|
571
|
+
|
|
572
|
+
if (cp.execSync) {
|
|
573
|
+
callback =
|
|
574
|
+
callback ||
|
|
575
|
+
function (err, result) {
|
|
576
|
+
return result
|
|
577
|
+
}
|
|
578
|
+
try {
|
|
579
|
+
return callback(null, this.getPixelRatioSync())
|
|
580
|
+
} catch (e) {
|
|
581
|
+
return callback(e)
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// XXX We could cache this, but sometimes it's better
|
|
586
|
+
// to recalculate to be pixel perfect.
|
|
587
|
+
if (this._ratio && !this._needsRatio) {
|
|
588
|
+
return callback(null, this._ratio)
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
return this.termSize(function (err, dimensions) {
|
|
592
|
+
if (err) {
|
|
593
|
+
return callback(err)
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
self._ratio = {
|
|
597
|
+
tw: dimensions.width / self.screen.width,
|
|
598
|
+
th: dimensions.height / self.screen.height
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
self._needsRatio = false
|
|
602
|
+
|
|
603
|
+
return callback(null, self._ratio)
|
|
604
|
+
})
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
OverlayImage.prototype.renderImageSync = function (img, ratio) {
|
|
608
|
+
if (OverlayImage.hasW3MDisplay === false) {
|
|
609
|
+
throw new Error('W3M Image Display not available.')
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
if (!ratio) {
|
|
613
|
+
throw new Error('No ratio.')
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// clearImage unsets these:
|
|
617
|
+
const _file = this.file
|
|
618
|
+
const _lastSize = this._lastSize
|
|
619
|
+
|
|
620
|
+
this.clearImageSync()
|
|
621
|
+
|
|
622
|
+
this.file = _file
|
|
623
|
+
this._lastSize = _lastSize
|
|
624
|
+
|
|
625
|
+
const width = (this.width * ratio.tw) | 0,
|
|
626
|
+
height = (this.height * ratio.th) | 0,
|
|
627
|
+
aleft = (this.aleft * ratio.tw) | 0,
|
|
628
|
+
atop = (this.atop * ratio.th) | 0
|
|
629
|
+
|
|
630
|
+
const input =
|
|
631
|
+
'0;1;' +
|
|
632
|
+
aleft +
|
|
633
|
+
';' +
|
|
634
|
+
atop +
|
|
635
|
+
';' +
|
|
636
|
+
width +
|
|
637
|
+
';' +
|
|
638
|
+
height +
|
|
639
|
+
';;;;;' +
|
|
640
|
+
img +
|
|
641
|
+
'\n4;\n3;\n'
|
|
642
|
+
|
|
643
|
+
this._props = {
|
|
644
|
+
aleft: aleft,
|
|
645
|
+
atop: atop,
|
|
646
|
+
width: width,
|
|
647
|
+
height: height
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
try {
|
|
651
|
+
cp.execFileSync(OverlayImage.w3mdisplay, [], {
|
|
652
|
+
env: process.env,
|
|
653
|
+
encoding: 'utf8',
|
|
654
|
+
input: input,
|
|
655
|
+
timeout: 1000
|
|
656
|
+
})
|
|
657
|
+
} catch (e) {}
|
|
658
|
+
|
|
659
|
+
return true
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
OverlayImage.prototype.clearImageSync = function () {
|
|
663
|
+
if (OverlayImage.hasW3MDisplay === false) {
|
|
664
|
+
throw new Error('W3M Image Display not available.')
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
if (!this._props) {
|
|
668
|
+
return false
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
let width = this._props.width + 2,
|
|
672
|
+
height = this._props.height + 2,
|
|
673
|
+
aleft = this._props.aleft,
|
|
674
|
+
atop = this._props.atop
|
|
675
|
+
|
|
676
|
+
if (this._drag) {
|
|
677
|
+
aleft -= 10
|
|
678
|
+
atop -= 10
|
|
679
|
+
width += 10
|
|
680
|
+
height += 10
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const input =
|
|
684
|
+
'6;' + aleft + ';' + atop + ';' + width + ';' + height + '\n4;\n3;\n'
|
|
685
|
+
|
|
686
|
+
delete this.file
|
|
687
|
+
delete this._props
|
|
688
|
+
delete this._lastSize
|
|
689
|
+
|
|
690
|
+
try {
|
|
691
|
+
cp.execFileSync(OverlayImage.w3mdisplay, [], {
|
|
692
|
+
env: process.env,
|
|
693
|
+
encoding: 'utf8',
|
|
694
|
+
input: input,
|
|
695
|
+
timeout: 1000
|
|
696
|
+
})
|
|
697
|
+
} catch (e) {}
|
|
698
|
+
|
|
699
|
+
return true
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
OverlayImage.prototype.imageSizeSync = function () {
|
|
703
|
+
const img = this.file
|
|
704
|
+
|
|
705
|
+
if (OverlayImage.hasW3MDisplay === false) {
|
|
706
|
+
throw new Error('W3M Image Display not available.')
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
if (!img) {
|
|
710
|
+
throw new Error('No image.')
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
let buf = ''
|
|
714
|
+
const input = '5;' + img + '\n'
|
|
715
|
+
|
|
716
|
+
try {
|
|
717
|
+
buf = cp.execFileSync(OverlayImage.w3mdisplay, [], {
|
|
718
|
+
env: process.env,
|
|
719
|
+
encoding: 'utf8',
|
|
720
|
+
input: input,
|
|
721
|
+
timeout: 1000
|
|
722
|
+
})
|
|
723
|
+
} catch (e) {}
|
|
724
|
+
|
|
725
|
+
const size = buf.trim().split(/\s+/)
|
|
726
|
+
|
|
727
|
+
return {
|
|
728
|
+
raw: buf.trim(),
|
|
729
|
+
width: +size[0],
|
|
730
|
+
height: +size[1]
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
OverlayImage.prototype.termSizeSync = function (_, recurse) {
|
|
735
|
+
if (OverlayImage.hasW3MDisplay === false) {
|
|
736
|
+
throw new Error('W3M Image Display not available.')
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
let buf = ''
|
|
740
|
+
|
|
741
|
+
try {
|
|
742
|
+
buf = cp.execFileSync(OverlayImage.w3mdisplay, ['-test'], {
|
|
743
|
+
env: process.env,
|
|
744
|
+
encoding: 'utf8',
|
|
745
|
+
timeout: 1000
|
|
746
|
+
})
|
|
747
|
+
} catch (e) {}
|
|
748
|
+
|
|
749
|
+
if (!buf.trim()) {
|
|
750
|
+
// Bug: w3mimgdisplay will sometimes
|
|
751
|
+
// output nothing. Try again:
|
|
752
|
+
recurse = recurse || 0
|
|
753
|
+
if (++recurse === 5) {
|
|
754
|
+
throw new Error('Term size not determined.')
|
|
755
|
+
}
|
|
756
|
+
return this.termSizeSync(_, recurse)
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
const size = buf.trim().split(/\s+/)
|
|
760
|
+
|
|
761
|
+
return {
|
|
762
|
+
raw: buf.trim(),
|
|
763
|
+
width: +size[0],
|
|
764
|
+
height: +size[1]
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
OverlayImage.prototype.getPixelRatioSync = function () {
|
|
769
|
+
// XXX We could cache this, but sometimes it's better
|
|
770
|
+
// to recalculate to be pixel perfect.
|
|
771
|
+
if (this._ratio && !this._needsRatio) {
|
|
772
|
+
return this._ratio
|
|
773
|
+
}
|
|
774
|
+
this._needsRatio = false
|
|
775
|
+
|
|
776
|
+
const dimensions = this.termSizeSync()
|
|
777
|
+
|
|
778
|
+
this._ratio = {
|
|
779
|
+
tw: dimensions.width / this.screen.width,
|
|
780
|
+
th: dimensions.height / this.screen.height
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
return this._ratio
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
OverlayImage.prototype.displayImage = function (callback) {
|
|
787
|
+
return this.screen.displayImage(this.file, callback)
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Expose
|
|
792
|
+
*/
|
|
793
|
+
|
|
794
|
+
module.exports = OverlayImage
|