Skip to content

Commit

Permalink
using \x1b[K, no need for strip-ansi anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Dec 26, 2013
1 parent 6195366 commit 2d4d2e3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
20 changes: 3 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@ var through2 = require('through2');
var duplexer = require('duplexer');
var parser = require('tap-parser');
var sprintf = require('sprintf');
var strip = require('strip-ansi');

module.exports = function (opts) {
if (!opts) opts = {};
var tap = parser();
var out = through2();
var test, lastAssert;

var replaceLine = (function () {
var prevWidth = 0;
return function (str) {
if (opts.width) str = str.slice(0, opts.width);
var len = strip(str).length;
var n = prevWidth - len;
if (n < 0) n = 0;
var s = str + Array(n + 1).join(' ');
prevWidth = len;
return '\r' + s;
};
})();

tap.on('comment', function (comment) {
if (test && test.ok) {
var s = updateName(test.offset + 1, '✓ ' + test.name, 32);
Expand All @@ -35,14 +21,14 @@ module.exports = function (opts) {
offset: 0,
ok: true
};
out.push(replaceLine('# ' + comment) + '\n');
out.push('\r# ' + comment + '\x1b[K\n');
});

tap.on('assert', function (res) {
var ok = res.ok ? 'ok' : 'not ok';
var c = res.ok ? 32 : 31;
var fmt = ' %s \x1b[1m\x1b[' + c + 'm%d\x1b[0m %s';
var str = replaceLine(sprintf(fmt, ok, res.number, res.name));
var fmt = '\r %s \x1b[1m\x1b[' + c + 'm%d\x1b[0m %s\x1b[K';
var str = sprintf(fmt, ok, res.number, res.name);

if (!res.ok) {
var y = (++ test.offset) + 1;
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"through2": "~0.2.3",
"tap-parser": "~0.4.0",
"duplexer": "~0.1.1",
"strip-ansi": "~0.1.1",
"sprintf": "~0.1.3"
},
"devDependencies": {
Expand Down

0 comments on commit 2d4d2e3

Please sign in to comment.