From f5e7880bb1eb9b96cf0d33b8935c17c0ffb48840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ChangZhuo=20Chen=20=28=E9=99=B3=E6=98=8C=E5=80=AC=29?= Date: Tue, 4 Aug 2015 20:17:35 +0800 Subject: [PATCH] Implement several CSI --- lib/ansiparser2.js | 54 ++++++++++ test/spec-ansiparser2.js | 216 ++++++++++++++++++--------------------- 2 files changed, 152 insertions(+), 118 deletions(-) diff --git a/lib/ansiparser2.js b/lib/ansiparser2.js index 12adbc9..64c7f29 100644 --- a/lib/ansiparser2.js +++ b/lib/ansiparser2.js @@ -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': () => { diff --git a/test/spec-ansiparser2.js b/test/spec-ansiparser2.js index 4f6cb0b..67ac52e 100644 --- a/test/spec-ansiparser2.js +++ b/test/spec-ansiparser2.js @@ -406,41 +406,33 @@ 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); @@ -448,20 +440,16 @@ describe('AnsiParser', () => { }); 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); @@ -469,20 +457,16 @@ describe('AnsiParser', () => { }); 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); @@ -490,87 +474,67 @@ describe('AnsiParser', () => { }); 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); @@ -578,56 +542,72 @@ describe('AnsiParser', () => { }); 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); }); });