Skip to content

Commit 0801585

Browse files
wraithgarfritzy
authored andcommitted
PR-URL: #4049 Credit: @wraithgar Close: #4049 Reviewed-by: @fritzy
1 parent 7b4aa59 commit 0801585

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+955
-216
lines changed

node_modules/gauge/LICENSE

Lines changed: 0 additions & 13 deletions
This file was deleted.

node_modules/gauge/LICENSE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
2+
3+
ISC License
4+
5+
Copyright npm, Inc.
6+
7+
Permission to use, copy, modify, and/or distribute this
8+
software for any purpose with or without fee is hereby
9+
granted, provided that the above copyright notice and this
10+
permission notice appear in all copies.
11+
12+
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
13+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
14+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
15+
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
16+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
20+
USE OR PERFORMANCE OF THIS SOFTWARE.

node_modules/gauge/base-theme.js renamed to node_modules/gauge/lib/base-theme.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ var progressBar = require('./progress-bar.js')
44

55
module.exports = {
66
activityIndicator: function (values, theme, width) {
7-
if (values.spun == null) return
7+
if (values.spun == null) {
8+
return
9+
}
810
return spin(theme, values.spun)
911
},
1012
progressbar: function (values, theme, width) {
11-
if (values.completed == null) return
13+
if (values.completed == null) {
14+
return
15+
}
1216
return progressBar(theme, width, values.completed)
13-
}
17+
},
1418
}

node_modules/gauge/lib/demo.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var Gauge = require('./')
2+
var gaugeDefault = require('./themes.js')
3+
var onExit = require('signal-exit')
4+
5+
var activeGauge
6+
7+
onExit(function () {
8+
activeGauge.disable()
9+
})
10+
11+
var themes = gaugeDefault.getThemeNames()
12+
13+
nextBar()
14+
function nextBar () {
15+
var themeName = themes.shift()
16+
17+
console.log('Demoing output for ' + themeName)
18+
19+
var gt = new Gauge(process.stderr, {
20+
updateInterval: 50,
21+
theme: themeName,
22+
cleanupOnExit: false,
23+
})
24+
activeGauge = gt
25+
26+
var progress = 0
27+
28+
var cnt = 0
29+
var pulse = setInterval(function () {
30+
gt.pulse('this is a thing that happened ' + (++cnt))
31+
}, 110)
32+
var prog = setInterval(function () {
33+
progress += 0.04
34+
gt.show(themeName + ':' + Math.round(progress * 1000), progress)
35+
if (progress >= 1) {
36+
clearInterval(prog)
37+
clearInterval(pulse)
38+
gt.disable()
39+
if (themes.length) {
40+
nextBar()
41+
}
42+
}
43+
}, 100)
44+
gt.show()
45+
}
File renamed without changes.
File renamed without changes.

node_modules/gauge/index.js renamed to node_modules/gauge/lib/index.js

