Skip to content

Commit 1ebff45

Browse files
chore: inline nyan reporter's write function (mochajs#5056)
1 parent 8812413 commit 1ebff45

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

lib/reporters/nyan.js

+22-31
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function NyanCat(runner, options) {
6666
runner.once(EVENT_RUN_END, function () {
6767
Base.cursor.show();
6868
for (var i = 0; i < self.numberOfLines; i++) {
69-
write('\n');
69+
process.stdout.write('\n');
7070
}
7171
self.epilogue();
7272
});
@@ -102,15 +102,15 @@ NyanCat.prototype.drawScoreboard = function () {
102102
var stats = this.stats;
103103

104104
function draw(type, n) {
105-
write(' ');
106-
write(Base.color(type, n));
107-
write('\n');
105+
process.stdout.write(' ');
106+
process.stdout.write(Base.color(type, n));
107+
process.stdout.write('\n');
108108
}
109109

110110
draw('green', stats.passes);
111111
draw('fail', stats.failures);
112112
draw('pending', stats.pending);
113-
write('\n');
113+
process.stdout.write('\n');
114114

115115
this.cursorUp(this.numberOfLines);
116116
};
@@ -144,9 +144,9 @@ NyanCat.prototype.drawRainbow = function () {
144144
var self = this;
145145

146146
this.trajectories.forEach(function (line) {
147-
write('\u001b[' + self.scoreboardWidth + 'C');
148-
write(line.join(''));
149-
write('\n');
147+
process.stdout.write('\u001b[' + self.scoreboardWidth + 'C');
148+
process.stdout.write(line.join(''));
149+
process.stdout.write('\n');
150150
});
151151

152152
this.cursorUp(this.numberOfLines);
@@ -163,25 +163,25 @@ NyanCat.prototype.drawNyanCat = function () {
163163
var dist = '\u001b[' + startWidth + 'C';
164164
var padding = '';
165165

166-
write(dist);
167-
write('_,------,');
168-
write('\n');
166+
process.stdout.write(dist);
167+
process.stdout.write('_,------,');
168+
process.stdout.write('\n');
169169

170-
write(dist);
170+
process.stdout.write(dist);
171171
padding = self.tick ? ' ' : ' ';
172-
write('_|' + padding + '/\\_/\\ ');
173-
write('\n');
172+
process.stdout.write('_|' + padding + '/\\_/\\ ');
173+
process.stdout.write('\n');
174174

175-
write(dist);
175+
process.stdout.write(dist);
176176
padding = self.tick ? '_' : '__';
177177
var tail = self.tick ? '~' : '^';
178-
write(tail + '|' + padding + this.face() + ' ');
179-
write('\n');
178+
process.stdout.write(tail + '|' + padding + this.face() + ' ');
179+
process.stdout.write('\n');
180180

181-
write(dist);
181+
process.stdout.write(dist);
182182
padding = self.tick ? ' ' : ' ';
183-
write(padding + '"" "" ');
184-
write('\n');
183+
process.stdout.write(padding + '"" "" ');
184+
process.stdout.write('\n');
185185

186186
this.cursorUp(this.numberOfLines);
187187
};
@@ -213,7 +213,7 @@ NyanCat.prototype.face = function () {
213213
*/
214214

215215
NyanCat.prototype.cursorUp = function (n) {
216-
write('\u001b[' + n + 'A');
216+
process.stdout.write('\u001b[' + n + 'A');
217217
};
218218

219219
/**
@@ -224,7 +224,7 @@ NyanCat.prototype.cursorUp = function (n) {
224224
*/
225225

226226
NyanCat.prototype.cursorDown = function (n) {
227-
write('\u001b[' + n + 'B');
227+
process.stdout.write('\u001b[' + n + 'B');
228228
};
229229

230230
/**
@@ -264,13 +264,4 @@ NyanCat.prototype.rainbowify = function (str) {
264264
return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
265265
};
266266

267-
/**
268-
* Stdout helper.
269-
*
270-
* @param {string} string A message to write to stdout.
271-
*/
272-
function write(string) {
273-
process.stdout.write(string);
274-
}
275-
276267
NyanCat.description = '"nyan cat"';

0 commit comments

Comments
 (0)