@socketsecurity/cli-with-sentry 0.14.137 → 0.14.138
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,21 @@
|
|
|
1
|
+
## MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Yaron Naveh and blessed-contrib contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
function Carousel(pages, options) {
|
|
3
|
+
this.currPage = 0
|
|
4
|
+
this.pages = pages
|
|
5
|
+
this.options = options
|
|
6
|
+
this.screen = this.options.screen
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
Carousel.prototype.move = function () {
|
|
10
|
+
let i = this.screen.children.length
|
|
11
|
+
while (i--) {
|
|
12
|
+
this.screen.children[i].detach()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
this.pages[this.currPage](this.screen, this.currPage)
|
|
16
|
+
this.screen.render()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Carousel.prototype.next = function () {
|
|
20
|
+
this.currPage++
|
|
21
|
+
if (this.currPage == this.pages.length) {
|
|
22
|
+
if (!this.options.rotate) {
|
|
23
|
+
this.currPage--
|
|
24
|
+
return
|
|
25
|
+
} else {
|
|
26
|
+
this.currPage = 0
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
this.move()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Carousel.prototype.prev = function () {
|
|
33
|
+
this.currPage--
|
|
34
|
+
if (this.currPage < 0) {
|
|
35
|
+
if (!this.options.rotate) {
|
|
36
|
+
this.currPage++
|
|
37
|
+
return
|
|
38
|
+
} else {
|
|
39
|
+
this.currPage = this.pages.length - 1
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
this.move()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Carousel.prototype.home = function () {
|
|
46
|
+
this.currPage = 0
|
|
47
|
+
this.move()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Carousel.prototype.end = function () {
|
|
51
|
+
this.currPage = this.pages.length - 1
|
|
52
|
+
this.move()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Carousel.prototype.start = function () {
|
|
56
|
+
const self = this
|
|
57
|
+
|
|
58
|
+
this.move()
|
|
59
|
+
|
|
60
|
+
if (this.options.interval) {
|
|
61
|
+
setInterval(this.next.bind(this), this.options.interval)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (this.options.controlKeys) {
|
|
65
|
+
this.screen.key(['right', 'left', 'home', 'end'], function (ch, key) {
|
|
66
|
+
if (key.name == 'right') {
|
|
67
|
+
self.next()
|
|
68
|
+
}
|
|
69
|
+
if (key.name == 'left') {
|
|
70
|
+
self.prev()
|
|
71
|
+
}
|
|
72
|
+
if (key.name == 'home') {
|
|
73
|
+
self.home()
|
|
74
|
+
}
|
|
75
|
+
if (key.name == 'end') {
|
|
76
|
+
self.end()
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = Carousel
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const utils = require('../utils')
|
|
3
|
+
|
|
4
|
+
const widgetSpacing = 0
|
|
5
|
+
|
|
6
|
+
function Grid(options) {
|
|
7
|
+
if (!options.screen) {
|
|
8
|
+
throw (
|
|
9
|
+
'Error: A screen property must be specified in the grid options.\r\n' +
|
|
10
|
+
'Note: Release 2.0.0 has breaking changes. Please refer to the README or to https://github.com/yaronn/blessed-contrib/issues/39'
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
this.options = options
|
|
14
|
+
this.options.dashboardMargin = this.options.dashboardMargin || 0
|
|
15
|
+
this.cellWidth = (100 - this.options.dashboardMargin * 2) / this.options.cols
|
|
16
|
+
this.cellHeight = (100 - this.options.dashboardMargin * 2) / this.options.rows
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Grid.prototype.set = function (row, col, rowSpan, colSpan, obj, opts) {
|
|
20
|
+
if (obj instanceof Grid) {
|
|
21
|
+
throw (
|
|
22
|
+
'Error: A Grid is not allowed to be nested inside another grid.\r\n' +
|
|
23
|
+
'Note: Release 2.0.0 has breaking changes. Please refer to the README or to https://github.com/yaronn/blessed-contrib/issues/39'
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const top = row * this.cellHeight + this.options.dashboardMargin
|
|
28
|
+
const left = col * this.cellWidth + this.options.dashboardMargin
|
|
29
|
+
|
|
30
|
+
//var options = JSON.parse(JSON.stringify(opts));
|
|
31
|
+
let options = {}
|
|
32
|
+
options = utils.MergeRecursive(options, opts)
|
|
33
|
+
options.top = top + '%'
|
|
34
|
+
options.left = left + '%'
|
|
35
|
+
options.width = this.cellWidth * colSpan - widgetSpacing + '%'
|
|
36
|
+
options.height = this.cellHeight * rowSpan - widgetSpacing + '%'
|
|
37
|
+
if (!this.options.hideBorder) {
|
|
38
|
+
options.border = { type: 'line', fg: this.options.color || 'cyan' }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const instance = obj(options)
|
|
42
|
+
this.options.screen.append(instance)
|
|
43
|
+
return instance
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = Grid
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
function OutputBuffer(options) {
|
|
4
|
+
this.isTTY = true
|
|
5
|
+
this.columns = options.cols
|
|
6
|
+
this.rows = options.rows
|
|
7
|
+
this.write = function (s) {
|
|
8
|
+
s = s.replace('\x1b8', '') //not clear from where in blessed this code comes from. It forces the terminal to clear and loose existing content.
|
|
9
|
+
options.res.write(s)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
this.on = function () {}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function InputBuffer() {
|
|
16
|
+
this.isTTY = true
|
|
17
|
+
this.isRaw = true
|
|
18
|
+
|
|
19
|
+
this.emit = function () {}
|
|
20
|
+
|
|
21
|
+
this.setRawMode = function () {}
|
|
22
|
+
this.resume = function () {}
|
|
23
|
+
this.pause = function () {}
|
|
24
|
+
|
|
25
|
+
this.on = function () {}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function serverError(req, res, err) {
|
|
29
|
+
setTimeout(function () {
|
|
30
|
+
if (!res.headersSent) {
|
|
31
|
+
res.writeHead(500, { 'Content-Type': 'text/plain' })
|
|
32
|
+
}
|
|
33
|
+
res.write('\r\n\r\n' + err + '\r\n\r\n')
|
|
34
|
+
//restore cursor
|
|
35
|
+
res.end('\u001b[?25h')
|
|
36
|
+
}, 0)
|
|
37
|
+
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function createScreen(req, res) {
|
|
42
|
+
const url = require('node:url')
|
|
43
|
+
const query = url.parse(req.url, true).query
|
|
44
|
+
|
|
45
|
+
const cols = query.cols || 250
|
|
46
|
+
const rows = query.rows || 50
|
|
47
|
+
|
|
48
|
+
if (cols <= 35 || cols >= 500 || rows <= 5 || rows >= 300) {
|
|
49
|
+
serverError(
|
|
50
|
+
req,
|
|
51
|
+
res,
|
|
52
|
+
'cols must be bigger than 35 and rows must be bigger than 5'
|
|
53
|
+
)
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
res.writeHead(200, { 'Content-Type': 'text/plain' })
|
|
58
|
+
|
|
59
|
+
const contrib = require('../index')
|
|
60
|
+
const output = new contrib.OutputBuffer({ res: res, cols: cols, rows: rows })
|
|
61
|
+
const input = new contrib.InputBuffer() //required to run under forever since it replaces stdin to non-tty
|
|
62
|
+
const Program = require('../../blessed/lib/program')
|
|
63
|
+
const program = new Program({ output: output, input: input })
|
|
64
|
+
|
|
65
|
+
if (query.terminal) {
|
|
66
|
+
program.terminal = query.terminal
|
|
67
|
+
}
|
|
68
|
+
if (query.isOSX) {
|
|
69
|
+
program.isOSXTerm = query.isOSX
|
|
70
|
+
}
|
|
71
|
+
if (query.isiTerm2) {
|
|
72
|
+
program.isiTerm2 = query.isiTerm2
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const ScreenWidget = require('../../blessed/lib/widgets/screen')
|
|
76
|
+
const screen = new ScreenWidget({ program: program })
|
|
77
|
+
return screen
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
exports.createScreen = createScreen
|
|
81
|
+
exports.OutputBuffer = OutputBuffer
|
|
82
|
+
exports.InputBuffer = InputBuffer
|
|
83
|
+
exports.serverError = serverError
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const x256 = require('x256')
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Recursively merge properties of two objects
|
|
6
|
+
*/
|
|
7
|
+
function MergeRecursive(obj1, obj2) {
|
|
8
|
+
if (obj1 == null) {
|
|
9
|
+
return obj2
|
|
10
|
+
}
|
|
11
|
+
if (obj2 == null) {
|
|
12
|
+
return obj1
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (const p in obj2) {
|
|
16
|
+
try {
|
|
17
|
+
// property in destination object set; update its value
|
|
18
|
+
if (obj2[p].constructor == Object) {
|
|
19
|
+
obj1[p] = MergeRecursive(obj1[p], obj2[p])
|
|
20
|
+
} else {
|
|
21
|
+
obj1[p] = obj2[p]
|
|
22
|
+
}
|
|
23
|
+
} catch (e) {
|
|
24
|
+
// property in destination object not set; create it and set its value
|
|
25
|
+
obj1[p] = obj2[p]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return obj1
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getTypeName(thing) {
|
|
33
|
+
if (thing === null) {
|
|
34
|
+
return '[object Null]'
|
|
35
|
+
} // special case
|
|
36
|
+
return Object.prototype.toString.call(thing)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function abbreviateNumber(value) {
|
|
40
|
+
let newValue = value
|
|
41
|
+
if (value >= 1000) {
|
|
42
|
+
const suffixes = ['', 'k', 'm', 'b', 't']
|
|
43
|
+
const suffixNum = Math.floor(('' + value).length / 3)
|
|
44
|
+
let shortValue = ''
|
|
45
|
+
for (let precision = 2; precision >= 1; precision--) {
|
|
46
|
+
shortValue = parseFloat(
|
|
47
|
+
(suffixNum != 0
|
|
48
|
+
? value / Math.pow(1000, suffixNum)
|
|
49
|
+
: value
|
|
50
|
+
).toPrecision(precision)
|
|
51
|
+
)
|
|
52
|
+
const dotLessShortValue = (shortValue + '').replace(/[^a-zA-Z 0-9]+/g, '')
|
|
53
|
+
if (dotLessShortValue.length <= 2) {
|
|
54
|
+
break
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
newValue = shortValue + suffixes[suffixNum]
|
|
58
|
+
}
|
|
59
|
+
return newValue
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getColorCode(color) {
|
|
63
|
+
if (Array.isArray(color) && color.length == 3) {
|
|
64
|
+
return x256(color[0], color[1], color[2])
|
|
65
|
+
} else {
|
|
66
|
+
return color
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
exports.MergeRecursive = MergeRecursive
|
|
71
|
+
exports.getTypeName = getTypeName
|
|
72
|
+
exports.abbreviateNumber = abbreviateNumber
|
|
73
|
+
exports.getColorCode = getColorCode
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const Box = require('../../../blessed/lib/widgets/box'),
|
|
3
|
+
InnerCanvas = require('drawille-canvas-blessed-contrib').Canvas,
|
|
4
|
+
Node = require('../../../blessed/lib/widgets/node')
|
|
5
|
+
|
|
6
|
+
function Canvas(options, canvasType) {
|
|
7
|
+
const self = this
|
|
8
|
+
|
|
9
|
+
if (!(this instanceof Node)) {
|
|
10
|
+
return new Canvas(options)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
options = options || {}
|
|
14
|
+
this.options = options
|
|
15
|
+
Box.call(this, options)
|
|
16
|
+
|
|
17
|
+
this.on('attach', function () {
|
|
18
|
+
self.calcSize()
|
|
19
|
+
|
|
20
|
+
self._canvas = new InnerCanvas(
|
|
21
|
+
this.canvasSize.width,
|
|
22
|
+
this.canvasSize.height,
|
|
23
|
+
canvasType
|
|
24
|
+
)
|
|
25
|
+
self.ctx = self._canvas.getContext()
|
|
26
|
+
|
|
27
|
+
if (self.options.data) {
|
|
28
|
+
self.setData(self.options.data)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Canvas.prototype = Object.create(Box.prototype)
|
|
34
|
+
|
|
35
|
+
Canvas.prototype.type = 'canvas'
|
|
36
|
+
|
|
37
|
+
Canvas.prototype.calcSize = function () {
|
|
38
|
+
this.canvasSize = { width: this.width * 2 - 12, height: this.height * 4 }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Canvas.prototype.clear = function () {
|
|
42
|
+
this.ctx.clearRect(0, 0, this.canvasSize.width, this.canvasSize.height)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Canvas.prototype.render = function () {
|
|
46
|
+
this.clearPos(true)
|
|
47
|
+
const inner = this.ctx._canvas.frame()
|
|
48
|
+
this.setContent(inner)
|
|
49
|
+
return this._render()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = Canvas
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const Node = require('../../../../blessed/lib/widgets/node'),
|
|
3
|
+
Canvas = require('../canvas')
|
|
4
|
+
|
|
5
|
+
function Bar(options) {
|
|
6
|
+
if (!(this instanceof Node)) {
|
|
7
|
+
return new Bar(options)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const self = this
|
|
11
|
+
|
|
12
|
+
Canvas.call(this, options, require('ansi-term'))
|
|
13
|
+
|
|
14
|
+
this.options.barWidth = this.options.barWidth || 6
|
|
15
|
+
this.options.barSpacing = this.options.barSpacing || 9
|
|
16
|
+
|
|
17
|
+
if (this.options.barSpacing - this.options.barWidth < 3) {
|
|
18
|
+
this.options.barSpacing = this.options.barWidth + 3
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
this.options.xOffset = this.options.xOffset == null ? 5 : this.options.xOffset
|
|
22
|
+
if (this.options.showText === false) {
|
|
23
|
+
this.options.showText = false
|
|
24
|
+
} else {
|
|
25
|
+
this.options.showText = true
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.on('attach', function () {
|
|
29
|
+
if (self.options.data) {
|
|
30
|
+
self.setData(self.options.data)
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
Bar.prototype = Object.create(Canvas.prototype)
|
|
36
|
+
|
|
37
|
+
Bar.prototype.calcSize = function () {
|
|
38
|
+
this.canvasSize = { width: this.width - 2, height: this.height }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Bar.prototype.setData = function (bar) {
|
|
42
|
+
if (!this.ctx) {
|
|
43
|
+
throw 'error: canvas context does not exist. setData() for bar charts must be called after the chart has been added to the screen via screen.append()'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.clear()
|
|
47
|
+
|
|
48
|
+
const c = this.ctx
|
|
49
|
+
let max = Math.max.apply(Math, bar.data)
|
|
50
|
+
max = Math.max(max, this.options.maxHeight)
|
|
51
|
+
let x = this.options.xOffset
|
|
52
|
+
const barY = this.canvasSize.height - 5
|
|
53
|
+
|
|
54
|
+
for (let i = 0; i < bar.data.length; i++) {
|
|
55
|
+
const h = Math.round(barY * (bar.data[i] / max))
|
|
56
|
+
|
|
57
|
+
if (bar.data[i] > 0) {
|
|
58
|
+
c.strokeStyle = 'blue'
|
|
59
|
+
if (this.options.barBgColor) {
|
|
60
|
+
c.strokeStyle = this.options.barBgColor
|
|
61
|
+
}
|
|
62
|
+
c.fillRect(x, barY - h + 1, this.options.barWidth, h)
|
|
63
|
+
} else {
|
|
64
|
+
c.strokeStyle = 'normal'
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
c.fillStyle = 'white'
|
|
68
|
+
if (this.options.barFgColor) {
|
|
69
|
+
c.fillStyle = this.options.barFgColor
|
|
70
|
+
}
|
|
71
|
+
if (this.options.showText) {
|
|
72
|
+
c.fillText(bar.data[i].toString(), x + 1, this.canvasSize.height - 4)
|
|
73
|
+
}
|
|
74
|
+
c.strokeStyle = 'normal'
|
|
75
|
+
c.fillStyle = 'white'
|
|
76
|
+
if (this.options.labelColor) {
|
|
77
|
+
c.fillStyle = this.options.labelColor
|
|
78
|
+
}
|
|
79
|
+
if (this.options.showText) {
|
|
80
|
+
c.fillText(bar.titles[i], x + 1, this.canvasSize.height - 3)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
x += this.options.barSpacing
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
Bar.prototype.getOptionsPrototype = function () {
|
|
88
|
+
return {
|
|
89
|
+
barWidth: 1,
|
|
90
|
+
barSpacing: 1,
|
|
91
|
+
xOffset: 1,
|
|
92
|
+
maxHeight: 1,
|
|
93
|
+
data: { titles: ['s'], data: [1] }
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
Bar.prototype.type = 'bar'
|
|
98
|
+
|
|
99
|
+
module.exports = Bar
|