Lines changed: 89 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function Gauge (arg1, arg2) {
3232
this._status = {
3333
spun: 0,
3434
section: '',
35-
subsection: ''
35+
subsection: '',
3636
}
3737
this._paused = false // are we paused for back pressure?
3838
this._disabled = true // are all progress bar updates disabled?
@@ -50,10 +50,10 @@ function Gauge (arg1, arg2) {
5050
this._theme = options.theme
5151
var theme = this._computeTheme(options.theme)
5252
var template = options.template || [
53-
{type: 'progressbar', length: 20},
54-
{type: 'activityIndicator', kerning: 1, length: 1},
55-
{type: 'section', kerning: 1, default: ''},
56-
{type: 'subsection', kerning: 1, default: ''}
53+
{ type: 'progressbar', length: 20 },
54+
{ type: 'activityIndicator', kerning: 1, length: 1 },
55+
{ type: 'section', kerning: 1, default: '' },
56+
{ type: 'subsection', kerning: 1, default: '' },
5757
]
5858
this.setWriteTo(writeTo, options.tty)
5959
var PlumbingClass = options.Plumbing || Plumbing
@@ -79,17 +79,28 @@ Gauge.prototype.isEnabled = function () {
7979

8080
Gauge.prototype.setTemplate = function (template) {
8181
this._gauge.setTemplate(template)
82-
if (this._showing) this._requestRedraw()
82+
if (this._showing) {
83+
this._requestRedraw()
84+
}
8385
}
8486

8587
Gauge.prototype._computeTheme = function (theme) {
86-
if (!theme) theme = {}
88+
if (!theme) {
89+
theme = {}
90+
}
8791
if (typeof theme === 'string') {
8892
theme = this._themes.getTheme(theme)
89-
} else if (theme && (Object.keys(theme).length === 0 || theme.hasUnicode != null || theme.hasColor != null)) {
93+
} else if (
94+
theme &&
95+
(Object.keys(theme).length === 0 || theme.hasUnicode != null || theme.hasColor != null)
96+
) {
9097
var useUnicode = theme.hasUnicode == null ? hasUnicode() : theme.hasUnicode
9198
var useColor = theme.hasColor == null ? hasColor : theme.hasColor
92-
theme = this._themes.getDefault({hasUnicode: useUnicode, hasColor: useColor, platform: theme.platform})
99+
theme = this._themes.getDefault({
100+
hasUnicode: useUnicode,
101+
hasColor: useColor,
102+
platform: theme.platform,
103+
})
93104
}
94105
return theme
95106
}
@@ -101,13 +112,17 @@ Gauge.prototype.setThemeset = function (themes) {
101112

102113
Gauge.prototype.setTheme = function (theme) {
103114
this._gauge.setTheme(this._computeTheme(theme))
104-
if (this._showing) this._requestRedraw()
115+
if (this._showing) {
116+
this._requestRedraw()
117+
}
105118
this._theme = theme
106119
}
107120

108121
Gauge.prototype._requestRedraw = function () {
109122
this._needsRedraw = true
110-
if (!this._fixedFramerate) this._doRedraw()
123+
if (!this._fixedFramerate) {
124+
this._doRedraw()
125+
}
111126
}
112127

113128
Gauge.prototype.getWidth = function () {
@@ -116,33 +131,49 @@ Gauge.prototype.getWidth = function () {
116131

117132
Gauge.prototype.setWriteTo = function (writeTo, tty) {
118133
var enabled = !this._disabled
119-
if (enabled) this.disable()
134+
if (enabled) {
135+
this.disable()
136+
}
120137
this._writeTo = writeTo
121138
this._tty = tty ||
122139
(writeTo === process.stderr && process.stdout.isTTY && process.stdout) ||
123140
(writeTo.isTTY && writeTo) ||
124141
this._tty
125-
if (this._gauge) this._gauge.setWidth(this.getWidth())
126-
if (enabled) this.enable()
142+
if (this._gauge) {
143+
this._gauge.setWidth(this.getWidth())
144+
}
145+
if (enabled) {
146+
this.enable()
147+
}
127148
}
128149

129150
Gauge.prototype.enable = function () {
130-
if (!this._disabled) return
151+
if (!this._disabled) {
152+
return
153+
}
131154
this._disabled = false
132-
if (this._tty) this._enableEvents()
133-
if (this._showing) this.show()
155+
if (this._tty) {
156+
this._enableEvents()
157+
}
158+
if (this._showing) {
159+
this.show()
160+
}
134161
}
135162

136163
Gauge.prototype.disable = function () {
137-
if (this._disabled) return
164+
if (this._disabled) {
165+
return
166+
}
138167
if (this._showing) {
139168
this._lastUpdateAt = null
140169
this._showing = false
141170
this._doRedraw()
142171
this._showing = true
143172
}
144173
this._disabled = true
145-
if (this._tty) this._disableEvents()
174+
if (this._tty) {
175+
this._disableEvents()
176+
}
146177
}
147178

148179
Gauge.prototype._enableEvents = function () {
@@ -152,19 +183,29 @@ Gauge.prototype._enableEvents = function () {
152183
this._tty.on('resize', this._$$handleSizeChange)
153184
if (this._fixedFramerate) {
154185
this.redrawTracker = setInterval(this._$$doRedraw, this._updateInterval)
155-
if (this.redrawTracker.unref) this.redrawTracker.unref()
186+
if (this.redrawTracker.unref) {
187+
this.redrawTracker.unref()
188+
}
156189
}
157190
}
158191

159192
Gauge.prototype._disableEvents = function () {
160193
this._tty.removeListener('resize', this._$$handleSizeChange)
161-
if (this._fixedFramerate) clearInterval(this.redrawTracker)
162-
if (this._removeOnExit) this._removeOnExit()
194+
if (this._fixedFramerate) {
195+
clearInterval(this.redrawTracker)
196+
}
197+
if (this._removeOnExit) {
198+
this._removeOnExit()
199+
}
163200
}
164201

165202
Gauge.prototype.hide = function (cb) {
166-
if (this._disabled) return cb && process.nextTick(cb)
167-
if (!this._showing) return cb && process.nextTick(cb)
203+
if (this._disabled) {
204+
return cb && process.nextTick(cb)
205+
}
206+
if (!this._showing) {
207+
return cb && process.nextTick(cb)
208+
}
168209
this._showing = false
169210
this._doRedraw()
170211
cb && setImmediate(cb)
@@ -181,16 +222,24 @@ Gauge.prototype.show = function (section, completed) {
181222
this._status[key] = section[key]
182223
}
183224
}
184-
if (completed != null) this._status.completed = completed
185-
if (this._disabled) return
225+
if (completed != null) {
226+
this._status.completed = completed
227+
}
228+
if (this._disabled) {
229+
return
230+
}
186231
this._requestRedraw()
187232
}
188233

189234
Gauge.prototype.pulse = function (subsection) {
190235
this._status.subsection = subsection || ''
191236
this._status.spun++
192-
if (this._disabled) return
193-
if (!this._showing) return
237+
if (this._disabled) {
238+
return
239+
}
240+
if (!this._showing) {
241+
return
242+
}
194243
this._requestRedraw()
195244
}
196245

@@ -200,10 +249,14 @@ Gauge.prototype._handleSizeChange = function () {
200249
}
201250

202251
Gauge.prototype._doRedraw = function () {
203-
if (this._disabled || this._paused) return
252+
if (this._disabled || this._paused) {
253+
return
254+
}
204255
if (!this._fixedFramerate) {
205256
var now = Date.now()
206-
if (this._lastUpdateAt && now - this._lastUpdateAt < this._updateInterval) return
257+
if (this._lastUpdateAt && now - this._lastUpdateAt < this._updateInterval) {
258+
return
259+
}
207260
this._lastUpdateAt = now
208261
}
209262
if (!this._showing && this._onScreen) {
@@ -214,15 +267,19 @@ Gauge.prototype._doRedraw = function () {
214267
}
215268
return this._writeTo.write(result)
216269
}
217-
if (!this._showing && !this._onScreen) return
270+
if (!this._showing && !this._onScreen) {
271+
return
272+
}
218273
if (this._showing && !this._onScreen) {
219274
this._onScreen = true
220275
this._needsRedraw = true
221276
if (this._hideCursor) {
222277
this._writeTo.write(this._gauge.hideCursor())
223278
}
224279
}
225-
if (!this._needsRedraw) return
280+
if (!this._needsRedraw) {
281+
return
282+
}
226283
if (!this._writeTo.write(this._gauge.show(this._status))) {
227284
this._paused = true
228285
this._writeTo.on('drain', callWith(this, function () {

node_modules/gauge/plumbing.js renamed to node_modules/gauge/lib/plumbing.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ var renderTemplate = require('./render-template.js')
44
var validate = require('aproba')
55

66
var Plumbing = module.exports = function (theme, template, width) {
7-
if (!width) width = 80
7+
if (!width) {
8+
width = 80
9+
}
810
validate('OAN', [theme, template, width])
911
this.showing = false
1012
this.theme = theme
File renamed without changes.

node_modules/gauge/progress-bar.js renamed to node_modules/gauge/lib/progress-bar.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ var stringWidth = require('string-width')
66

77
module.exports = function (theme, width, completed) {
88
validate('ONN', [theme, width, completed])
9-
if (completed < 0) completed = 0
10-
if (completed > 1) completed = 1
11-
if (width <= 0) return ''
9+
if (completed < 0) {
10+
completed = 0
11+
}
12+
if (completed > 1) {
13+
completed = 1
14+
}
15+
if (width <= 0) {
16+
return ''
17+
}
1218
var sofar = Math.round(width * completed)
1319
var rest = width - sofar
1420
var template = [
15-
{type: 'complete', value: repeat(theme.complete, sofar), length: sofar},
16-
{type: 'remaining', value: repeat(theme.remaining, rest), length: rest}
21+
{ type: 'complete', value: repeat(theme.complete, sofar), length: sofar },
22+
{ type: 'remaining', value: repeat(theme.remaining, rest), length: rest },
1723
]
1824
return renderTemplate(width, template, theme)
1925
}

0 commit comments

Comments
 (0)