Skip to content

Commit

Permalink
Implement several CSI
Browse files Browse the repository at this point in the history
  • Loading branch information
czchen committed Aug 4, 2015
1 parent de26c84 commit f5e7880
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 118 deletions.
54 changes: 54 additions & 0 deletions lib/ansiparser2.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,60 @@ export default class {
this._termbuf.handleTab(count);
},

'J': () => {
const count = getFirstParam(this._parseCsiParams(), 1);

this._termbuf.handleClear(count);
},

'K': () => {
const count = getFirstParam(this._parseCsiParams(), 1);

this._termbuf.eraseLine(count);
},

'L': () => {
const count = getFirstParam(this._parseCsiParams(), 1);

this._termbuf.insertLine(count);
},

'M': () => {
const count = getFirstParam(this._parseCsiParams(), 1);

this._termbuf.deleteLine(count);
},

'P': () => {
const count = getFirstParam(this._parseCsiParams(), 1);

this._termbuf.handleDel(count);
},

'S': () => {
const count = getFirstParam(this._parseCsiParams(), 1);

this._termbuf.scrollUp(count);
},

'T': () => {
const count = getFirstParam(this._parseCsiParams(), 1);

this._termbuf.scrollDown(count);
},

'X': () => {
const count = getFirstParam(this._parseCsiParams(), 1);

this._termbuf.eraseChar(count);
},

'Z': () => {
const count = getFirstParam(this._parseCsiParams(), 1);

this._termbuf.handleBackTab(count);
},

'f': this._setPosition,

