Skip to content

Commit

Permalink
Merge pull request xtermjs#2547 from Tyriar/layering5
Browse files Browse the repository at this point in the history
Move remaining renderer parts into browser
  • Loading branch information
Tyriar authored Nov 8, 2019
2 parents dd4eb7b + 939dcca commit b68a4d2
Show file tree
Hide file tree
Showing 18 changed files with 291 additions and 210 deletions.
12 changes: 8 additions & 4 deletions addons/xterm-addon-webgl/src/WebglRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants';
import { RenderModel, COMBINED_CHAR_BIT_MASK } from './RenderModel';
import { Disposable } from 'common/Lifecycle';
import { DEFAULT_COLOR, CHAR_DATA_CHAR_INDEX, CHAR_DATA_CODE_INDEX, NULL_CELL_CODE } from 'common/buffer/Constants';
import { Terminal } from 'xterm';
import { Terminal, IEvent } from 'xterm';
import { getLuminance } from './ColorUtils';
import { IRenderLayer } from './renderLayer/Types';
import { IRenderDimensions, IRenderer } from 'browser/renderer/Types';
import { IRenderDimensions, IRenderer, IRequestRefreshRowsEvent } from 'browser/renderer/Types';
import { IColorSet } from 'browser/Types';
import { FLAGS } from './Constants';
import { getCompatAttr } from './CharDataCompat';
import { EventEmitter } from 'common/EventEmitter';

export const INDICIES_PER_CELL = 4;

