Permalink
Browse files

fix the 0=>1 offset issues for color_width and lines tests

  • Loading branch information...
1 parent 6f3c6cd commit 45958fbf1fd51092cf7e1865d907dadac42617d1 @substack committed May 11, 2012
Showing with 28 additions and 18 deletions.
  1. +7 −7 index.js
  2. +5 −3 test/color_width.js
  3. +16 −8 test/lines.js
View
@@ -14,8 +14,8 @@ module.exports = function (opts) {
pos.writable = true;
pos.readable = true;
- pos.x = opts.x || 0;
- pos.y = opts.y || 0;
+ pos.x = opts.x || 1;
+ pos.y = opts.y || 1;
var bin = binary();
pos.write = bin.write.bind(bin);
@@ -103,7 +103,7 @@ module.exports = function (opts) {
function xcheck () {
if (width && pos.x >= width) {
pos.y += Math.floor(pos.x / width);
- pos.x = (pos.x % width) + 1;
+ pos.x = pos.x % width;
}
}
@@ -123,12 +123,12 @@ module.exports = function (opts) {
var b = new Buffer([vars.c]);
if (c === '\n'.charCodeAt(0)) {
pos.y ++;
- pos.x = 0;
+ pos.x = 1;
emit(b);
parse.call(this);
}
else if (c === '\r'.charCodeAt(0)) {
- pos.x = 0;
+ pos.x = 1;
emit(b);
parse.call(this);
}
@@ -163,14 +163,14 @@ module.exports = function (opts) {
}
else if (x === 'D') {
// scroll down
- pos.x = 0;
+ pos.x = 1;
pos.y ++;
emit(b);
parse.call(this);
}
else if (x === 'M') {
// scroll up
- pos.x = 0;
+ pos.x = 1;
pos.y --;
emit(b);
parse.call(this);
View
@@ -13,7 +13,7 @@ test('color width', function (t) {
.seq(function () { pos.once('pos', this.ok) })
.seq(function () { setTimeout(this.ok, 50) })
.seq(function () {
- t.equal(pos.x, 5);
+ t.equal(pos.x, 6);
t.equal(pos.y, 1);
charm
.foreground('red')
@@ -24,8 +24,10 @@ test('color width', function (t) {
.seq(function () { pos.once('pos', this.ok) })
.seq(function () { setTimeout(this.ok, 50) })
.seq(function () {
+ // abcdefghij (10)
+ // *
t.equal(pos.x, 1);
- t.equal(pos.y, 1);
+ t.equal(pos.y, 2);
charm
.background('yellow')
.write(new Buffer('klmn'))
@@ -36,7 +38,7 @@ test('color width', function (t) {
.seq(function () { setTimeout(this.ok, 50) })
.seq(function () {
t.equal(pos.x, 5);
- t.equal(pos.y, 1);
+ t.equal(pos.y, 2);
charm.end();
t.end();
})
View
@@ -10,8 +10,8 @@ test('lines', function (t) {
.seq(function () { pos.once('pos', this.ok) })
.seq(function () { setTimeout(this.ok, 50) })
.seq(function () {
- t.equal(pos.x, 3);
- t.equal(pos.y, 0);
+ t.equal(pos.x, 4);
+ t.equal(pos.y, 1);
process.nextTick(function () {
pos.write(new Buffer('\n'));
});
@@ -20,24 +20,32 @@ test('lines', function (t) {
.seq(function () { pos.once('pos', this.ok) })
.seq(function () { setTimeout(this.ok, 50) })
.seq(function () {
- t.equal(pos.x, 0);
- t.equal(pos.y, 1);
+ // abc\n
+ // *
+ t.equal(pos.x, 1);
+ t.equal(pos.y, 2);
pos.write(new Buffer('defg\fhi'));
this();
})
.seq(function () { pos.once('pos', this.ok) })
.seq(function () { setTimeout(this.ok, 50) })
.seq(function () {
- t.equal(pos.x, 6);
- t.equal(pos.y, 2);
+ // abc\n
+ // defg\f
+ // hi*
+ t.equal(pos.x, 7);
+ t.equal(pos.y, 3);
pos.write(new Buffer('jk\rl'));
this();
})
.seq(function () { pos.once('pos', this.ok) })
.seq(function () { setTimeout(this.ok, 50) })
.seq(function () {
- t.equal(pos.x, 1);
- t.equal(pos.y, 2);
+ // abc\n
+ // defg\f
+ // l*
+ t.equal(pos.x, 2);
+ t.equal(pos.y, 3);
pos.end();
t.end();
})

0 comments on commit 45958fb

Please sign in to comment.