Skip to content

Commit

Permalink
chore: inline nyan reporter's write function
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Dec 27, 2023
1 parent 645469e commit d06e3eb
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions lib/reporters/nyan.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function NyanCat(runner, options) {
runner.once(EVENT_RUN_END, function () {
Base.cursor.show();
for (var i = 0; i < self.numberOfLines; i++) {
write('\n');
process.stdout.write('\n');
}
self.epilogue();
});
Expand Down Expand Up @@ -102,15 +102,15 @@ NyanCat.prototype.drawScoreboard = function () {
var stats = this.stats;

function draw(type, n) {
write(' ');
write(Base.color(type, n));
write('\n');
process.stdout.write(' ');
process.stdout.write(Base.color(type, n));
process.stdout.write('\n');
}

draw('green', stats.passes);
draw('fail', stats.failures);
draw('pending', stats.pending);
write('\n');
process.stdout.write('\n');

this.cursorUp(this.numberOfLines);
};
Expand Down Expand Up @@ -144,9 +144,9 @@ NyanCat.prototype.drawRainbow = function () {
var self = this;

this.trajectories.forEach(function (line) {
write('\u001b[' + self.scoreboardWidth + 'C');
write(line.join(''));
write('\n');
process.stdout.write('\u001b[' + self.scoreboardWidth + 'C');
process.stdout.write(line.join(''));
process.stdout.write('\n');
});

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

write(dist);
write('_,------,');
write('\n');
process.stdout.write(dist);
process.stdout.write('_,------,');
process.stdout.write('\n');

write(dist);
process.stdout.write(dist);
padding = self.tick ? ' ' : ' ';
write('_|' + padding + '/\\_/\\ ');
write('\n');
process.stdout.write('_|' + padding + '/\\_/\\ ');
process.stdout.write('\n');

write(dist);
process.stdout.write(dist);
padding = self.tick ? '_' : '__';
var tail = self.tick ? '~' : '^';
write(tail + '|' + padding + this.face() + ' ');
write('\n');
process.stdout.write(tail + '|' + padding + this.face() + ' ');
process.stdout.write('\n');

write(dist);
process.stdout.write(dist);
padding = self.tick ? ' ' : ' ';
write(padding + '"" "" ');
write('\n');
process.stdout.write(padding + '"" "" ');
process.stdout.write('\n');

this.cursorUp(this.numberOfLines);
};
Expand Down Expand Up @@ -213,7 +213,7 @@ NyanCat.prototype.face = function () {
*/

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

/**
Expand All @@ -224,7 +224,7 @@ NyanCat.prototype.cursorUp = function (n) {
*/

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

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

/**
* Stdout helper.
*
* @param {string} string A message to write to stdout.
*/
function write(string) {
process.stdout.write(string);
}

NyanCat.description = '"nyan cat"';

0 comments on commit d06e3eb

Please sign in to comment.