Use IBufferService for buffer access in InputHandler
This commit is contained in:
+139
-131
@@ -13,7 +13,8 @@ import { CellData } from 'common/buffer/CellData';
|
||||
import { Attributes } from 'common/buffer/Constants';
|
||||
import { AttributeData } from 'common/buffer/AttributeData';
|
||||
import { Params } from 'common/parser/Params';
|
||||
import { MockCoreService } from 'common/TestUtils.test';
|
||||
import { MockCoreService, MockBufferService } from 'common/TestUtils.test';
|
||||
import { IBufferService } from 'common/services/Services';
|
||||
|
||||
function getCursor(term: TestTerminal): number[] {
|
||||
return [
|
||||
@@ -27,30 +28,31 @@ describe('InputHandler', () => {
|
||||
const terminal = new MockInputHandlingTerminal();
|
||||
terminal.cols = 80;
|
||||
terminal.rows = 30;
|
||||
terminal.buffer.x = 1;
|
||||
terminal.buffer.y = 2;
|
||||
terminal.buffer.ybase = 0;
|
||||
terminal.curAttrData.fg = 3;
|
||||
const inputHandler = new InputHandler(terminal, new MockCoreService());
|
||||
const bufferService = new MockBufferService(80, 30);
|
||||
bufferService.buffer.x = 1;
|
||||
bufferService.buffer.y = 2;
|
||||
bufferService.buffer.ybase = 0;
|
||||
const inputHandler = new InputHandler(terminal, bufferService, new MockCoreService());
|
||||
// Save cursor position
|
||||
inputHandler.saveCursor();
|
||||
assert.equal(terminal.buffer.x, 1);
|
||||
assert.equal(terminal.buffer.y, 2);
|
||||
assert.equal(bufferService.buffer.x, 1);
|
||||
assert.equal(bufferService.buffer.y, 2);
|
||||
assert.equal(terminal.curAttrData.fg, 3);
|
||||
// Change cursor position
|
||||
terminal.buffer.x = 10;
|
||||
terminal.buffer.y = 20;
|
||||
bufferService.buffer.x = 10;
|
||||
bufferService.buffer.y = 20;
|
||||
terminal.curAttrData.fg = 30;
|
||||
// Restore cursor position
|
||||
inputHandler.restoreCursor();
|
||||
assert.equal(terminal.buffer.x, 1);
|
||||
assert.equal(terminal.buffer.y, 2);
|
||||
assert.equal(bufferService.buffer.x, 1);
|
||||
assert.equal(bufferService.buffer.y, 2);
|
||||
assert.equal(terminal.curAttrData.fg, 3);
|
||||
});
|
||||
describe('setCursorStyle', () => {
|
||||
it('should call Terminal.setOption with correct params', () => {
|
||||
const terminal = new MockInputHandlingTerminal();
|
||||
const inputHandler = new InputHandler(terminal, new MockCoreService());
|
||||
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCoreService());
|
||||
const collect = ' ';
|
||||
|
||||
inputHandler.setCursorStyle(Params.fromArray([0]), collect);
|
||||
@@ -93,7 +95,7 @@ describe('InputHandler', () => {
|
||||
const terminal = new MockInputHandlingTerminal();
|
||||
const collect = '?';
|
||||
terminal.bracketedPasteMode = false;
|
||||
const inputHandler = new InputHandler(terminal, new MockCoreService());
|
||||
const inputHandler = new InputHandler(terminal, new MockBufferService(80, 30), new MockCoreService());
|
||||
// Set bracketed paste mode
|
||||
inputHandler.setMode(Params.fromArray([2004]), collect);
|
||||
assert.equal(terminal.bracketedPasteMode, true);
|
||||
@@ -103,92 +105,95 @@ describe('InputHandler', () => {
|
||||
});
|
||||
});
|
||||
describe('regression tests', function(): void {
|
||||
function termContent(term: Terminal, trim: boolean): string[] {
|
||||
function termContent(bufferService: IBufferService, trim: boolean): string[] {
|
||||
const result = [];
|
||||
for (let i = 0; i < term.rows; ++i) result.push(term.buffer.lines.get(i).translateToString(trim));
|
||||
for (let i = 0; i < bufferService.rows; ++i) result.push(bufferService.buffer.lines.get(i).translateToString(trim));
|
||||
return result;
|
||||
}
|
||||
|
||||
it('insertChars', function(): void {
|
||||
const term = new Terminal();
|
||||
const inputHandler = new InputHandler(term, new MockCoreService());
|
||||
const bufferService = new MockBufferService(80, 30);
|
||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService());
|
||||
|
||||
// insert some data in first and second line
|
||||
inputHandler.parse(Array(term.cols - 9).join('a'));
|
||||
inputHandler.parse('1234567890');
|
||||
inputHandler.parse(Array(term.cols - 9).join('a'));
|
||||
inputHandler.parse('1234567890');
|
||||
const line1: IBufferLine = term.buffer.lines.get(0);
|
||||
const line1: IBufferLine = bufferService.buffer.lines.get(0);
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + '1234567890');
|
||||
|
||||
// insert one char from params = [0]
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.insertChars(Params.fromArray([0]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + ' 123456789');
|
||||
|
||||
// insert one char from params = [1]
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.insertChars(Params.fromArray([1]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + ' 12345678');
|
||||
|
||||
// insert two chars from params = [2]
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.insertChars(Params.fromArray([2]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + ' 123456');
|
||||
|
||||
// insert 10 chars from params = [10]
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.insertChars(Params.fromArray([10]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + ' ');
|
||||
expect(line1.translateToString(true)).equals(Array(term.cols - 9).join('a'));
|
||||
});
|
||||
it('deleteChars', function(): void {
|
||||
const term = new Terminal();
|
||||
const inputHandler = new InputHandler(term, new MockCoreService());
|
||||
const bufferService = new MockBufferService(80, 30);
|
||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService());
|
||||
|
||||
// insert some data in first and second line
|
||||
inputHandler.parse(Array(term.cols - 9).join('a'));
|
||||
inputHandler.parse('1234567890');
|
||||
inputHandler.parse(Array(term.cols - 9).join('a'));
|
||||
inputHandler.parse('1234567890');
|
||||
const line1: IBufferLine = term.buffer.lines.get(0);
|
||||
const line1: IBufferLine = bufferService.buffer.lines.get(0);
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + '1234567890');
|
||||
|
||||
// delete one char from params = [0]
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.deleteChars(Params.fromArray([0]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + '234567890 ');
|
||||
expect(line1.translateToString(true)).equals(Array(term.cols - 9).join('a') + '234567890');
|
||||
|
||||
// insert one char from params = [1]
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.deleteChars(Params.fromArray([1]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + '34567890 ');
|
||||
expect(line1.translateToString(true)).equals(Array(term.cols - 9).join('a') + '34567890');
|
||||
|
||||
// insert two chars from params = [2]
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.deleteChars(Params.fromArray([2]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + '567890 ');
|
||||
expect(line1.translateToString(true)).equals(Array(term.cols - 9).join('a') + '567890');
|
||||
|
||||
// insert 10 chars from params = [10]
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.deleteChars(Params.fromArray([10]));
|
||||
expect(line1.translateToString(false)).equals(Array(term.cols - 9).join('a') + ' ');
|
||||
expect(line1.translateToString(true)).equals(Array(term.cols - 9).join('a'));
|
||||
});
|
||||
it('eraseInLine', function(): void {
|
||||
const term = new Terminal();
|
||||
const inputHandler = new InputHandler(term, new MockCoreService());
|
||||
const bufferService = new MockBufferService(80, 30);
|
||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService());
|
||||
|
||||
// fill 6 lines to test 3 different states
|
||||
inputHandler.parse(Array(term.cols + 1).join('a'));
|
||||
@@ -196,101 +201,102 @@ describe('InputHandler', () => {
|
||||
inputHandler.parse(Array(term.cols + 1).join('a'));
|
||||
|
||||
// params[0] - right erase
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.eraseInLine(Params.fromArray([0]));
|
||||
expect(term.buffer.lines.get(0).translateToString(false)).equals(Array(71).join('a') + ' ');
|
||||
expect(bufferService.buffer.lines.get(0).translateToString(false)).equals(Array(71).join('a') + ' ');
|
||||
|
||||
// params[1] - left erase
|
||||
term.buffer.y = 1;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 1;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.eraseInLine(Params.fromArray([1]));
|
||||
expect(term.buffer.lines.get(1).translateToString(false)).equals(Array(71).join(' ') + ' aaaaaaaaa');
|
||||
expect(bufferService.buffer.lines.get(1).translateToString(false)).equals(Array(71).join(' ') + ' aaaaaaaaa');
|
||||
|
||||
// params[1] - left erase
|
||||
term.buffer.y = 2;
|
||||
term.buffer.x = 70;
|
||||
bufferService.buffer.y = 2;
|
||||
bufferService.buffer.x = 70;
|
||||
inputHandler.eraseInLine(Params.fromArray([2]));
|
||||
expect(term.buffer.lines.get(2).translateToString(false)).equals(Array(term.cols + 1).join(' '));
|
||||
expect(bufferService.buffer.lines.get(2).translateToString(false)).equals(Array(term.cols + 1).join(' '));
|
||||
|
||||
});
|
||||
it('eraseInDisplay', function(): void {
|
||||
const term = new Terminal({cols: 80, rows: 7});
|
||||
const inputHandler = new InputHandler(term, new MockCoreService());
|
||||
const bufferService = new MockBufferService(80, 7);
|
||||
const inputHandler = new InputHandler(term, bufferService, new MockCoreService());
|
||||
|
||||
// fill display with a's
|
||||
for (let i = 0; i < term.rows; ++i) inputHandler.parse(Array(term.cols + 1).join('a'));
|
||||
for (let i = 0; i < term.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||
|
||||
// params [0] - right and below erase
|
||||
term.buffer.y = 5;
|
||||
term.buffer.x = 40;
|
||||
bufferService.buffer.y = 5;
|
||||
bufferService.buffer.x = 40;
|
||||
inputHandler.eraseInDisplay(Params.fromArray([0]));
|
||||
expect(termContent(term, false)).eql([
|
||||
Array(term.cols + 1).join('a'),
|
||||
Array(term.cols + 1).join('a'),
|
||||
Array(term.cols + 1).join('a'),
|
||||
Array(term.cols + 1).join('a'),
|
||||
Array(term.cols + 1).join('a'),
|
||||
Array(40 + 1).join('a') + Array(term.cols - 40 + 1).join(' '),
|
||||
Array(term.cols + 1).join(' ')
|
||||
expect(termContent(bufferService, false)).eql([
|
||||
Array(bufferService.cols + 1).join('a'),
|
||||
Array(bufferService.cols + 1).join('a'),
|
||||
Array(bufferService.cols + 1).join('a'),
|
||||
Array(bufferService.cols + 1).join('a'),
|
||||
Array(bufferService.cols + 1).join('a'),
|
||||
Array(40 + 1).join('a') + Array(bufferService.cols - 40 + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' ')
|
||||
]);
|
||||
expect(termContent(term, true)).eql([
|
||||
Array(term.cols + 1).join('a'),
|
||||
Array(term.cols + 1).join('a'),
|
||||
Array(term.cols + 1).join('a'),
|
||||
Array(term.cols + 1).join('a'),
|
||||
Array(term.cols + 1).join('a'),
|
||||
expect(termContent(bufferService, true)).eql([
|
||||
Array(bufferService.cols + 1).join('a'),
|
||||
Array(bufferService.cols + 1).join('a'),
|
||||
Array(bufferService.cols + 1).join('a'),
|
||||
Array(bufferService.cols + 1).join('a'),
|
||||
Array(bufferService.cols + 1).join('a'),
|
||||
Array(40 + 1).join('a'),
|
||||
''
|
||||
]);
|
||||
|
||||
// reset
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 0;
|
||||
for (let i = 0; i < term.rows; ++i) inputHandler.parse(Array(term.cols + 1).join('a'));
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 0;
|
||||
for (let i = 0; i < bufferService.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||
|
||||
// params [1] - left and above
|
||||
term.buffer.y = 5;
|
||||
term.buffer.x = 40;
|
||||
bufferService.buffer.y = 5;
|
||||
bufferService.buffer.x = 40;
|
||||
inputHandler.eraseInDisplay(Params.fromArray([1]));
|
||||
expect(termContent(term, false)).eql([
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(41 + 1).join(' ') + Array(term.cols - 41 + 1).join('a'),
|
||||
Array(term.cols + 1).join('a')
|
||||
expect(termContent(bufferService, false)).eql([
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(41 + 1).join(' ') + Array(bufferService.cols - 41 + 1).join('a'),
|
||||
Array(bufferService.cols + 1).join('a')
|
||||
]);
|
||||
expect(termContent(term, true)).eql([
|
||||
expect(termContent(bufferService, true)).eql([
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
Array(41 + 1).join(' ') + Array(term.cols - 41 + 1).join('a'),
|
||||
Array(term.cols + 1).join('a')
|
||||
Array(41 + 1).join(' ') + Array(bufferService.cols - 41 + 1).join('a'),
|
||||
Array(bufferService.cols + 1).join('a')
|
||||
]);
|
||||
|
||||
// reset
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 0;
|
||||
for (let i = 0; i < term.rows; ++i) inputHandler.parse(Array(term.cols + 1).join('a'));
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 0;
|
||||
for (let i = 0; i < bufferService.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||
|
||||
// params [2] - whole screen
|
||||
term.buffer.y = 5;
|
||||
term.buffer.x = 40;
|
||||
bufferService.buffer.y = 5;
|
||||
bufferService.buffer.x = 40;
|
||||
inputHandler.eraseInDisplay(Params.fromArray([2]));
|
||||
expect(termContent(term, false)).eql([
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(term.cols + 1).join(' '),
|
||||
Array(term.cols + 1).join(' ')
|
||||
expect(termContent(bufferService, false)).eql([
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' '),
|
||||
Array(bufferService.cols + 1).join(' ')
|
||||
]);
|
||||
expect(termContent(term, true)).eql([
|
||||
expect(termContent(bufferService, true)).eql([
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
@@ -301,34 +307,34 @@ describe('InputHandler', () => {
|
||||
]);
|
||||
|
||||
// reset and add a wrapped line
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 0;
|
||||
inputHandler.parse(Array(term.cols + 1).join('a')); // line 0
|
||||
inputHandler.parse(Array(term.cols + 10).join('a')); // line 1 and 2
|
||||
for (let i = 3; i < term.rows; ++i) inputHandler.parse(Array(term.cols + 1).join('a'));
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 0;
|
||||
inputHandler.parse(Array(bufferService.cols + 1).join('a')); // line 0
|
||||
inputHandler.parse(Array(bufferService.cols + 10).join('a')); // line 1 and 2
|
||||
for (let i = 3; i < bufferService.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||
|
||||
// params[1] left and above with wrap
|
||||
// confirm precondition that line 2 is wrapped
|
||||
expect(term.buffer.lines.get(2).isWrapped).true;
|
||||
term.buffer.y = 2;
|
||||
term.buffer.x = 40;
|
||||
expect(bufferService.buffer.lines.get(2).isWrapped).true;
|
||||
bufferService.buffer.y = 2;
|
||||
bufferService.buffer.x = 40;
|
||||
inputHandler.eraseInDisplay(Params.fromArray([1]));
|
||||
expect(term.buffer.lines.get(2).isWrapped).false;
|
||||
expect(bufferService.buffer.lines.get(2).isWrapped).false;
|
||||
|
||||
// reset and add a wrapped line
|
||||
term.buffer.y = 0;
|
||||
term.buffer.x = 0;
|
||||
inputHandler.parse(Array(term.cols + 1).join('a')); // line 0
|
||||
inputHandler.parse(Array(term.cols + 10).join('a')); // line 1 and 2
|
||||
for (let i = 3; i < term.rows; ++i) inputHandler.parse(Array(term.cols + 1).join('a'));
|
||||
bufferService.buffer.y = 0;
|
||||
bufferService.buffer.x = 0;
|
||||
inputHandler.parse(Array(bufferService.cols + 1).join('a')); // line 0
|
||||
inputHandler.parse(Array(bufferService.cols + 10).join('a')); // line 1 and 2
|
||||
for (let i = 3; i < bufferService.rows; ++i) inputHandler.parse(Array(bufferService.cols + 1).join('a'));
|
||||
|
||||
// params[1] left and above with wrap
|
||||
// confirm precondition that line 2 is wrapped
|
||||
expect(term.buffer.lines.get(2).isWrapped).true;
|
||||
term.buffer.y = 1;
|
||||
term.buffer.x = 90; // Cursor is beyond last column
|
||||
expect(bufferService.buffer.lines.get(2).isWrapped).true;
|
||||
bufferService.buffer.y = 1;
|
||||
bufferService.buffer.x = 90; // Cursor is beyond last column
|
||||
inputHandler.eraseInDisplay(Params.fromArray([1]));
|
||||
expect(term.buffer.lines.get(2).isWrapped).false;
|
||||
expect(bufferService.buffer.lines.get(2).isWrapped).false;
|
||||
});
|
||||
});
|
||||
it('convertEol setting', function(): void {
|
||||
@@ -351,7 +357,7 @@ describe('InputHandler', () => {
|
||||
describe('print', () => {
|
||||
it('should not cause an infinite loop (regression test)', () => {
|
||||
const term = new Terminal();
|
||||
const inputHandler = new InputHandler(term, new MockCoreService());
|
||||
const inputHandler = new InputHandler(term, new MockBufferService(80, 30), new MockCoreService());
|
||||
const container = new Uint32Array(10);
|
||||
container[0] = 0x200B;
|
||||
inputHandler.print(container, 0, 1);
|
||||
@@ -360,56 +366,58 @@ describe('InputHandler', () => {
|
||||
|
||||
describe('alt screen', () => {
|
||||
let term: Terminal;
|
||||
let bufferService: IBufferService;
|
||||
let handler: InputHandler;
|
||||
|
||||
beforeEach(() => {
|
||||
term = new Terminal();
|
||||
handler = new InputHandler(term, new MockCoreService());
|
||||
bufferService = new MockBufferService(80, 30);
|
||||
handler = new InputHandler(term, bufferService, new MockCoreService());
|
||||
});
|
||||
it('should handle DECSET/DECRST 47 (alt screen buffer)', () => {
|
||||
handler.parse('\x1b[?47h\r\n\x1b[31mJUNK\x1b[?47lTEST');
|
||||
expect(term.buffer.translateBufferLineToString(0, true)).to.equal('');
|
||||
expect(term.buffer.translateBufferLineToString(1, true)).to.equal(' TEST');
|
||||
expect(bufferService.buffer.translateBufferLineToString(0, true)).to.equal('');
|
||||
expect(bufferService.buffer.translateBufferLineToString(1, true)).to.equal(' TEST');
|
||||
// Text color of 'TEST' should be red
|
||||
expect((term.buffer.lines.get(1).loadCell(4, new CellData()).getFgColor())).to.equal(1);
|
||||
expect((bufferService.buffer.lines.get(1).loadCell(4, new CellData()).getFgColor())).to.equal(1);
|
||||
});
|
||||
it('should handle DECSET/DECRST 1047 (alt screen buffer)', () => {
|
||||
handler.parse('\x1b[?1047h\r\n\x1b[31mJUNK\x1b[?1047lTEST');
|
||||
expect(term.buffer.translateBufferLineToString(0, true)).to.equal('');
|
||||
expect(term.buffer.translateBufferLineToString(1, true)).to.equal(' TEST');
|
||||
expect(bufferService.buffer.translateBufferLineToString(0, true)).to.equal('');
|
||||
expect(bufferService.buffer.translateBufferLineToString(1, true)).to.equal(' TEST');
|
||||
// Text color of 'TEST' should be red
|
||||
expect((term.buffer.lines.get(1).loadCell(4, new CellData()).getFgColor())).to.equal(1);
|
||||
expect((bufferService.buffer.lines.get(1).loadCell(4, new CellData()).getFgColor())).to.equal(1);
|
||||
});
|
||||
it('should handle DECSET/DECRST 1048 (alt screen cursor)', () => {
|
||||
handler.parse('\x1b[?1048h\r\n\x1b[31mJUNK\x1b[?1048lTEST');
|
||||
expect(term.buffer.translateBufferLineToString(0, true)).to.equal('TEST');
|
||||
expect(term.buffer.translateBufferLineToString(1, true)).to.equal('JUNK');
|
||||
expect(bufferService.buffer.translateBufferLineToString(0, true)).to.equal('TEST');
|
||||
expect(bufferService.buffer.translateBufferLineToString(1, true)).to.equal('JUNK');
|
||||
// Text color of 'TEST' should be default
|
||||
expect(term.buffer.lines.get(0).loadCell(0, new CellData()).fg).to.equal(DEFAULT_ATTR_DATA.fg);
|
||||
expect(bufferService.buffer.lines.get(0).loadCell(0, new CellData()).fg).to.equal(DEFAULT_ATTR_DATA.fg);
|
||||
// Text color of 'JUNK' should be red
|
||||
expect((term.buffer.lines.get(1).loadCell(0, new CellData()).getFgColor())).to.equal(1);
|
||||
expect((bufferService.buffer.lines.get(1).loadCell(0, new CellData()).getFgColor())).to.equal(1);
|
||||
});
|
||||
it('should handle DECSET/DECRST 1049 (alt screen buffer+cursor)', () => {
|
||||
handler.parse('\x1b[?1049h\r\n\x1b[31mJUNK\x1b[?1049lTEST');
|
||||
expect(term.buffer.translateBufferLineToString(0, true)).to.equal('TEST');
|
||||
expect(term.buffer.translateBufferLineToString(1, true)).to.equal('');
|
||||
expect(bufferService.buffer.translateBufferLineToString(0, true)).to.equal('TEST');
|
||||
expect(bufferService.buffer.translateBufferLineToString(1, true)).to.equal('');
|
||||
// Text color of 'TEST' should be default
|
||||
expect(term.buffer.lines.get(0).loadCell(0, new CellData()).fg).to.equal(DEFAULT_ATTR_DATA.fg);
|
||||
expect(bufferService.buffer.lines.get(0).loadCell(0, new CellData()).fg).to.equal(DEFAULT_ATTR_DATA.fg);
|
||||
});
|
||||
it('should handle DECSET/DECRST 1049 - maintains saved cursor for alt buffer', () => {
|
||||
handler.parse('\x1b[?1049h\r\n\x1b[31m\x1b[s\x1b[?1049lTEST');
|
||||
expect(term.buffer.translateBufferLineToString(0, true)).to.equal('TEST');
|
||||
expect(bufferService.buffer.translateBufferLineToString(0, true)).to.equal('TEST');
|
||||
// Text color of 'TEST' should be default
|
||||
expect(term.buffer.lines.get(0).loadCell(0, new CellData()).fg).to.equal(DEFAULT_ATTR_DATA.fg);
|
||||
expect(bufferService.buffer.lines.get(0).loadCell(0, new CellData()).fg).to.equal(DEFAULT_ATTR_DATA.fg);
|
||||
handler.parse('\x1b[?1049h\x1b[uTEST');
|
||||
expect(term.buffer.translateBufferLineToString(1, true)).to.equal('TEST');
|
||||
expect(bufferService.buffer.translateBufferLineToString(1, true)).to.equal('TEST');
|
||||
// Text color of 'TEST' should be red
|
||||
expect((term.buffer.lines.get(1).loadCell(0, new CellData()).getFgColor())).to.equal(1);
|
||||
expect((bufferService.buffer.lines.get(1).loadCell(0, new CellData()).getFgColor())).to.equal(1);
|
||||
});
|
||||
it('should handle DECSET/DECRST 1049 - clears alt buffer with erase attributes', () => {
|
||||
handler.parse('\x1b[42m\x1b[?1049h');
|
||||
// Buffer should be filled with green background
|
||||
expect(term.buffer.lines.get(20).loadCell(10, new CellData()).getBgColor()).to.equal(2);
|
||||
expect(bufferService.buffer.lines.get(20).loadCell(10, new CellData()).getBgColor()).to.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+106
-102
@@ -19,7 +19,7 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content
|
||||
import { CellData } from 'common/buffer/CellData';
|
||||
import { AttributeData } from 'common/buffer/AttributeData';
|
||||
import { IAttributeData, IDisposable } from 'common/Types';
|
||||
import { ICoreService } from 'common/services/Services';
|
||||
import { ICoreService, IBufferService } from 'common/services/Services';
|
||||
import { ISelectionService } from 'browser/services/Services';
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,10 @@ const GLEVEL: {[key: string]: number} = {'(': 0, ')': 1, '*': 2, '+': 3, '-': 1,
|
||||
class DECRQSS implements IDcsHandler {
|
||||
private _data: Uint32Array = new Uint32Array(0);
|
||||
|
||||
constructor(private _terminal: any) { }
|
||||
constructor(
|
||||
private _terminal: any,
|
||||
private _bufferService: IBufferService
|
||||
) { }
|
||||
|
||||
hook(collect: string, params: IParams, flag: number): void {
|
||||
this._data = new Uint32Array(0);
|
||||
@@ -61,8 +64,8 @@ class DECRQSS implements IDcsHandler {
|
||||
case '"p': // DECSCL
|
||||
return this._terminal.handler(`${C0.ESC}P1$r61"p${C0.ESC}\\`);
|
||||
case 'r': // DECSTBM
|
||||
const pt = '' + (this._terminal.buffer.scrollTop + 1) +
|
||||
';' + (this._terminal.buffer.scrollBottom + 1) + 'r';
|
||||
const pt = '' + (this._bufferService.buffer.scrollTop + 1) +
|
||||
';' + (this._bufferService.buffer.scrollBottom + 1) + 'r';
|
||||
return this._terminal.handler(`${C0.ESC}P1$r${pt}${C0.ESC}\\`);
|
||||
case 'm': // SGR
|
||||
// TODO: report real settings instead of 0m
|
||||
@@ -124,6 +127,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
|
||||
constructor(
|
||||
protected _terminal: IInputHandlingTerminal,
|
||||
private _bufferService: IBufferService,
|
||||
private _coreService: ICoreService,
|
||||
private _parser: IEscapeSequenceParser = new EscapeSequenceParser())
|
||||
{
|
||||
@@ -293,7 +297,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
/**
|
||||
* DCS handler
|
||||
*/
|
||||
this._parser.setDcsHandler('$q', new DECRQSS(this._terminal));
|
||||
this._parser.setDcsHandler('$q', new DECRQSS(this._terminal, this._bufferService));
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
@@ -312,7 +316,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
let buffer = this._terminal.buffer;
|
||||
let buffer = this._bufferService.buffer;
|
||||
const cursorStartX = buffer.x;
|
||||
const cursorStartY = buffer.y;
|
||||
|
||||
@@ -326,7 +330,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
}
|
||||
this._parser.parse(this._parseBuffer, this._stringDecoder.decode(data, this._parseBuffer));
|
||||
|
||||
buffer = this._terminal.buffer;
|
||||
buffer = this._bufferService.buffer;
|
||||
if (buffer.x !== cursorStartX || buffer.y !== cursorStartY) {
|
||||
this._onCursorMove.fire();
|
||||
}
|
||||
@@ -338,7 +342,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
let buffer = this._terminal.buffer;
|
||||
let buffer = this._bufferService.buffer;
|
||||
const cursorStartX = buffer.x;
|
||||
const cursorStartY = buffer.y;
|
||||
|
||||
@@ -352,7 +356,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
}
|
||||
this._parser.parse(this._parseBuffer, this._utf8Decoder.decode(data, this._parseBuffer));
|
||||
|
||||
buffer = this._terminal.buffer;
|
||||
buffer = this._bufferService.buffer;
|
||||
if (buffer.x !== cursorStartX || buffer.y !== cursorStartY) {
|
||||
this._onCursorMove.fire();
|
||||
}
|
||||
@@ -361,7 +365,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
public print(data: Uint32Array, start: number, end: number): void {
|
||||
let code: number;
|
||||
let chWidth: number;
|
||||
const buffer = this._terminal.buffer;
|
||||
const buffer = this._bufferService.buffer;
|
||||
const charset = this._terminal.charset;
|
||||
const screenReaderMode = this._terminal.options.screenReaderMode;
|
||||
const cols = this._terminal.cols;
|
||||
@@ -510,7 +514,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
public lineFeed(): void {
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
const buffer = this._bufferService.buffer;
|
||||
|
||||
if (this._terminal.options.convertEol) {
|
||||
buffer.x = 0;
|
||||
@@ -533,7 +537,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Carriage Return (Ctrl-M).
|
||||
*/
|
||||
public carriageReturn(): void {
|
||||
this._terminal.buffer.x = 0;
|
||||
this._bufferService.buffer.x = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -542,8 +546,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
public backspace(): void {
|
||||
this._restrictCursor();
|
||||
if (this._terminal.buffer.x > 0) {
|
||||
this._terminal.buffer.x--;
|
||||
if (this._bufferService.buffer.x > 0) {
|
||||
this._bufferService.buffer.x--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -552,13 +556,13 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Horizontal Tab (HT) (Ctrl-I).
|
||||
*/
|
||||
public tab(): void {
|
||||
if (this._terminal.buffer.x >= this._terminal.cols) {
|
||||
if (this._bufferService.buffer.x >= this._terminal.cols) {
|
||||
return;
|
||||
}
|
||||
const originalX = this._terminal.buffer.x;
|
||||
this._terminal.buffer.x = this._terminal.buffer.nextStop();
|
||||
const originalX = this._bufferService.buffer.x;
|
||||
this._bufferService.buffer.x = this._bufferService.buffer.nextStop();
|
||||
if (this._terminal.options.screenReaderMode) {
|
||||
this._terminal.onA11yTabEmitter.fire(this._terminal.buffer.x - originalX);
|
||||
this._terminal.onA11yTabEmitter.fire(this._bufferService.buffer.x - originalX);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,10 +588,10 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Restrict cursor to viewport size / scroll margin (origin mode).
|
||||
*/
|
||||
private _restrictCursor(): void {
|
||||
this._terminal.buffer.x = Math.min(this._terminal.cols - 1, Math.max(0, this._terminal.buffer.x));
|
||||
this._terminal.buffer.y = this._terminal.originMode
|
||||
? Math.min(this._terminal.buffer.scrollBottom, Math.max(this._terminal.buffer.scrollTop, this._terminal.buffer.y))
|
||||
: Math.min(this._terminal.rows - 1, Math.max(0, this._terminal.buffer.y));
|
||||
this._bufferService.buffer.x = Math.min(this._terminal.cols - 1, Math.max(0, this._bufferService.buffer.x));
|
||||
this._bufferService.buffer.y = this._terminal.originMode
|
||||
? Math.min(this._bufferService.buffer.scrollBottom, Math.max(this._bufferService.buffer.scrollTop, this._bufferService.buffer.y))
|
||||
: Math.min(this._terminal.rows - 1, Math.max(0, this._bufferService.buffer.y));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -595,11 +599,11 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
private _setCursor(x: number, y: number): void {
|
||||
if (this._terminal.originMode) {
|
||||
this._terminal.buffer.x = x;
|
||||
this._terminal.buffer.y = this._terminal.buffer.scrollTop + y;
|
||||
this._bufferService.buffer.x = x;
|
||||
this._bufferService.buffer.y = this._bufferService.buffer.scrollTop + y;
|
||||
} else {
|
||||
this._terminal.buffer.x = x;
|
||||
this._terminal.buffer.y = y;
|
||||
this._bufferService.buffer.x = x;
|
||||
this._bufferService.buffer.y = y;
|
||||
}
|
||||
this._restrictCursor();
|
||||
}
|
||||
@@ -611,7 +615,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
// for relative changes we have to make sure we are within 0 .. cols/rows - 1
|
||||
// before calculating the new position
|
||||
this._restrictCursor();
|
||||
this._setCursor(this._terminal.buffer.x + x, this._terminal.buffer.y + y);
|
||||
this._setCursor(this._bufferService.buffer.x + x, this._bufferService.buffer.y + y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -653,7 +657,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
public cursorNextLine(params: IParams): void {
|
||||
this._moveCursor(0, params.params[0] || 1);
|
||||
this._terminal.buffer.x = 0;
|
||||
this._bufferService.buffer.x = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -663,7 +667,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
public cursorPrecedingLine(params: IParams): void {
|
||||
this._moveCursor(0, -(params.params[0] || 1));
|
||||
this._terminal.buffer.x = 0;
|
||||
this._bufferService.buffer.x = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -671,7 +675,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Cursor Character Absolute [column] (default = [row,1]) (CHA).
|
||||
*/
|
||||
public cursorCharAbsolute(params: IParams): void {
|
||||
this._setCursor((params.params[0] || 1) - 1, this._terminal.buffer.y);
|
||||
this._setCursor((params.params[0] || 1) - 1, this._bufferService.buffer.y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -692,7 +696,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Currently same functionality as CHA.
|
||||
*/
|
||||
public charPosAbsolute(params: IParams): void {
|
||||
this._setCursor((params.params[0] || 1) - 1, this._terminal.buffer.y);
|
||||
this._setCursor((params.params[0] || 1) - 1, this._bufferService.buffer.y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -709,7 +713,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* [row] (default = [1,column])
|
||||
*/
|
||||
public linePosAbsolute(params: IParams): void {
|
||||
this._setCursor(this._terminal.buffer.x, (params.params[0] || 1) - 1);
|
||||
this._setCursor(this._bufferService.buffer.x, (params.params[0] || 1) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -742,9 +746,9 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
public tabClear(params: IParams): void {
|
||||
const param = params.params[0];
|
||||
if (param === 0) {
|
||||
delete this._terminal.buffer.tabs[this._terminal.buffer.x];
|
||||
delete this._bufferService.buffer.tabs[this._bufferService.buffer.x];
|
||||
} else if (param === 3) {
|
||||
this._terminal.buffer.tabs = {};
|
||||
this._bufferService.buffer.tabs = {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -753,12 +757,12 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
|
||||
*/
|
||||
public cursorForwardTab(params: IParams): void {
|
||||
if (this._terminal.buffer.x >= this._terminal.cols) {
|
||||
if (this._bufferService.buffer.x >= this._terminal.cols) {
|
||||
return;
|
||||
}
|
||||
let param = params.params[0] || 1;
|
||||
while (param--) {
|
||||
this._terminal.buffer.x = this._terminal.buffer.nextStop();
|
||||
this._bufferService.buffer.x = this._bufferService.buffer.nextStop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -766,13 +770,13 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
|
||||
*/
|
||||
public cursorBackwardTab(params: IParams): void {
|
||||
if (this._terminal.buffer.x >= this._terminal.cols) {
|
||||
if (this._bufferService.buffer.x >= this._terminal.cols) {
|
||||
return;
|
||||
}
|
||||
let param = params.params[0] || 1;
|
||||
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
const buffer = this._bufferService.buffer;
|
||||
|
||||
while (param--) {
|
||||
buffer.x = buffer.prevStop();
|
||||
@@ -788,11 +792,11 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* @param end end - 1 is last erased cell
|
||||
*/
|
||||
private _eraseInBufferLine(y: number, start: number, end: number, clearWrap: boolean = false): void {
|
||||
const line = this._terminal.buffer.lines.get(this._terminal.buffer.ybase + y);
|
||||
const line = this._bufferService.buffer.lines.get(this._bufferService.buffer.ybase + y);
|
||||
line.replaceCells(
|
||||
start,
|
||||
end,
|
||||
this._terminal.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
this._bufferService.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
);
|
||||
if (clearWrap) {
|
||||
line.isWrapped = false;
|
||||
@@ -805,8 +809,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* @param y row index
|
||||
*/
|
||||
private _resetBufferLine(y: number): void {
|
||||
const line = this._terminal.buffer.lines.get(this._terminal.buffer.ybase + y);
|
||||
line.fill(this._terminal.buffer.getNullCell(this._terminal.eraseAttrData()));
|
||||
const line = this._bufferService.buffer.lines.get(this._bufferService.buffer.ybase + y);
|
||||
line.fill(this._bufferService.buffer.getNullCell(this._terminal.eraseAttrData()));
|
||||
line.isWrapped = false;
|
||||
}
|
||||
|
||||
@@ -827,22 +831,22 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
let j;
|
||||
switch (params.params[0]) {
|
||||
case 0:
|
||||
j = this._terminal.buffer.y;
|
||||
j = this._bufferService.buffer.y;
|
||||
this._terminal.updateRange(j);
|
||||
this._eraseInBufferLine(j++, this._terminal.buffer.x, this._terminal.cols, this._terminal.buffer.x === 0);
|
||||
this._eraseInBufferLine(j++, this._bufferService.buffer.x, this._terminal.cols, this._bufferService.buffer.x === 0);
|
||||
for (; j < this._terminal.rows; j++) {
|
||||
this._resetBufferLine(j);
|
||||
}
|
||||
this._terminal.updateRange(j);
|
||||
break;
|
||||
case 1:
|
||||
j = this._terminal.buffer.y;
|
||||
j = this._bufferService.buffer.y;
|
||||
this._terminal.updateRange(j);
|
||||
// Deleted front part of line and everything before. This line will no longer be wrapped.
|
||||
this._eraseInBufferLine(j, 0, this._terminal.buffer.x + 1, true);
|
||||
if (this._terminal.buffer.x + 1 >= this._terminal.cols) {
|
||||
this._eraseInBufferLine(j, 0, this._bufferService.buffer.x + 1, true);
|
||||
if (this._bufferService.buffer.x + 1 >= this._terminal.cols) {
|
||||
// Deleted entire previous line. This next line can no longer be wrapped.
|
||||
this._terminal.buffer.lines.get(j + 1).isWrapped = false;
|
||||
this._bufferService.buffer.lines.get(j + 1).isWrapped = false;
|
||||
}
|
||||
while (j--) {
|
||||
this._resetBufferLine(j);
|
||||
@@ -859,11 +863,11 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
break;
|
||||
case 3:
|
||||
// Clear scrollback (everything not in viewport)
|
||||
const scrollBackSize = this._terminal.buffer.lines.length - this._terminal.rows;
|
||||
const scrollBackSize = this._bufferService.buffer.lines.length - this._terminal.rows;
|
||||
if (scrollBackSize > 0) {
|
||||
this._terminal.buffer.lines.trimStart(scrollBackSize);
|
||||
this._terminal.buffer.ybase = Math.max(this._terminal.buffer.ybase - scrollBackSize, 0);
|
||||
this._terminal.buffer.ydisp = Math.max(this._terminal.buffer.ydisp - scrollBackSize, 0);
|
||||
this._bufferService.buffer.lines.trimStart(scrollBackSize);
|
||||
this._bufferService.buffer.ybase = Math.max(this._bufferService.buffer.ybase - scrollBackSize, 0);
|
||||
this._bufferService.buffer.ydisp = Math.max(this._bufferService.buffer.ydisp - scrollBackSize, 0);
|
||||
// Force a scroll event to refresh viewport
|
||||
this._onScroll.fire(0);
|
||||
}
|
||||
@@ -886,16 +890,16 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
this._restrictCursor();
|
||||
switch (params.params[0]) {
|
||||
case 0:
|
||||
this._eraseInBufferLine(this._terminal.buffer.y, this._terminal.buffer.x, this._terminal.cols);
|
||||
this._eraseInBufferLine(this._bufferService.buffer.y, this._bufferService.buffer.x, this._terminal.cols);
|
||||
break;
|
||||
case 1:
|
||||
this._eraseInBufferLine(this._terminal.buffer.y, 0, this._terminal.buffer.x + 1);
|
||||
this._eraseInBufferLine(this._bufferService.buffer.y, 0, this._bufferService.buffer.x + 1);
|
||||
break;
|
||||
case 2:
|
||||
this._eraseInBufferLine(this._terminal.buffer.y, 0, this._terminal.cols);
|
||||
this._eraseInBufferLine(this._bufferService.buffer.y, 0, this._terminal.cols);
|
||||
break;
|
||||
}
|
||||
this._terminal.updateRange(this._terminal.buffer.y);
|
||||
this._terminal.updateRange(this._bufferService.buffer.y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -907,7 +911,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
let param = params.params[0] || 1;
|
||||
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
const buffer = this._bufferService.buffer;
|
||||
|
||||
if (buffer.y > buffer.scrollBottom || buffer.y < buffer.scrollTop) {
|
||||
return;
|
||||
@@ -939,7 +943,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
let param = params.params[0] || 1;
|
||||
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
const buffer = this._bufferService.buffer;
|
||||
|
||||
if (buffer.y > buffer.scrollBottom || buffer.y < buffer.scrollTop) {
|
||||
return;
|
||||
@@ -969,14 +973,14 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
public insertChars(params: IParams): void {
|
||||
this._restrictCursor();
|
||||
const line = this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase);
|
||||
const line = this._bufferService.buffer.lines.get(this._bufferService.buffer.y + this._bufferService.buffer.ybase);
|
||||
if (line) {
|
||||
line.insertCells(
|
||||
this._terminal.buffer.x,
|
||||
this._bufferService.buffer.x,
|
||||
params.params[0] || 1,
|
||||
this._terminal.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
this._bufferService.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
);
|
||||
this._terminal.updateRange(this._terminal.buffer.y);
|
||||
this._terminal.updateRange(this._bufferService.buffer.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -986,14 +990,14 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
public deleteChars(params: IParams): void {
|
||||
this._restrictCursor();
|
||||
const line = this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase);
|
||||
const line = this._bufferService.buffer.lines.get(this._bufferService.buffer.y + this._bufferService.buffer.ybase);
|
||||
if (line) {
|
||||
line.deleteCells(
|
||||
this._terminal.buffer.x,
|
||||
this._bufferService.buffer.x,
|
||||
params.params[0] || 1,
|
||||
this._terminal.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
this._bufferService.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
);
|
||||
this._terminal.updateRange(this._terminal.buffer.y);
|
||||
this._terminal.updateRange(this._bufferService.buffer.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1004,7 +1008,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
let param = params.params[0] || 1;
|
||||
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
const buffer = this._bufferService.buffer;
|
||||
|
||||
while (param--) {
|
||||
buffer.lines.splice(buffer.ybase + buffer.scrollTop, 1);
|
||||
@@ -1023,7 +1027,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
let param = params.params[0] || 1;
|
||||
|
||||
// make buffer local for faster access
|
||||
const buffer = this._terminal.buffer;
|
||||
const buffer = this._bufferService.buffer;
|
||||
|
||||
while (param--) {
|
||||
buffer.lines.splice(buffer.ybase + buffer.scrollBottom, 1);
|
||||
@@ -1041,14 +1045,14 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
public eraseChars(params: IParams): void {
|
||||
this._restrictCursor();
|
||||
const line = this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase);
|
||||
const line = this._bufferService.buffer.lines.get(this._bufferService.buffer.y + this._bufferService.buffer.ybase);
|
||||
if (line) {
|
||||
line.replaceCells(
|
||||
this._terminal.buffer.x,
|
||||
this._terminal.buffer.x + (params.params[0] || 1),
|
||||
this._terminal.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
this._bufferService.buffer.x,
|
||||
this._bufferService.buffer.x + (params.params[0] || 1),
|
||||
this._bufferService.buffer.getNullCell(this._terminal.eraseAttrData())
|
||||
);
|
||||
this._terminal.updateRange(this._terminal.buffer.y);
|
||||
this._terminal.updateRange(this._bufferService.buffer.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1349,7 +1353,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
// FALL-THROUGH
|
||||
case 47: // alt screen buffer
|
||||
case 1047: // alt screen buffer
|
||||
this._terminal.buffers.activateAltBuffer(this._terminal.eraseAttrData());
|
||||
this._bufferService.buffers.activateAltBuffer(this._terminal.eraseAttrData());
|
||||
this._terminal.refresh(0, this._terminal.rows - 1);
|
||||
if (this._terminal.viewport) {
|
||||
this._terminal.viewport.syncScrollArea();
|
||||
@@ -1531,7 +1535,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
case 47: // normal screen buffer
|
||||
case 1047: // normal screen buffer - clearing it first
|
||||
// Ensure the selection manager has the correct buffer
|
||||
this._terminal.buffers.activateNormalBuffer();
|
||||
this._bufferService.buffers.activateNormalBuffer();
|
||||
if (param === 1049) {
|
||||
this.restoreCursor();
|
||||
}
|
||||
@@ -1815,8 +1819,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
break;
|
||||
case 6:
|
||||
// cursor position
|
||||
const y = this._terminal.buffer.y + 1;
|
||||
const x = this._terminal.buffer.x + 1;
|
||||
const y = this._bufferService.buffer.y + 1;
|
||||
const x = this._bufferService.buffer.x + 1;
|
||||
this._coreService.triggerDataEvent(`${C0.ESC}[${y};${x}R`);
|
||||
break;
|
||||
}
|
||||
@@ -1826,8 +1830,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
switch (params.params[0]) {
|
||||
case 6:
|
||||
// cursor position
|
||||
const y = this._terminal.buffer.y + 1;
|
||||
const x = this._terminal.buffer.x + 1;
|
||||
const y = this._bufferService.buffer.y + 1;
|
||||
const x = this._bufferService.buffer.x + 1;
|
||||
this._coreService.triggerDataEvent(`${C0.ESC}[?${y};${x}R`);
|
||||
break;
|
||||
case 15:
|
||||
@@ -1865,10 +1869,10 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
this._terminal.viewport.syncScrollArea();
|
||||
}
|
||||
this._coreService.decPrivateModes.applicationCursorKeys = false;
|
||||
this._terminal.buffer.scrollTop = 0;
|
||||
this._terminal.buffer.scrollBottom = this._terminal.rows - 1;
|
||||
this._bufferService.buffer.scrollTop = 0;
|
||||
this._bufferService.buffer.scrollBottom = this._terminal.rows - 1;
|
||||
this._terminal.curAttrData = DEFAULT_ATTR_DATA.clone();
|
||||
this._terminal.buffer.x = this._terminal.buffer.y = 0; // ?
|
||||
this._bufferService.buffer.x = this._bufferService.buffer.y = 0; // ?
|
||||
this._terminal.charset = null;
|
||||
this._terminal.glevel = 0; // ??
|
||||
this._terminal.charsets = [null]; // ??
|
||||
@@ -1927,8 +1931,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
}
|
||||
|
||||
if (bottom > top) {
|
||||
this._terminal.buffer.scrollTop = top - 1;
|
||||
this._terminal.buffer.scrollBottom = bottom - 1;
|
||||
this._bufferService.buffer.scrollTop = top - 1;
|
||||
this._bufferService.buffer.scrollBottom = bottom - 1;
|
||||
this._setCursor(0, 0);
|
||||
}
|
||||
}
|
||||
@@ -1940,11 +1944,11 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Save cursor (ANSI.SYS).
|
||||
*/
|
||||
public saveCursor(params?: IParams): void {
|
||||
this._terminal.buffer.savedX = this._terminal.buffer.x;
|
||||
this._terminal.buffer.savedY = this._terminal.buffer.ybase + this._terminal.buffer.y;
|
||||
this._terminal.buffer.savedCurAttrData.fg = this._terminal.curAttrData.fg;
|
||||
this._terminal.buffer.savedCurAttrData.bg = this._terminal.curAttrData.bg;
|
||||
this._terminal.buffer.savedCharset = this._terminal.charset;
|
||||
this._bufferService.buffer.savedX = this._bufferService.buffer.x;
|
||||
this._bufferService.buffer.savedY = this._bufferService.buffer.ybase + this._bufferService.buffer.y;
|
||||
this._bufferService.buffer.savedCurAttrData.fg = this._terminal.curAttrData.fg;
|
||||
this._bufferService.buffer.savedCurAttrData.bg = this._terminal.curAttrData.bg;
|
||||
this._bufferService.buffer.savedCharset = this._terminal.charset;
|
||||
}
|
||||
|
||||
|
||||
@@ -1954,13 +1958,13 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Restore cursor (ANSI.SYS).
|
||||
*/
|
||||
public restoreCursor(params?: IParams): void {
|
||||
this._terminal.buffer.x = this._terminal.buffer.savedX || 0;
|
||||
this._terminal.buffer.y = Math.max(this._terminal.buffer.savedY - this._terminal.buffer.ybase, 0);
|
||||
this._terminal.curAttrData.fg = this._terminal.buffer.savedCurAttrData.fg;
|
||||
this._terminal.curAttrData.bg = this._terminal.buffer.savedCurAttrData.bg;
|
||||
this._bufferService.buffer.x = this._bufferService.buffer.savedX || 0;
|
||||
this._bufferService.buffer.y = Math.max(this._bufferService.buffer.savedY - this._bufferService.buffer.ybase, 0);
|
||||
this._terminal.curAttrData.fg = this._bufferService.buffer.savedCurAttrData.fg;
|
||||
this._terminal.curAttrData.bg = this._bufferService.buffer.savedCurAttrData.bg;
|
||||
this._terminal.charset = (this as any)._savedCharset;
|
||||
if (this._terminal.buffer.savedCharset) {
|
||||
this._terminal.charset = this._terminal.buffer.savedCharset;
|
||||
if (this._bufferService.buffer.savedCharset) {
|
||||
this._terminal.charset = this._bufferService.buffer.savedCharset;
|
||||
}
|
||||
this._restrictCursor();
|
||||
}
|
||||
@@ -1982,7 +1986,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* Moves cursor to first position on next line.
|
||||
*/
|
||||
public nextLine(): void {
|
||||
this._terminal.buffer.x = 0;
|
||||
this._bufferService.buffer.x = 0;
|
||||
this.index();
|
||||
}
|
||||
|
||||
@@ -2059,9 +2063,9 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
public index(): void {
|
||||
this._restrictCursor();
|
||||
this._terminal.buffer.y++;
|
||||
if (this._terminal.buffer.y > this._terminal.buffer.scrollBottom) {
|
||||
this._terminal.buffer.y--;
|
||||
this._bufferService.buffer.y++;
|
||||
if (this._bufferService.buffer.y > this._bufferService.buffer.scrollBottom) {
|
||||
this._bufferService.buffer.y--;
|
||||
this._terminal.scroll();
|
||||
}
|
||||
this._restrictCursor();
|
||||
@@ -2075,7 +2079,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
* the value of the active column when the terminal receives an HTS.
|
||||
*/
|
||||
public tabSet(): void {
|
||||
this._terminal.buffer.tabs[this._terminal.buffer.x] = true;
|
||||
this._bufferService.buffer.tabs[this._bufferService.buffer.x] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2087,7 +2091,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
*/
|
||||
public reverseIndex(): void {
|
||||
this._restrictCursor();
|
||||
const buffer = this._terminal.buffer;
|
||||
const buffer = this._bufferService.buffer;
|
||||
if (buffer.y === buffer.scrollTop) {
|
||||
// possibly move the code below to term.reverseScroll();
|
||||
// test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
|
||||
@@ -2142,7 +2146,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
cell.fg = this._terminal.curAttrData.fg;
|
||||
cell.bg = this._terminal.curAttrData.bg;
|
||||
|
||||
const buffer = this._terminal.buffer;
|
||||
const buffer = this._bufferService.buffer;
|
||||
|
||||
this._setCursor(0, 0);
|
||||
for (let yOffset = 0; yOffset < this._terminal.rows; ++yOffset) {
|
||||
|
||||
+1
-1
@@ -297,7 +297,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
|
||||
this._userScrolling = false;
|
||||
|
||||
// Register input handler and refire/handle events
|
||||
this._inputHandler = new InputHandler(this, this._coreService);
|
||||
this._inputHandler = new InputHandler(this, this._bufferService, this._coreService);
|
||||
this._inputHandler.onCursorMove(() => this._onCursorMove.fire());
|
||||
this._inputHandler.onLineFeed(() => this._onLineFeed.fire());
|
||||
this.register(this._inputHandler);
|
||||
|
||||
Reference in New Issue
Block a user