Permalink
Browse files

finally something that works with griddle output and passes tests

  • Loading branch information...
substack committed May 12, 2012
1 parent 1cbfbb6 commit a1117f64d8e115dc68608b0e787d8a3be9778739
Showing with 10 additions and 5 deletions.
  1. +8 −5 index.js
  2. +2 −0 test/color_width.js
View
@@ -101,16 +101,16 @@ module.exports = function (opts) {
}
function xcheck () {
- if (width && pos.x >= width) {
+ if (width && pos.x > width) {
pos.y += Math.floor(pos.x / width);
- pos.x = pos.x % width;
+ pos.x = Math.max(pos.x % width, 1);
}
}
var emit = (function () {
var nt = false;
return function (buf) {
- pos.emit('data', buf);
+ pos.emit('data', buf, pos.x, pos.y);
pos.emit('pos', pos.x, pos.y);
};
})();
@@ -158,6 +158,7 @@ module.exports = function (opts) {
var p = stack.pop();
pos.x = p.x;
pos.y = p.y;
+ xcheck();
emit(b);
parse.call(this);
}
@@ -177,15 +178,17 @@ module.exports = function (opts) {
}
else {
pos.x += 2;
- xcheck() || emit(b);
+ xcheck();
+ emit(b);
parse.call(this);
}
})
;
}
else {
pos.x ++;
- xcheck() || emit(b);
+ emit(b);
+ xcheck();
parse.call(this);
}
})
View
@@ -37,6 +37,8 @@ test('color width', function (t) {
.seq(function () { pos.once('pos', this.ok) })
.seq(function () { setTimeout(this.ok, 50) })
.seq(function () {
+ // abcdefghij
+ // klmn*
t.equal(pos.x, 5);
t.equal(pos.y, 2);
charm.end();

0 comments on commit a1117f6

Please sign in to comment.