@@ -32,7 +32,7 @@ function Gauge (arg1, arg2) {
32
32
this . _status = {
33
33
spun : 0 ,
34
34
section : '' ,
35
- subsection : ''
35
+ subsection : '' ,
36
36
}
37
37
this . _paused = false // are we paused for back pressure?
38
38
this . _disabled = true // are all progress bar updates disabled?
@@ -50,10 +50,10 @@ function Gauge (arg1, arg2) {
50
50
this . _theme = options . theme
51
51
var theme = this . _computeTheme ( options . theme )
52
52
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 : '' } ,
57
57
]
58
58
this . setWriteTo ( writeTo , options . tty )
59
59
var PlumbingClass = options . Plumbing || Plumbing
@@ -79,17 +79,28 @@ Gauge.prototype.isEnabled = function () {
79
79
80
80
Gauge . prototype . setTemplate = function ( template ) {
81
81
this . _gauge . setTemplate ( template )
82
- if ( this . _showing ) this . _requestRedraw ( )
82
+ if ( this . _showing ) {
83
+ this . _requestRedraw ( )
84
+ }
83
85
}
84
86
85
87
Gauge . prototype . _computeTheme = function ( theme ) {
86
- if ( ! theme ) theme = { }
88
+ if ( ! theme ) {
89
+ theme = { }
90
+ }
87
91
if ( typeof theme === 'string' ) {
88
92
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
+ ) {
90
97
var useUnicode = theme . hasUnicode == null ? hasUnicode ( ) : theme . hasUnicode
91
98
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
+ } )
93
104
}
94
105
return theme
95
106
}
@@ -101,13 +112,17 @@ Gauge.prototype.setThemeset = function (themes) {
101
112
102
113
Gauge . prototype . setTheme = function ( theme ) {
103
114
this . _gauge . setTheme ( this . _computeTheme ( theme ) )
104
- if ( this . _showing ) this . _requestRedraw ( )
115
+ if ( this . _showing ) {
116
+ this . _requestRedraw ( )
117
+ }
105
118
this . _theme = theme
106
119
}
107
120
108
121
Gauge . prototype . _requestRedraw = function ( ) {
109
122
this . _needsRedraw = true
110
- if ( ! this . _fixedFramerate ) this . _doRedraw ( )
123
+ if ( ! this . _fixedFramerate ) {
124
+ this . _doRedraw ( )
125
+ }
111
126
}
112
127
113
128
Gauge . prototype . getWidth = function ( ) {
@@ -116,33 +131,49 @@ Gauge.prototype.getWidth = function () {
116
131
117
132
Gauge . prototype . setWriteTo = function ( writeTo , tty ) {
118
133
var enabled = ! this . _disabled
119
- if ( enabled ) this . disable ( )
134
+ if ( enabled ) {
135
+ this . disable ( )
136
+ }
120
137
this . _writeTo = writeTo
121
138
this . _tty = tty ||
122
139
( writeTo === process . stderr && process . stdout . isTTY && process . stdout ) ||
123
140
( writeTo . isTTY && writeTo ) ||
124
141
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
+ }
127
148
}
128
149
129
150
Gauge . prototype . enable = function ( ) {
130
- if ( ! this . _disabled ) return
151
+ if ( ! this . _disabled ) {
152
+ return
153
+ }
131
154
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
+ }
134
161
}
135
162
136
163
Gauge . prototype . disable = function ( ) {
137
- if ( this . _disabled ) return
164
+ if ( this . _disabled ) {
165
+ return
166
+ }
138
167
if ( this . _showing ) {
139
168
this . _lastUpdateAt = null
140
169
this . _showing = false
141
170
this . _doRedraw ( )
142
171
this . _showing = true
143
172
}
144
173
this . _disabled = true
145
- if ( this . _tty ) this . _disableEvents ( )
174
+ if ( this . _tty ) {
175
+ this . _disableEvents ( )
176
+ }
146
177
}
147
178
148
179
Gauge . prototype . _enableEvents = function ( ) {
@@ -152,19 +183,29 @@ Gauge.prototype._enableEvents = function () {
152
183
this . _tty . on ( 'resize' , this . _$$handleSizeChange )
153
184
if ( this . _fixedFramerate ) {
154
185
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
+ }
156
189
}
157
190
}
158
191
159
192
Gauge . prototype . _disableEvents = function ( ) {
160
193
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
+ }
163
200
}
164
201
165
202
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
+ }
168
209
this . _showing = false
169
210
this . _doRedraw ( )
170
211
cb && setImmediate ( cb )
@@ -181,16 +222,24 @@ Gauge.prototype.show = function (section, completed) {
181
222
this . _status [ key ] = section [ key ]
182
223
}
183
224
}
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
+ }
186
231
this . _requestRedraw ( )
187
232
}
188
233
189
234
Gauge . prototype . pulse = function ( subsection ) {
190
235
this . _status . subsection = subsection || ''
191
236
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
+ }
194
243
this . _requestRedraw ( )
195
244
}
196
245
@@ -200,10 +249,14 @@ Gauge.prototype._handleSizeChange = function () {
200
249
}
201
250
202
251
Gauge . prototype . _doRedraw = function ( ) {
203
- if ( this . _disabled || this . _paused ) return
252
+ if ( this . _disabled || this . _paused ) {
253
+ return
254
+ }
204
255
if ( ! this . _fixedFramerate ) {
205
256
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
+ }
207
260
this . _lastUpdateAt = now
208
261
}
209
262
if ( ! this . _showing && this . _onScreen ) {
@@ -214,15 +267,19 @@ Gauge.prototype._doRedraw = function () {
214
267
}
215
268
return this . _writeTo . write ( result )
216
269
}
217
- if ( ! this . _showing && ! this . _onScreen ) return
270
+ if ( ! this . _showing && ! this . _onScreen ) {
271
+ return
272
+ }
218
273
if ( this . _showing && ! this . _onScreen ) {
219
274
this . _onScreen = true
220
275
this . _needsRedraw = true
221
276
if ( this . _hideCursor ) {
222
277
this . _writeTo . write ( this . _gauge . hideCursor ( ) )
223
278
}
224
279
}
225
- if ( ! this . _needsRedraw ) return
280
+ if ( ! this . _needsRedraw ) {
281
+ return
282
+ }
226
283
if ( ! this . _writeTo . write ( this . _gauge . show ( this . _status ) ) ) {
227
284
this . _paused = true
228
285
this . _writeTo . on ( 'drain' , callWith ( this , function ( ) {
0 commit comments