From 338558d86c6a5a018347664bf7bdead3b89c3e63 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 31 Dec 2018 20:00:16 -0800 Subject: [PATCH] Make Terminal API properties readonly Fixes #1867 --- src/Buffer.test.ts | 4 ++-- src/BufferSet.test.ts | 4 ++-- src/Linkifier.test.ts | 14 +++++++------- src/SelectionManager.test.ts | 4 ++-- src/SelectionModel.test.ts | 4 ++-- src/Types.ts | 2 +- typings/xterm.d.ts | 18 +++++++++++------- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/Buffer.test.ts b/src/Buffer.test.ts index 0546dfe809..9d1d50c8e0 100644 --- a/src/Buffer.test.ts +++ b/src/Buffer.test.ts @@ -19,8 +19,8 @@ describe('Buffer', () => { beforeEach(() => { terminal = new MockTerminal(); - terminal.cols = INIT_COLS; - terminal.rows = INIT_ROWS; + (terminal as any).cols = INIT_COLS; + (terminal as any).rows = INIT_ROWS; terminal.options.scrollback = 1000; buffer = new Buffer(terminal, true); }); diff --git a/src/BufferSet.test.ts b/src/BufferSet.test.ts index 26f9cd42f7..576a8ca472 100644 --- a/src/BufferSet.test.ts +++ b/src/BufferSet.test.ts @@ -15,8 +15,8 @@ describe('BufferSet', () => { beforeEach(() => { terminal = new MockTerminal(); - terminal.cols = 80; - terminal.rows = 24; + (terminal as any).cols = 80; + (terminal as any).rows = 24; terminal.options.scrollback = 1000; bufferSet = new BufferSet(terminal); }); diff --git a/src/Linkifier.test.ts b/src/Linkifier.test.ts index 0ba1294a0e..07dbf1b3b0 100644 --- a/src/Linkifier.test.ts +++ b/src/Linkifier.test.ts @@ -41,8 +41,8 @@ describe('Linkifier', () => { beforeEach(() => { terminal = new MockTerminal(); - terminal.cols = 100; - terminal.rows = 10; + (terminal as any).cols = 100; + (terminal as any).rows = 10; terminal.buffer = new MockBuffer(); (terminal.buffer).setLines(new CircularList(20)); terminal.buffer.ydisp = 0; @@ -65,7 +65,7 @@ describe('Linkifier', () => { function assertLinkifiesRow(rowText: string, linkMatcherRegex: RegExp, links: {x: number, length: number}[], done: MochaDone): void { addRow(rowText); linkifier.registerLinkMatcher(linkMatcherRegex, () => {}); - terminal.rows = terminal.buffer.lines.length - 1; + (terminal as any).rows = terminal.buffer.lines.length - 1; linkifier.linkifyRows(); // Allow linkify to happen setTimeout(() => { @@ -142,19 +142,19 @@ describe('Linkifier', () => { }); describe('multi-line links', () => { it('should match links that start on line 1/2 of a wrapped line and end on the last character of line 1/2', done => { - terminal.cols = 4; + (terminal as any).cols = 4; assertLinkifiesMultiLineLink('12345', /1234/, [{x1: 0, x2: 4, y1: 0, y2: 0}], done); }); it('should match links that start on line 1/2 of a wrapped line and wrap to line 2/2', done => { - terminal.cols = 4; + (terminal as any).cols = 4; assertLinkifiesMultiLineLink('12345', /12345/, [{x1: 0, x2: 1, y1: 0, y2: 1}], done); }); it('should match links that start and end on line 2/2 of a wrapped line', done => { - terminal.cols = 4; + (terminal as any).cols = 4; assertLinkifiesMultiLineLink('12345678', /5678/, [{x1: 0, x2: 4, y1: 1, y2: 1}], done); }); it('should match links that start on line 2/3 of a wrapped line and wrap to line 3/3', done => { - terminal.cols = 4; + (terminal as any).cols = 4; assertLinkifiesMultiLineLink('123456789', /56789/, [{x1: 0, x2: 1, y1: 1, y2: 2}], done); }); }); diff --git a/src/SelectionManager.test.ts b/src/SelectionManager.test.ts index 2f74ccdab0..21bc6754b2 100644 --- a/src/SelectionManager.test.ts +++ b/src/SelectionManager.test.ts @@ -45,8 +45,8 @@ describe('SelectionManager', () => { beforeEach(() => { terminal = new TestMockTerminal(); - terminal.cols = 80; - terminal.rows = 2; + (terminal as any).cols = 80; + (terminal as any).rows = 2; terminal.options.scrollback = 100; terminal.buffers = new BufferSet(terminal); terminal.buffer = terminal.buffers.active; diff --git a/src/SelectionModel.test.ts b/src/SelectionModel.test.ts index 8d4b30bb58..d49f41d0c7 100644 --- a/src/SelectionModel.test.ts +++ b/src/SelectionModel.test.ts @@ -23,8 +23,8 @@ describe('SelectionManager', () => { beforeEach(() => { terminal = new MockTerminal(); - terminal.cols = 80; - terminal.rows = 2; + (terminal as any).cols = 80; + (terminal as any).rows = 2; terminal.options.scrollback = 10; terminal.buffers = new BufferSet(terminal); terminal.buffer = terminal.buffers.active; diff --git a/src/Types.ts b/src/Types.ts index 8ebb28d3e3..e6f36ac42d 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -237,7 +237,7 @@ export interface IBufferAccessor { } export interface IElementAccessor { - element: HTMLElement; + readonly element: HTMLElement; } export interface ILinkifierAccessor { diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 7528bb5540..b092429673 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -325,28 +325,32 @@ declare module 'xterm' { /** * The element containing the terminal. */ - element: HTMLElement; + readonly element: HTMLElement; /** * The textarea that accepts input for the terminal. */ - textarea: HTMLTextAreaElement; + readonly textarea: HTMLTextAreaElement; /** - * The number of rows in the terminal's viewport. + * The number of rows in the terminal's viewport. Use + * `ITerminalOptions.rows` to set this in the constructor and + * `Terminal.resize` for when the terminal exists. */ - rows: number; + readonly rows: number; /** - * The number of columns in the terminal's viewport. + * The number of columns in the terminal's viewport. Use + * `ITerminalOptions.cols` to set this in the constructor and + * `Terminal.resize` for when the terminal exists. */ - cols: number; + readonly cols: number; /** * (EXPERIMENTAL) Get all markers registered against the buffer. If the alt * buffer is active this will always return []. */ - markers: IMarker[]; + readonly markers: IMarker[]; /** * Natural language strings that can be localized.