'm': () => {
Expand Down
216 changes: 98 additions & 118 deletions test/spec-ansiparser2.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,228 +406,208 @@ describe('AnsiParser', () => {
});

describe('[J]', () => {
it.skip('default', () => {
const input = `${CSI}J`;

parser.feed(input);
it('default', () => {
parser.parse(str2ab(`${CSI}J`));

assert.ok(termbuf.clear.calledOnce);
assert.strictEqual(termbuf.clear.getCall(0).args[0], 0);
assert.ok(termbuf.handleClear.calledOnce);
assert.strictEqual(termbuf.handleClear.getCall(0).args[0], 1);
});

it.skip('has count', () => {
it('has count', () => {
const count = 5;
const input = `${CSI}${count}J`;

parser.feed(input);
parser.parse(str2ab(`${CSI}${count}J`));

assert.ok(termbuf.clear.calledOnce);
assert.strictEqual(termbuf.clear.getCall(0).args[0], count);
assert.ok(termbuf.handleClear.calledOnce);
assert.strictEqual(termbuf.handleClear.getCall(0).args[0], count);
});
});

describe('[K]', () => {
it.skip('default', () => {
const input = `${CSI}K`;

parser.feed(input);
it('default', () => {
parser.parse(str2ab(`${CSI}K`));

assert.ok(termbuf.eraseLine.calledOnce);
assert.strictEqual(termbuf.eraseLine.getCall(0).args[0], 0);
assert.strictEqual(termbuf.eraseLine.getCall(0).args[0], 1);
});

it.skip('has count', () => {
it('has count', () => {
const count = 5;
const input = `${CSI}${count}K`;

parser.feed(input);
parser.parse(str2ab(`${CSI}${count}K`));

assert.ok(termbuf.eraseLine.calledOnce);
assert.strictEqual(termbuf.eraseLine.getCall(0).args[0], count);
});
});

describe('[L]', () => {
it.skip('default', () => {
const input = `${CSI}L`;

parser.feed(input);
it('default', () => {
parser.parse(str2ab(`${CSI}L`));

assert.ok(termbuf.insertLine.calledOnce);
assert.strictEqual(termbuf.insertLine.getCall(0).args[0], 1);
});

it.skip('has count', () => {
it('has count', () => {
const count = 5;
const input = `${CSI}${count}L`;

parser.feed(input);
parser.parse(str2ab(`${CSI}${count}L`));

assert.ok(termbuf.insertLine.calledOnce);
assert.strictEqual(termbuf.insertLine.getCall(0).args[0], count);
});
});

describe('[M]', () => {
it.skip('default', () => {
const input = `${CSI}M`;

parser.feed(input);
it('default', () => {
parser.parse(str2ab(`${CSI}M`));

assert.ok(termbuf.deleteLine.calledOnce);
assert.strictEqual(termbuf.deleteLine.getCall(0).args[0], 1);
});

it.skip('has count', () => {
it('has count', () => {
const count = 5;
const input = `${CSI}${count}M`;

parser.feed(input);
parser.parse(str2ab(`${CSI}${count}M`));

assert.ok(termbuf.deleteLine.calledOnce);
assert.strictEqual(termbuf.deleteLine.getCall(0).args[0], count);
});
});

describe('[P]', () => {
it.skip('default', () => {
const input = `${CSI}P`;

parser.feed(input);
it('default', () => {
parser.parse(str2ab(`${CSI}P`));

assert.ok(termbuf.del.calledOnce);
assert.strictEqual(termbuf.del.getCall(0).args[0], 1);
assert.ok(termbuf.handleDel.calledOnce);
assert.strictEqual(termbuf.handleDel.getCall(0).args[0], 1);
});

it.skip('has count', () => {
it('has count', () => {
const count = 5;
const input = `${CSI}${count}P`;

parser.feed(input);
parser.parse(str2ab(`${CSI}${count}P`));

assert.ok(termbuf.del.calledOnce);
assert.strictEqual(termbuf.del.getCall(0).args[0], count);
assert.ok(termbuf.handleDel.calledOnce);
assert.strictEqual(termbuf.handleDel.getCall(0).args[0], count);
});
});

describe('[S] SU – Scroll Up', () => {
it.skip('default', () => {
const input = `${CSI}S`;

parser.feed(input);
it('default', () => {
parser.parse(str2ab(`${CSI}S`));

assert.ok(termbuf.scroll.calledOnce);
assert.strictEqual(termbuf.scroll.getCall(0).args[0], false);
assert.strictEqual(termbuf.scroll.getCall(0).args[1], 1);
assert.ok(termbuf.scrollUp.calledOnce);
assert.strictEqual(termbuf.scrollUp.getCall(0).args[0], 1);
});

it.skip('has page', () => {
const page = 5;
const input = `${CSI}${page}S`;

parser.feed(input);
it('has count', () => {
const count = 5;
parser.parse(str2ab(`${CSI}${count}S`));

assert.ok(termbuf.scroll.calledOnce);
assert.strictEqual(termbuf.scroll.getCall(0).args[0], false);
assert.strictEqual(termbuf.scroll.getCall(0).args[1], page);
assert.ok(termbuf.scrollUp.calledOnce);
assert.strictEqual(termbuf.scrollUp.getCall(0).args[0], count);
});
});

describe('[T] SD – Scroll Down', () => {
it.skip('default', () => {
const input = `${CSI}T`;

parser.feed(input);
it('default', () => {
parser.parse(str2ab(`${CSI}T`));

assert.ok(termbuf.scroll.calledOnce);
assert.strictEqual(termbuf.scroll.getCall(0).args[0], true);
assert.strictEqual(termbuf.scroll.getCall(0).args[1], 1);
assert.ok(termbuf.scrollDown.calledOnce);
assert.strictEqual(termbuf.scrollDown.getCall(0).args[0], 1);
});

it.skip('has page', () => {
const page = 5;
const input = `${CSI}${page}T`;

parser.feed(input);
it('has count', () => {
const count = 5;
parser.parse(str2ab(`${CSI}${count}T`));

assert.ok(termbuf.scroll.calledOnce);
assert.strictEqual(termbuf.scroll.getCall(0).args[0], true);
assert.strictEqual(termbuf.scroll.getCall(0).args[1], page);
assert.ok(termbuf.scrollDown.calledOnce);
assert.strictEqual(termbuf.scrollDown.getCall(0).args[0], count);
});
});

describe('[X]', () => {
it.skip('default', () => {
const input = `${CSI}X`;

parser.feed(input);
it('default', () => {
parser.parse(str2ab(`${CSI}X`));

assert.ok(termbuf.eraseChar.calledOnce);
assert.strictEqual(termbuf.eraseChar.getCall(0).args[0], 1);
});

it.skip('has count', () => {
it('has count', () => {
const count = 5;
const input = `${CSI}${count}X`;

parser.feed(input);
parser.parse(str2ab(`${CSI}${count}X`));

assert.ok(termbuf.eraseChar.calledOnce);
assert.strictEqual(termbuf.eraseChar.getCall(0).args[0], count);
});
});

describe('[Z]', () => {
it.skip('default', () => {
const input = `${CSI}Z`;

parser.feed(input);
it('default', () => {
parser.parse(str2ab(`${CSI}Z`));

assert.ok(termbuf.backTab.calledOnce);
assert.strictEqual(termbuf.backTab.getCall(0).args[0], 1);
assert.ok(termbuf.handleBackTab.calledOnce);
assert.strictEqual(termbuf.handleBackTab.getCall(0).args[0], 1);
});

it.skip('has count', () => {
it('has count', () => {
const count = 5;
const input = `${CSI}${count}Z`;

parser.feed(input);
parser.parse(str2ab(`${CSI}${count}Z`));

assert.ok(termbuf.backTab.calledOnce);
assert.strictEqual(termbuf.backTab.getCall(0).args[0], count);
assert.ok(termbuf.handleBackTab.calledOnce);
assert.strictEqual(termbuf.handleBackTab.getCall(0).args[0], count);
});
});

describe('[d]', () => {
it.skip('default', () => {
const curX = 10;
const curY = 20;
termbuf.curX = curX;
termbuf.curY = curY;
it('no row/column', () => {
parser.parse(str2ab(`${CSI}H`));

const input = `${CSI}d`;
assert.ok(termbuf.gotoPos.calledOnce);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[0], 0);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[1], 0);
});

parser.feed(input);
it('has row', () => {
const row = 10;

parser.parse(str2ab(`${CSI}${row}H`));

assert.ok(termbuf.gotoPos.calledOnce);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[0], curX);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[1], 0);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[0], 0);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[1], row - 1);
});

it('has row and column', () => {
const row = 10;
const column = 20;

parser.parse(str2ab(`${CSI}${row};${column}H`));

assert.ok(termbuf.gotoPos.calledOnce);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[0], column - 1);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[1], row - 1);
});

it.skip('has column', () => {
const curX = 10;
const curY = 20;
termbuf.curX = curX;
termbuf.curY = curY;
it('bad row', () => {
const row = '?';
const column = 20;

const column = 5;
const input = `${CSI}${column}d`;
parser.parse(str2ab(`${CSI}${row};${column}H`));

parser.feed(input);
assert.ok(termbuf.gotoPos.calledOnce);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[0], column - 1);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[1], 0);
});

it('bad column', () => {
const row = 10;
const column = '?';

parser.parse(str2ab(`${CSI}${row};${column}H`));

assert.ok(termbuf.gotoPos.calledOnce);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[0], curX);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[1], column - 1);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[0], 0);
assert.strictEqual(termbuf.gotoPos.getCall(0).args[1], row - 1);
});
});

Expand Down

0 comments on commit f5e7880

Please sign in to comment.