Expand All @@ -41,6 +42,9 @@ export class WebglRenderer extends Disposable implements IRenderer {

private _core: ITerminal;

private _onRequestRefreshRows = new EventEmitter<IRequestRefreshRowsEvent>();
public get onRequestRefreshRows(): IEvent<IRequestRefreshRowsEvent> { return this._onRequestRefreshRows.event; }

constructor(
private _terminal: Terminal,
private _colors: IColorSet,
Expand All @@ -54,7 +58,7 @@ export class WebglRenderer extends Disposable implements IRenderer {

this._renderLayers = [
new LinkRenderLayer(this._core.screenElement, 2, this._colors, this._core),
new CursorRenderLayer(this._core.screenElement, 3, this._colors)
new CursorRenderLayer(this._core.screenElement, 3, this._colors, this._onRequestRefreshRows)
];
this.dimensions = {
scaledCharWidth: 0,
Expand Down Expand Up @@ -186,7 +190,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
this._glyphRenderer.updateSelection(this._model, columnSelectMode);

// TODO: #2102 Should this move to RenderCoordinator?
this._core.refresh(0, this._terminal.rows - 1);
this._onRequestRefreshRows.fire({ start: 0, end: this._terminal.rows - 1 });
}

public onCursorMove(): void {
Expand Down
23 changes: 14 additions & 9 deletions addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { BaseRenderLayer } from './BaseRenderLayer';
import { ICellData } from 'common/Types';
import { CellData } from 'common/buffer/CellData';
import { IColorSet } from 'browser/Types';
import { IRenderDimensions } from 'browser/renderer/Types';
import { IRenderDimensions, IRequestRefreshRowsEvent } from 'browser/renderer/Types';
import { IEventEmitter } from 'common/EventEmitter';

interface ICursorState {
x: number;
Expand All @@ -29,7 +30,12 @@ export class CursorRenderLayer extends BaseRenderLayer {
private _cursorBlinkStateManager: CursorBlinkStateManager | undefined;
private _cell: ICellData = new CellData();

constructor(container: HTMLElement, zIndex: number, colors: IColorSet) {
constructor(
container: HTMLElement,
zIndex: number,
colors: IColorSet,
private _onRequestRefreshRowsEvent: IEventEmitter<IRequestRefreshRowsEvent>
) {
super(container, 'cursor', zIndex, true, colors);
this._state = {
x: 0,
Expand Down Expand Up @@ -70,14 +76,14 @@ export class CursorRenderLayer extends BaseRenderLayer {
if (this._cursorBlinkStateManager) {
this._cursorBlinkStateManager.pause();
}
terminal.refresh(terminal.buffer.cursorY, terminal.buffer.cursorY);
this._onRequestRefreshRowsEvent.fire({ start: terminal.buffer.cursorY, end: terminal.buffer.cursorY });
}

public onFocus(terminal: Terminal): void {
if (this._cursorBlinkStateManager) {
this._cursorBlinkStateManager.resume(terminal);
} else {
terminal.refresh(terminal.buffer.cursorY, terminal.buffer.cursorY);
this._onRequestRefreshRowsEvent.fire({ start: terminal.buffer.cursorY, end: terminal.buffer.cursorY });
}
}

Expand All @@ -89,13 +95,12 @@ export class CursorRenderLayer extends BaseRenderLayer {
});
}
} else {
if (this._cursorBlinkStateManager) {
this._cursorBlinkStateManager.dispose();
}
this._cursorBlinkStateManager?.dispose();
this._cursorBlinkStateManager = undefined;
}
// Request a refresh from the terminal as management of rendering is being
// moved back to the terminal
terminal.refresh(terminal.buffer.cursorY, terminal.buffer.cursorY);
this._onRequestRefreshRowsEvent.fire({ start: terminal.buffer.cursorY, end: terminal.buffer.cursorY });
}

public onCursorMove(terminal: Terminal): void {
Expand All @@ -115,7 +120,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
private _render(terminal: Terminal, triggeredByAnimationFrame: boolean): void {
// Don't draw the cursor if it's hidden
// TODO: Need to expose API for this
if (!(terminal as any)._core.cursorState || (terminal as any)._core.cursorHidden) {
if (!(terminal as any)._core._coreService.isCursorInitialized || (terminal as any)._core._coreService.isCursorHidden) {
this._clearCursor();
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ export class InputHandler extends Disposable implements IInputHandler {
this._logService.debug('DECSET 1015 not supported (see #2507)');
break;
case 25: // show cursor
this._terminal.cursorHidden = false;
this._coreService.isCursorHidden = false;
break;
case 1048: // alt screen cursor
this.saveCursor();
Expand Down Expand Up @@ -1620,7 +1620,7 @@ export class InputHandler extends Disposable implements IInputHandler {
this._logService.debug('DECRST 1015 not supported (see #2507)');
break;
case 25: // hide cursor
this._terminal.cursorHidden = true;
this._coreService.isCursorHidden = true;
break;
case 1048: // alt screen cursor
this.restoreCursor();
Expand Down Expand Up @@ -1954,7 +1954,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* http://vt100.net/docs/vt220-rm/table4-10.html
*/
public softReset(params: IParams): void {
this._terminal.cursorHidden = false;
this._coreService.isCursorHidden = false;
this._terminal.insertMode = false;
this._terminal.originMode = false;
this._terminal.wraparoundMode = true; // defaults: xterm - true, vt100 - false
Expand Down
11 changes: 0 additions & 11 deletions src/Terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
it('should clear a buffer equal to rows', () => {
const promptLine = term.buffer.lines.get(term.buffer.ybase + term.buffer.y);
Expand Down
30 changes: 11 additions & 19 deletions src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Viewport } from 'browser/Viewport';
import { rightClickHandler, moveTextAreaUnderMouseCursor, handlePasteEvent, copyHandler, paste } from 'browser/Clipboard';
import { C0 } from 'common/data/EscapeSequences';
import { InputHandler } from './InputHandler';
import { Renderer } from './renderer/Renderer';
import { Renderer } from 'browser/renderer/Renderer';
import { Linkifier } from 'browser/Linkifier';
import { SelectionService } from 'browser/services/SelectionService';
import * as Browser from 'common/Platform';
Expand All @@ -38,7 +38,7 @@ import { SoundService } from 'browser/services/SoundService';
import { MouseZoneManager } from 'browser/MouseZoneManager';
import { AccessibilityManager } from './AccessibilityManager';
import { ITheme, IMarker, IDisposable, ISelectionPosition } from 'xterm';
import { DomRenderer } from './renderer/dom/DomRenderer';
import { DomRenderer } from 'browser/renderer/dom/DomRenderer';
import { IKeyboardEvent, KeyboardResultType, ICharset, IBufferLine, IAttributeData, CoreMouseEventType, CoreMouseButton, CoreMouseAction } from 'common/Types';
import { evaluateKeyboardEvent } from 'common/input/Keyboard';
import { EventEmitter, IEvent } from 'common/EventEmitter';
Expand All @@ -48,7 +48,7 @@ import { ColorManager } from 'browser/ColorManager';
import { RenderService } from 'browser/services/RenderService';
import { IOptionsService, IBufferService, ICoreMouseService, ICoreService, ILogService, IDirtyRowService, IInstantiationService } from 'common/services/Services';
import { OptionsService } from 'common/services/OptionsService';
import { ICharSizeService, IRenderService, IMouseService, ISelectionService, ISoundService } from 'browser/services/Services';
import { ICharSizeService, IRenderService, IMouseService, ISelectionService, ISoundService, ICoreBrowserService } from 'browser/services/Services';
import { CharSizeService } from 'browser/services/CharSizeService';
import { BufferService, MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/BufferService';
import { Disposable } from 'common/Lifecycle';
Expand All @@ -63,6 +63,7 @@ import { DirtyRowService } from 'common/services/DirtyRowService';
import { InstantiationService } from 'common/services/InstantiationService';
import { CoreMouseService } from 'common/services/CoreMouseService';
import { WriteBuffer } from 'common/input/WriteBuffer';
import { CoreBrowserService } from 'browser/services/CoreBrowserService';

// Let it work inside Node.js for automated testing purposes.
const document = (typeof window !== 'undefined') ? window.document : null;
Expand Down Expand Up @@ -90,10 +91,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
// TODO: We should remove options once components adopt optionsService
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;

private _customKeyEventHandler: CustomKeyEventHandler;

// common services
Expand Down Expand Up @@ -251,8 +248,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
private _setup(): void {
this._parent = document ? document.body : null;

this.cursorState = 0;
this.cursorHidden = false;
this._customKeyEventHandler = null;

// modes
Expand Down Expand Up @@ -319,10 +314,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
}
}

public get isFocused(): boolean {
return document.activeElement === this.textarea && document.hasFocus();
}

private _setupOptionsListeners(): void {
// TODO: These listeners should be owned by individual components
this.optionsService.onOptionChange(key => {
Expand Down Expand Up @@ -537,6 +528,9 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this.register(addDisposableDomListener(this.textarea, 'blur', () => this._onTextAreaBlur()));
this._helperContainer.appendChild(this.textarea);

const coreBrowserService = this._instantiationService.createInstance(CoreBrowserService, this.textarea);
this._instantiationService.setService(ICoreBrowserService, coreBrowserService);

this._charSizeService = this._instantiationService.createInstance(CharSizeService, this._document, this._helperContainer);
this._instantiationService.setService(ICharSizeService, this._charSizeService);

Expand Down Expand Up @@ -637,8 +631,8 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp

private _createRenderer(): IRenderer {
switch (this.options.rendererType) {
case 'canvas': return new Renderer(this._colorManager.colors, this, this._bufferService, this._charSizeService, this.optionsService);
case 'dom': return new DomRenderer(this, this._colorManager.colors, this._charSizeService, this.optionsService);
case 'canvas': return this._instantiationService.createInstance(Renderer, this._colorManager.colors, this.screenElement, 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}"`);
}
}
Expand Down Expand Up @@ -945,8 +939,8 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
* Display the cursor element
*/
public showCursor(): void {
if (!this.cursorState) {
this.cursorState = 1;
if (!this._coreService.isCursorInitialized) {
this._coreService.isCursorInitialized = true;
this.refresh(this.buffer.y, this.buffer.y);
}
}
Expand Down Expand Up @@ -1510,7 +1504,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this.options.cols = this.cols;
const customKeyEventHandler = this._customKeyEventHandler;
const inputHandler = this._inputHandler;
const cursorState = this.cursorState;
const userScrolling = this._userScrolling;

this._setup();
Expand All @@ -1522,7 +1515,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
// reattach
this._customKeyEventHandler = customKeyEventHandler;
this._inputHandler = inputHandler;
this.cursorState = cursorState;
this._userScrolling = userScrolling;

// do a full screen refresh
Expand Down
3 changes: 2 additions & 1 deletion src/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @license MIT
*/

import { IRenderer, IRenderDimensions, CharacterJoinerHandler } from 'browser/renderer/Types';
import { IRenderer, IRenderDimensions, CharacterJoinerHandler, IRequestRefreshRowsEvent } from 'browser/renderer/Types';
import { IInputHandlingTerminal, ICompositionHelper, ITerminal, IBrowser, ITerminalOptions } from './Types';
import { IBuffer, IBufferStringIterator, IBufferSet } from 'common/buffer/Types';
import { IBufferLine, ICellData, IAttributeData, ICircularList, XtermListener, ICharset, CoreMouseEventType } from 'common/Types';
Expand Down Expand Up @@ -362,6 +362,7 @@ export class MockBuffer implements IBuffer {
}

export class MockRenderer implements IRenderer {
onRequestRefreshRows: IEvent<IRequestRefreshRowsEvent>;
onCanvasResize: IEvent<{ width: number; height: number; }>;
onRender: IEvent<{ start: number; end: number; }>;
dispose(): void {
Expand Down
4 changes: 0 additions & 4 deletions src/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export interface IInputHandlingTerminal {
savedCols: number;
mouseEvents: CoreMouseEventType;
sendFocus: boolean;
cursorHidden: boolean;

buffers: IBufferSet;
buffer: IBuffer;
Expand Down Expand Up @@ -154,11 +153,8 @@ export interface IInputHandler {
export interface ITerminal extends IPublicTerminal, IElementAccessor, IBufferAccessor, ILinkifierAccessor {
screenElement: HTMLElement;
browser: IBrowser;
cursorHidden: boolean;
cursorState: number;
buffer: IBuffer;
buffers: IBufferSet;
isFocused: boolean;
viewport: IViewport;
bracketedPasteMode: boolean;
optionsService: IOptionsService;
Expand Down
Loading

0 comments on commit b68a4d2

Please sign in to comment.