Add some tests
This commit is contained in:
@@ -11,7 +11,7 @@ import { IBufferService, IUnicodeService } from 'common/services/Services';
|
|||||||
import { Linkifier } from 'browser/Linkifier';
|
import { Linkifier } from 'browser/Linkifier';
|
||||||
import { MockLogService, MockUnicodeService } from 'common/TestUtils.test';
|
import { MockLogService, MockUnicodeService } from 'common/TestUtils.test';
|
||||||
import { IRegisteredLinkMatcher, IMouseZoneManager, IMouseZone } from 'browser/Types';
|
import { IRegisteredLinkMatcher, IMouseZoneManager, IMouseZone } from 'browser/Types';
|
||||||
import { IMarker } from 'common/Types';
|
import { IMarker, ITerminalOptions } from 'common/Types';
|
||||||
|
|
||||||
const INIT_COLS = 80;
|
const INIT_COLS = 80;
|
||||||
const INIT_ROWS = 24;
|
const INIT_ROWS = 24;
|
||||||
@@ -1501,6 +1501,22 @@ describe('Terminal', () => {
|
|||||||
assert.deepEqual(markers.map(el => el.line), [-1, -1, 0, 1, 2]);
|
assert.deepEqual(markers.map(el => el.line), [-1, -1, 0, 1, 2]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('options', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
term = new TestTerminal({});
|
||||||
|
});
|
||||||
|
it('get options', () => {
|
||||||
|
assert.equal(term.options.cols, 80);
|
||||||
|
assert.equal(term.options.rows, 24);
|
||||||
|
});
|
||||||
|
it('set options', async () => {
|
||||||
|
term.options.cols = 40;
|
||||||
|
assert.equal(term.options.cols, 40);
|
||||||
|
term.options.rows = 20;
|
||||||
|
assert.equal(term.options.rows, 20);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
class TestLinkifier extends Linkifier {
|
class TestLinkifier extends Linkifier {
|
||||||
|
|||||||
@@ -74,13 +74,6 @@ export class Terminal extends CoreTerminal implements ITerminal {
|
|||||||
|
|
||||||
public browser: IBrowser = Browser as any;
|
public browser: IBrowser = Browser as any;
|
||||||
|
|
||||||
public get options(): ITerminalOptions { return this.optionsService.options; }
|
|
||||||
public set options(options: ITerminalOptions) {
|
|
||||||
for (const key in options) {
|
|
||||||
this.optionsService.options[key] = options[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _customKeyEventHandler: CustomKeyEventHandler | undefined;
|
private _customKeyEventHandler: CustomKeyEventHandler | undefined;
|
||||||
|
|
||||||
// browser services
|
// browser services
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ export class MockTerminal implements ITerminal {
|
|||||||
public linkifier2!: ILinkifier2;
|
public linkifier2!: ILinkifier2;
|
||||||
public isFocused!: boolean;
|
public isFocused!: boolean;
|
||||||
public options: ITerminalOptions = {};
|
public options: ITerminalOptions = {};
|
||||||
|
public publicOptions: ITerminalOptions = {};
|
||||||
public element!: HTMLElement;
|
public element!: HTMLElement;
|
||||||
public screenElement!: HTMLElement;
|
public screenElement!: HTMLElement;
|
||||||
public rowContainer!: HTMLElement;
|
public rowContainer!: HTMLElement;
|
||||||
|
|||||||
Vendored
+1
@@ -16,6 +16,7 @@ export interface ITerminal extends IPublicTerminal, ICoreTerminal {
|
|||||||
browser: IBrowser;
|
browser: IBrowser;
|
||||||
buffer: IBuffer;
|
buffer: IBuffer;
|
||||||
viewport: IViewport | undefined;
|
viewport: IViewport | undefined;
|
||||||
|
publicOptions: ITerminalOptions;
|
||||||
options: ITerminalOptions;
|
options: ITerminalOptions;
|
||||||
linkifier: ILinkifier;
|
linkifier: ILinkifier;
|
||||||
linkifier2: ILinkifier2;
|
linkifier2: ILinkifier2;
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2016 The xterm.js authors. All rights reserved.
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Terminal } from 'browser/public/Terminal';
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import { ITerminalOptions } from 'common/Types';
|
||||||
|
|
||||||
|
const INIT_COLS = 80;
|
||||||
|
const INIT_ROWS = 24;
|
||||||
|
|
||||||
|
describe('Public Terminal', () => {
|
||||||
|
let term: Terminal;
|
||||||
|
const termOptions = {
|
||||||
|
cols: INIT_COLS,
|
||||||
|
rows: INIT_ROWS
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('options', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
term = new Terminal(termOptions);
|
||||||
|
});
|
||||||
|
it('get options', () => {
|
||||||
|
const options: ITerminalOptions = term.options;
|
||||||
|
assert.equal(options.cols, 80);
|
||||||
|
assert.equal(options.rows, 24);
|
||||||
|
});
|
||||||
|
it('set options', async () => {
|
||||||
|
const options: ITerminalOptions = term.options;
|
||||||
|
assert.throws(() => options.cols = 40);
|
||||||
|
assert.throws(() => options.rows = 20);
|
||||||
|
term.options.scrollback = 1;
|
||||||
|
assert.equal(term.options.scrollback, 1);
|
||||||
|
term.options= {
|
||||||
|
fontSize: 12,
|
||||||
|
fontFamily: 'Arial'
|
||||||
|
};
|
||||||
|
assert.equal(term.options.fontSize, 12);
|
||||||
|
assert.equal(term.options.fontFamily, 'Arial');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -90,10 +90,10 @@ export class Terminal implements ITerminalApi {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
public get options(): ITerminalOptions {
|
public get options(): ITerminalOptions {
|
||||||
return this._core.options;
|
return this._core.publicOptions;
|
||||||
}
|
}
|
||||||
public set options(options: ITerminalOptions) {
|
public set options(options: ITerminalOptions) {
|
||||||
this._core.options = options;
|
this._core.publicOptions = options;
|
||||||
}
|
}
|
||||||
public blur(): void {
|
public blur(): void {
|
||||||
this._core.blur();
|
this._core.blur();
|
||||||
|
|||||||
@@ -22,12 +22,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Disposable } from 'common/Lifecycle';
|
import { Disposable } from 'common/Lifecycle';
|
||||||
import { IInstantiationService, IOptionsService, IBufferService, ILogService, ICharsetService, ICoreService, ICoreMouseService, IUnicodeService, IDirtyRowService, LogLevelEnum } from 'common/services/Services';
|
import { IInstantiationService, IOptionsService, IBufferService, ILogService, ICharsetService, ICoreService, ICoreMouseService, IUnicodeService, IDirtyRowService, LogLevelEnum, ITerminalOptions } from 'common/services/Services';
|
||||||
import { InstantiationService } from 'common/services/InstantiationService';
|
import { InstantiationService } from 'common/services/InstantiationService';
|
||||||
import { LogService } from 'common/services/LogService';
|
import { LogService } from 'common/services/LogService';
|
||||||
import { BufferService, MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/BufferService';
|
import { BufferService, MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/BufferService';
|
||||||
import { OptionsService } from 'common/services/OptionsService';
|
import { OptionsService } from 'common/services/OptionsService';
|
||||||
import { IDisposable, IBufferLine, IAttributeData, ICoreTerminal, IKeyboardEvent, IScrollEvent, ScrollSource, ITerminalOptions } from 'common/Types';
|
import { IDisposable, IBufferLine, IAttributeData, ICoreTerminal, IKeyboardEvent, IScrollEvent, ScrollSource, ITerminalOptions as IPublicTerminalOptions } from 'common/Types';
|
||||||
import { CoreService } from 'common/services/CoreService';
|
import { CoreService } from 'common/services/CoreService';
|
||||||
import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter';
|
import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter';
|
||||||
import { CoreMouseService } from 'common/services/CoreMouseService';
|
import { CoreMouseService } from 'common/services/CoreMouseService';
|
||||||
@@ -86,12 +86,18 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
|
|||||||
public get cols(): number { return this._bufferService.cols; }
|
public get cols(): number { return this._bufferService.cols; }
|
||||||
public get rows(): number { return this._bufferService.rows; }
|
public get rows(): number { return this._bufferService.rows; }
|
||||||
public get buffers(): IBufferSet { return this._bufferService.buffers; }
|
public get buffers(): IBufferSet { return this._bufferService.buffers; }
|
||||||
public get options(): ITerminalOptions { return this.optionsService.publicOptions; }
|
public get publicOptions(): IPublicTerminalOptions { return this.optionsService.publicOptions; }
|
||||||
public set options(options: ITerminalOptions) {
|
public set publicOptions(options: IPublicTerminalOptions) {
|
||||||
for (const key in options) {
|
for (const key in options) {
|
||||||
this.optionsService.publicOptions[key] = options[key];
|
this.optionsService.publicOptions[key] = options[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public get options(): ITerminalOptions { return this.optionsService.options; }
|
||||||
|
public set options(options: ITerminalOptions) {
|
||||||
|
for (const key in options) {
|
||||||
|
this.optionsService.options[key] = options[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
options: Partial<ITerminalOptions>
|
options: Partial<ITerminalOptions>
|
||||||
|
|||||||
Reference in New Issue
Block a user