Move cursorState into core service

This commit is contained in:
Daniel Imms
2019-11-07 18:21:06 -08:00
parent 1e1038b2c7
commit 9d7935f8bd
9 changed files with 56 additions and 26 deletions
-11
View File
@@ -163,17 +163,6 @@ describe('Terminal', () => {
}); });
}); });
describe('reset', () => {
it('should not affect cursorState', () => {
term.cursorState = 1;
term.reset();
assert.equal(term.cursorState, 1);
term.cursorState = 0;
term.reset();
assert.equal(term.cursorState, 0);
});
});
describe('clear', () => { describe('clear', () => {
it('should clear a buffer equal to rows', () => { it('should clear a buffer equal to rows', () => {
const promptLine = term.buffer.lines.get(term.buffer.ybase + term.buffer.y); const promptLine = term.buffer.lines.get(term.buffer.ybase + term.buffer.y);
+3 -8
View File
@@ -90,8 +90,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
// TODO: We should remove options once components adopt optionsService // TODO: We should remove options once components adopt optionsService
public get options(): ITerminalOptions { return this.optionsService.options; } public get options(): ITerminalOptions { return this.optionsService.options; }
// TODO: This can be changed to an enum or boolean, 0 and 1 seem to be the only options
public cursorState: number;
public cursorHidden: boolean; public cursorHidden: boolean;
private _customKeyEventHandler: CustomKeyEventHandler; private _customKeyEventHandler: CustomKeyEventHandler;
@@ -251,7 +249,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
private _setup(): void { private _setup(): void {
this._parent = document ? document.body : null; this._parent = document ? document.body : null;
this.cursorState = 0;
this.cursorHidden = false; this.cursorHidden = false;
this._customKeyEventHandler = null; this._customKeyEventHandler = null;
@@ -637,7 +634,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
private _createRenderer(): IRenderer { private _createRenderer(): IRenderer {
switch (this.options.rendererType) { switch (this.options.rendererType) {
case 'canvas': return new Renderer(this._colorManager.colors, this, this._bufferService, this._charSizeService, this.optionsService); case 'canvas': return new Renderer(this._colorManager.colors, this, this._bufferService, this._charSizeService, this.optionsService, this._coreService);
case 'dom': return this._instantiationService.createInstance(DomRenderer, this._colorManager.colors, this.element, this.screenElement, this._viewportElement, this.linkifier); case 'dom': return this._instantiationService.createInstance(DomRenderer, this._colorManager.colors, this.element, this.screenElement, this._viewportElement, this.linkifier);
default: throw new Error(`Unrecognized rendererType "${this.options.rendererType}"`); default: throw new Error(`Unrecognized rendererType "${this.options.rendererType}"`);
} }
@@ -945,8 +942,8 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
* Display the cursor element * Display the cursor element
*/ */
public showCursor(): void { public showCursor(): void {
if (!this.cursorState) { if (!this._coreService.isCursorInitialized) {
this.cursorState = 1; this._coreService.isCursorInitialized = true;
this.refresh(this.buffer.y, this.buffer.y); this.refresh(this.buffer.y, this.buffer.y);
} }
} }
@@ -1510,7 +1507,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this.options.cols = this.cols; this.options.cols = this.cols;
const customKeyEventHandler = this._customKeyEventHandler; const customKeyEventHandler = this._customKeyEventHandler;
const inputHandler = this._inputHandler; const inputHandler = this._inputHandler;
const cursorState = this.cursorState;
const userScrolling = this._userScrolling; const userScrolling = this._userScrolling;
this._setup(); this._setup();
@@ -1522,7 +1518,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
// reattach // reattach
this._customKeyEventHandler = customKeyEventHandler; this._customKeyEventHandler = customKeyEventHandler;
this._inputHandler = inputHandler; this._inputHandler = inputHandler;
this.cursorState = cursorState;
this._userScrolling = userScrolling; this._userScrolling = userScrolling;
// do a full screen refresh // do a full screen refresh
-1
View File
@@ -155,7 +155,6 @@ export interface ITerminal extends IPublicTerminal, IElementAccessor, IBufferAcc
screenElement: HTMLElement; screenElement: HTMLElement;
browser: IBrowser; browser: IBrowser;
cursorHidden: boolean; cursorHidden: boolean;
cursorState: number;
buffer: IBuffer; buffer: IBuffer;
buffers: IBufferSet; buffers: IBufferSet;
isFocused: boolean; isFocused: boolean;
+3
View File
@@ -43,6 +43,9 @@ export class MockCoreMouseService implements ICoreMouseService {
} }
export class MockCoreService implements ICoreService { export class MockCoreService implements ICoreService {
isCursorInitialized: boolean = false;
isCursorHidden: boolean = false;
isFocused: boolean = false;
serviceBrand: any; serviceBrand: any;
decPrivateModes: IDecPrivateModes = {} as any; decPrivateModes: IDecPrivateModes = {} as any;
onData: IEvent<string> = new EventEmitter<string>().event; onData: IEvent<string> = new EventEmitter<string>().event;
+32
View File
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { ICoreService } from 'common/services/Services';
import { CoreService } from 'common/services/CoreService';
import { MockBufferService, MockLogService, MockOptionsService } from 'common/TestUtils.test';
import { assert } from 'chai';
describe('CoreService', () => {
let coreService: ICoreService;
beforeEach(() => {
coreService = new CoreService(
() => {},
new MockBufferService(80, 30),
new MockLogService(),
new MockOptionsService());
});
describe('reset', () => {
it('should not affect isCursorInitialized', () => {
coreService.isCursorInitialized = true;
coreService.reset();
assert.equal(coreService.isCursorInitialized, true);
coreService.isCursorInitialized = false;
coreService.reset();
assert.equal(coreService.isCursorInitialized, false);
});
});
});
+3
View File
@@ -15,6 +15,9 @@ const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({
export class CoreService implements ICoreService { export class CoreService implements ICoreService {
serviceBrand: any; serviceBrand: any;
public isCursorInitialized: boolean = false;
public isCursorHidden: boolean = false;
public isFocused: boolean = false;
public decPrivateModes: IDecPrivateModes; public decPrivateModes: IDecPrivateModes;
private _onData = new EventEmitter<string>(); private _onData = new EventEmitter<string>();
+7
View File
@@ -58,6 +58,13 @@ export const ICoreService = createDecorator<ICoreService>('CoreService');
export interface ICoreService { export interface ICoreService {
serviceBrand: any; serviceBrand: any;
/**
* Initially the cursor will not be visible until the first time the terminal
* is focused.
*/
isCursorInitialized: boolean;
isCursorHidden: boolean;
isFocused: boolean;
readonly decPrivateModes: IDecPrivateModes; readonly decPrivateModes: IDecPrivateModes;
readonly onData: IEvent<string>; readonly onData: IEvent<string>;
+4 -3
View File
@@ -9,7 +9,7 @@ import { ITerminal } from '../Types';
import { ICellData } from 'common/Types'; import { ICellData } from 'common/Types';
import { CellData } from 'common/buffer/CellData'; import { CellData } from 'common/buffer/CellData';
import { IColorSet } from 'browser/Types'; import { IColorSet } from 'browser/Types';
import { IBufferService, IOptionsService } from 'common/services/Services'; import { IBufferService, IOptionsService, ICoreService } from 'common/services/Services';
import { IEventEmitter } from 'common/EventEmitter'; import { IEventEmitter } from 'common/EventEmitter';
interface ICursorState { interface ICursorState {
@@ -39,7 +39,8 @@ export class CursorRenderLayer extends BaseRenderLayer {
rendererId: number, rendererId: number,
private _onRequestRefreshRowsEvent: IEventEmitter<IRequestRefreshRowsEvent>, private _onRequestRefreshRowsEvent: IEventEmitter<IRequestRefreshRowsEvent>,
readonly bufferService: IBufferService, readonly bufferService: IBufferService,
readonly optionsService: IOptionsService readonly optionsService: IOptionsService,
private readonly _coreService: ICoreService
) { ) {
super(container, 'cursor', zIndex, true, colors, rendererId, bufferService, optionsService); super(container, 'cursor', zIndex, true, colors, rendererId, bufferService, optionsService);
this._state = { this._state = {
@@ -127,7 +128,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
private _render(triggeredByAnimationFrame: boolean): void { private _render(triggeredByAnimationFrame: boolean): void {
// Don't draw the cursor if it's hidden // Don't draw the cursor if it's hidden
if (!this._terminal.cursorState || this._terminal.cursorHidden) { if (!this._coreService.isCursorInitialized || this._terminal.cursorHidden) {
this._clearCursor(); this._clearCursor();
return; return;
} }
+4 -3
View File
@@ -13,7 +13,7 @@ import { CharacterJoinerRegistry } from 'browser/renderer/CharacterJoinerRegistr
import { Disposable } from 'common/Lifecycle'; import { Disposable } from 'common/Lifecycle';
import { IColorSet } from 'browser/Types'; import { IColorSet } from 'browser/Types';
import { ICharSizeService } from 'browser/services/Services'; import { ICharSizeService } from 'browser/services/Services';
import { IBufferService, IOptionsService } from 'common/services/Services'; import { IBufferService, IOptionsService, ICoreService } from 'common/services/Services';
import { removeTerminalFromCache } from 'browser/renderer/atlas/CharAtlasCache'; import { removeTerminalFromCache } from 'browser/renderer/atlas/CharAtlasCache';
import { EventEmitter, IEvent } from 'common/EventEmitter'; import { EventEmitter, IEvent } from 'common/EventEmitter';
@@ -36,7 +36,8 @@ export class Renderer extends Disposable implements IRenderer {
private readonly _terminal: ITerminal, private readonly _terminal: ITerminal,
private readonly _bufferService: IBufferService, private readonly _bufferService: IBufferService,
private readonly _charSizeService: ICharSizeService, private readonly _charSizeService: ICharSizeService,
private readonly _optionsService: IOptionsService private readonly _optionsService: IOptionsService,
readonly coreService: ICoreService
) { ) {
super(); super();
const allowTransparency = this._optionsService.options.allowTransparency; const allowTransparency = this._optionsService.options.allowTransparency;
@@ -46,7 +47,7 @@ export class Renderer extends Disposable implements IRenderer {
new TextRenderLayer(this._terminal.screenElement, 0, this._colors, this._characterJoinerRegistry, allowTransparency, this._id, this._bufferService, _optionsService), new TextRenderLayer(this._terminal.screenElement, 0, this._colors, this._characterJoinerRegistry, allowTransparency, this._id, this._bufferService, _optionsService),
new SelectionRenderLayer(this._terminal.screenElement, 1, this._colors, this._id, this._bufferService, _optionsService), new SelectionRenderLayer(this._terminal.screenElement, 1, this._colors, this._id, this._bufferService, _optionsService),
new LinkRenderLayer(this._terminal.screenElement, 2, this._colors, this._id, this._terminal.linkifier, this._bufferService, _optionsService), new LinkRenderLayer(this._terminal.screenElement, 2, this._colors, this._id, this._terminal.linkifier, this._bufferService, _optionsService),
new CursorRenderLayer(this._terminal.screenElement, 3, this._colors, this._terminal, this._id, this._onRequestRefreshRows, this._bufferService, _optionsService) new CursorRenderLayer(this._terminal.screenElement, 3, this._colors, this._terminal, this._id, this._onRequestRefreshRows, this._bufferService, _optionsService, coreService)
]; ];
this.dimensions = { this.dimensions = {
scaledCharWidth: null, scaledCharWidth: null,