@@ -15,8 +15,8 @@ function MiniReporter() {
15
15
this . skipCount = 0 ;
16
16
this . rejectionCount = 0 ;
17
17
this . exceptionCount = 0 ;
18
- this . lastWritten = '' ;
19
- this . prevLineCount = 0 ;
18
+ this . currentStatus = '' ;
19
+ this . statusLineCount = 0 ;
20
20
this . stream = lastLineStream ( process . stderr ) ;
21
21
}
22
22
@@ -136,9 +136,9 @@ MiniReporter.prototype.finish = function () {
136
136
137
137
MiniReporter . prototype . write = function ( str ) {
138
138
cliCursor . hide ( ) ;
139
- this . lastWritten = str + '\n' ;
139
+ this . currentStatus = str + '\n' ;
140
140
this . _update ( ) ;
141
- this . prevLineCount = this . lastWritten . split ( '\n' ) . length ;
141
+ this . statusLineCount = this . currentStatus . split ( '\n' ) . length ;
142
142
} ;
143
143
144
144
MiniReporter . prototype . stdout = MiniReporter . prototype . stderr = function ( data ) {
@@ -147,11 +147,15 @@ MiniReporter.prototype.stdout = MiniReporter.prototype.stderr = function (data)
147
147
148
148
MiniReporter . prototype . _update = function ( data ) {
149
149
var str = '' ;
150
- var ct = this . prevLineCount ;
150
+ var ct = this . statusLineCount ;
151
151
var columns = process . stdout . columns ;
152
152
var lastLine = this . stream . lastLine ;
153
+
154
+ // Terminals will automatically wrap to a new line if text exceed the column width.
155
+ // We want what is (visually) the last line of output. Not everything after the last `\n` character.
153
156
lastLine = lastLine . substring ( lastLine . length - ( lastLine . length % columns ) ) ;
154
157
158
+ // Unless the last line of logOutput is completely empty, we need to delete it and rewrite it.
155
159
if ( lastLine . length ) {
156
160
ct ++ ;
157
161
}
@@ -161,37 +165,43 @@ MiniReporter.prototype._update = function (data) {
161
165
str += lastLine ;
162
166
163
167
if ( str . length ) {
168
+ // `push`ing to the stream is the equivalent to a `write`, but `lastLine` is not updated.
164
169
this . stream . push ( str ) ;
165
170
}
166
171
167
172
if ( data ) {
168
173
this . stream . write ( data ) ;
169
174
}
170
175
171
- var lastWritten = this . lastWritten ;
172
- if ( lastWritten . length ) {
176
+ var currentStatus = this . currentStatus ;
177
+ if ( currentStatus . length ) {
173
178
lastLine = this . stream . lastLine ;
179
+ // We need a newline between the last line of the log output and the status message.
180
+ // However, if the last line of the log output is the exact width of the terminal,
181
+ // a newline is already implied, and adding a second will cause problems.
174
182
if ( lastLine . length % columns ) {
175
- lastWritten = '\n' + lastWritten ;
183
+ currentStatus = '\n' + currentStatus ;
176
184
}
177
- this . stream . push ( lastWritten ) ;
185
+ // Writes the status message, without affecting the `lastLine` status.
186
+ this . stream . push ( currentStatus ) ;
178
187
}
179
188
} ;
180
189
181
190
// TODO(@jamestalamge): This should be fixed in log-update and ansi-escapes once we are confident it's a good solution.
182
191
var CSI = '\u001b[' ;
183
192
var ERASE_LINE = CSI + '2K' ;
184
- var CURSOR_LEFT = CSI + '0G' ;
193
+ var CURSOR_TO_COLUMN_0 = CSI + '0G' ;
185
194
var CURSOR_UP = CSI + '1A' ;
186
195
196
+ // Erases `count` lines from the end of the terminal.
187
197
function eraseLines ( count ) {
188
198
var clear = '' ;
189
199
190
200
for ( var i = 0 ; i < count ; i ++ ) {
191
201
clear += ERASE_LINE + ( i < count - 1 ? CURSOR_UP : '' ) ;
192
202
}
193
203
if ( count ) {
194
- clear += CURSOR_LEFT ;
204
+ clear += CURSOR_TO_COLUMN_0 ;
195
205
}
196
206
197
207
return clear ;
0 commit comments