From 3d2035e1a068ca54e5a4c0b87a308ba53f94cfd1 Mon Sep 17 00:00:00 2001 From: gou4shi1 Date: Thu, 15 Nov 2018 11:43:38 +0800 Subject: [PATCH 01/18] getCoordsRelativeToElement: use getBoundingClientRect and clientX/Y. --- src/utils/MouseHelper.ts | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/utils/MouseHelper.ts b/src/utils/MouseHelper.ts index ca1bb27e..c3f78e84 100644 --- a/src/utils/MouseHelper.ts +++ b/src/utils/MouseHelper.ts @@ -13,29 +13,10 @@ export class MouseHelper { this._renderer = renderer; } - public static getCoordsRelativeToElement(event: {pageX: number, pageY: number}, element: HTMLElement): [number, number] { - // Ignore browsers that don't support MouseEvent.pageX - if (event.pageX === null || event.pageX === undefined) { - return null; - } - - const originalElement = element; - let x = event.pageX; - let y = event.pageY; - - // Converts the coordinates from being relative to the document to being - // relative to the terminal. - while (element) { - x -= element.offsetLeft; - y -= element.offsetTop; - element = element.offsetParent; - } - element = originalElement; - while (element && element !== element.ownerDocument.body) { - x += element.scrollLeft; - y += element.scrollTop; - element = element.parentElement; - } + public static getCoordsRelativeToElement(event: {target: HTMLElement, clientX: number, clientY: number}, element: HTMLElement): [number, number] { + let rect = event.target.getBoundingClientRect(); + let x = event.clientX - rect.left; + let y = event.clientY - rect.top; return [x, y]; } From 3ca0598279d5526a4e50607f2b0b6720d507030a Mon Sep 17 00:00:00 2001 From: gou4shi1 Date: Thu, 15 Nov 2018 11:56:41 +0800 Subject: [PATCH 02/18] fix EventTarget type --- src/utils/MouseHelper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/MouseHelper.ts b/src/utils/MouseHelper.ts index c3f78e84..11efd647 100644 --- a/src/utils/MouseHelper.ts +++ b/src/utils/MouseHelper.ts @@ -13,7 +13,7 @@ export class MouseHelper { this._renderer = renderer; } - public static getCoordsRelativeToElement(event: {target: HTMLElement, clientX: number, clientY: number}, element: HTMLElement): [number, number] { + public static getCoordsRelativeToElement(event: {target: EventTarget, clientX: number, clientY: number}, element: HTMLElement): [number, number] { let rect = event.target.getBoundingClientRect(); let x = event.clientX - rect.left; let y = event.clientY - rect.top; From f4a522516c4f1c766ffd1609b7b13bc11ca33583 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 24 Nov 2018 07:03:52 -0800 Subject: [PATCH 03/18] Remove shared/ folder We changed plans from moving web worker compatible code to shared/ to enforcing layers using core/, common/, ui/ and public/. This change moves files back from the shared/ dir to clean up the codebase. Part of #1507 --- src/AccessibilityManager.ts | 2 +- src/SelectionManager.ts | 2 +- src/Terminal.ts | 2 +- .../utils/Browser.ts => core/Platform.ts} | 0 src/renderer/ColorManager.ts | 3 +-- src/renderer/Types.ts | 18 +++++++++++---- src/renderer/atlas/CharAtlasCache.ts | 2 +- .../atlas/CharAtlasGenerator.ts | 4 ++-- src/renderer/atlas/CharAtlasUtils.ts | 3 +-- src/renderer/atlas/DynamicCharAtlas.ts | 9 ++++---- src/renderer/atlas/NoneCharAtlas.ts | 3 +-- src/renderer/atlas/StaticCharAtlas.ts | 5 ++--- src/renderer/atlas/Types.ts | 18 +++++++++++++++ src/shared/Types.ts | 18 --------------- src/shared/atlas/Types.ts | 22 ------------------- src/utils/TestUtils.test.ts | 2 +- 16 files changed, 48 insertions(+), 65 deletions(-) rename src/{shared/utils/Browser.ts => core/Platform.ts} (100%) rename src/{shared => renderer}/atlas/CharAtlasGenerator.ts (97%) delete mode 100644 src/shared/Types.ts delete mode 100644 src/shared/atlas/Types.ts diff --git a/src/AccessibilityManager.ts b/src/AccessibilityManager.ts index 1a2de1d7..fa0121ad 100644 --- a/src/AccessibilityManager.ts +++ b/src/AccessibilityManager.ts @@ -5,7 +5,7 @@ import * as Strings from './Strings'; import { ITerminal, IBuffer } from './Types'; -import { isMac } from './shared/utils/Browser'; +import { isMac } from './core/Platform'; import { RenderDebouncer } from './ui/RenderDebouncer'; import { addDisposableDomListener } from './ui/Lifecycle'; import { Disposable } from './common/Lifecycle'; diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 49e21e2c..3dc50271 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -6,7 +6,7 @@ import { ITerminal, ISelectionManager, IBuffer, CharData, IBufferLine } from './Types'; import { XtermListener } from './common/Types'; import { MouseHelper } from './utils/MouseHelper'; -import * as Browser from './shared/utils/Browser'; +import * as Browser from './core/Platform'; import { CharMeasure } from './ui/CharMeasure'; import { EventEmitter } from './common/EventEmitter'; import { SelectionModel } from './SelectionModel'; diff --git a/src/Terminal.ts b/src/Terminal.ts index 8e89c9ca..e898f816 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -36,7 +36,7 @@ import { Renderer } from './renderer/Renderer'; import { Linkifier } from './Linkifier'; import { SelectionManager } from './SelectionManager'; import { CharMeasure } from './ui/CharMeasure'; -import * as Browser from './shared/utils/Browser'; +import * as Browser from './core/Platform'; import { addDisposableDomListener } from './ui/Lifecycle'; import * as Strings from './Strings'; import { MouseHelper } from './utils/MouseHelper'; diff --git a/src/shared/utils/Browser.ts b/src/core/Platform.ts similarity index 100% rename from src/shared/utils/Browser.ts rename to src/core/Platform.ts diff --git a/src/renderer/ColorManager.ts b/src/renderer/ColorManager.ts index d169f266..8a463670 100644 --- a/src/renderer/ColorManager.ts +++ b/src/renderer/ColorManager.ts @@ -3,8 +3,7 @@ * @license MIT */ -import { IColorManager } from './Types'; -import { IColor, IColorSet } from '../shared/Types'; +import { IColorManager, IColor, IColorSet } from './Types'; import { ITheme } from 'xterm'; const DEFAULT_FOREGROUND = fromHex('#ffffff'); diff --git a/src/renderer/Types.ts b/src/renderer/Types.ts index 824304ed..f2271f95 100644 --- a/src/renderer/Types.ts +++ b/src/renderer/Types.ts @@ -5,7 +5,6 @@ import { ITerminal, CharacterJoinerHandler } from '../Types'; import { IEventEmitter, ITheme, IDisposable } from 'xterm'; -import { IColorSet } from '../shared/Types'; /** * Flags used to render terminal text properly. @@ -48,9 +47,6 @@ export interface IColorManager { colors: IColorSet; } -// TODO: We should probably rewrite the imports for IColorSet, but there's a lot of them -export { IColorSet }; - export interface IRenderDimensions { scaledCharWidth: number; scaledCharHeight: number; @@ -134,3 +130,17 @@ export interface ICharacterJoinerRegistry { deregisterCharacterJoiner(joinerId: number): boolean; getJoinedCharacters(row: number): [number, number][]; } + +export interface IColor { + css: string; + rgba: number; // 32-bit int with rgba in each byte +} + +export interface IColorSet { + foreground: IColor; + background: IColor; + cursor: IColor; + cursorAccent: IColor; + selection: IColor; + ansi: IColor[]; +} diff --git a/src/renderer/atlas/CharAtlasCache.ts b/src/renderer/atlas/CharAtlasCache.ts index eee93d6c..3cb0e1cd 100644 --- a/src/renderer/atlas/CharAtlasCache.ts +++ b/src/renderer/atlas/CharAtlasCache.ts @@ -5,12 +5,12 @@ import { ITerminal } from '../../Types'; import { IColorSet } from '../Types'; -import { ICharAtlasConfig } from '../../shared/atlas/Types'; import { generateConfig, configEquals } from './CharAtlasUtils'; import BaseCharAtlas from './BaseCharAtlas'; import DynamicCharAtlas from './DynamicCharAtlas'; import NoneCharAtlas from './NoneCharAtlas'; import StaticCharAtlas from './StaticCharAtlas'; +import { ICharAtlasConfig } from './Types'; const charAtlasImplementations = { 'none': NoneCharAtlas, diff --git a/src/shared/atlas/CharAtlasGenerator.ts b/src/renderer/atlas/CharAtlasGenerator.ts similarity index 97% rename from src/shared/atlas/CharAtlasGenerator.ts rename to src/renderer/atlas/CharAtlasGenerator.ts index f78a6d41..03ab7b95 100644 --- a/src/shared/atlas/CharAtlasGenerator.ts +++ b/src/renderer/atlas/CharAtlasGenerator.ts @@ -4,9 +4,9 @@ */ import { FontWeight } from 'xterm'; -import { CHAR_ATLAS_CELL_SPACING, ICharAtlasConfig } from './Types'; +import { isFirefox, isSafari } from '../../core/Platform'; import { IColor } from '../Types'; -import { isFirefox, isSafari } from '../utils/Browser'; +import { ICharAtlasConfig, CHAR_ATLAS_CELL_SPACING } from './Types'; declare const Promise: any; diff --git a/src/renderer/atlas/CharAtlasUtils.ts b/src/renderer/atlas/CharAtlasUtils.ts index c504f77e..5b1add39 100644 --- a/src/renderer/atlas/CharAtlasUtils.ts +++ b/src/renderer/atlas/CharAtlasUtils.ts @@ -5,8 +5,7 @@ import { ITerminal } from '../../Types'; import { IColorSet } from '../Types'; -import { ICharAtlasConfig } from '../../shared/atlas/Types'; -import { DEFAULT_COLOR } from './Types'; +import { DEFAULT_COLOR, ICharAtlasConfig } from './Types'; export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: ITerminal, colors: IColorSet): ICharAtlasConfig { // null out some fields that don't matter diff --git a/src/renderer/atlas/DynamicCharAtlas.ts b/src/renderer/atlas/DynamicCharAtlas.ts index b6b323f0..72010768 100644 --- a/src/renderer/atlas/DynamicCharAtlas.ts +++ b/src/renderer/atlas/DynamicCharAtlas.ts @@ -3,14 +3,13 @@ * @license MIT */ -import { DIM_OPACITY, IGlyphIdentifier, INVERTED_DEFAULT_COLOR } from './Types'; -import { ICharAtlasConfig } from '../../shared/atlas/Types'; -import { IColor } from '../../shared/Types'; +import { DIM_OPACITY, IGlyphIdentifier, INVERTED_DEFAULT_COLOR, ICharAtlasConfig } from './Types'; import BaseCharAtlas from './BaseCharAtlas'; import { DEFAULT_ANSI_COLORS } from '../ColorManager'; -import { clearColor } from '../../shared/atlas/CharAtlasGenerator'; +import { clearColor } from './CharAtlasGenerator'; import LRUMap from './LRUMap'; -import { isFirefox, isSafari } from '../../shared/utils/Browser'; +import { isFirefox, isSafari } from '../../core/Platform'; +import { IColor } from '../Types'; // In practice we're probably never going to exhaust a texture this large. For debugging purposes, // however, it can be useful to set this to a really tiny value, to verify that LRU eviction works. diff --git a/src/renderer/atlas/NoneCharAtlas.ts b/src/renderer/atlas/NoneCharAtlas.ts index 1cbc9eea..308e3075 100644 --- a/src/renderer/atlas/NoneCharAtlas.ts +++ b/src/renderer/atlas/NoneCharAtlas.ts @@ -5,8 +5,7 @@ * A dummy CharAtlas implementation that always fails to draw characters. */ -import { IGlyphIdentifier } from './Types'; -import { ICharAtlasConfig } from '../../shared/atlas/Types'; +import { IGlyphIdentifier, ICharAtlasConfig } from './Types'; import BaseCharAtlas from './BaseCharAtlas'; export default class NoneCharAtlas extends BaseCharAtlas { diff --git a/src/renderer/atlas/StaticCharAtlas.ts b/src/renderer/atlas/StaticCharAtlas.ts index 8dc8be74..b54c833e 100644 --- a/src/renderer/atlas/StaticCharAtlas.ts +++ b/src/renderer/atlas/StaticCharAtlas.ts @@ -3,9 +3,8 @@ * @license MIT */ -import { DIM_OPACITY, IGlyphIdentifier, DEFAULT_COLOR } from './Types'; -import { CHAR_ATLAS_CELL_SPACING, ICharAtlasConfig } from '../../shared/atlas/Types'; -import { generateStaticCharAtlasTexture } from '../../shared/atlas/CharAtlasGenerator'; +import { DIM_OPACITY, IGlyphIdentifier, DEFAULT_COLOR, ICharAtlasConfig, CHAR_ATLAS_CELL_SPACING } from './Types'; +import { generateStaticCharAtlasTexture } from './CharAtlasGenerator'; import BaseCharAtlas from './BaseCharAtlas'; import { is256Color } from './CharAtlasUtils'; diff --git a/src/renderer/atlas/Types.ts b/src/renderer/atlas/Types.ts index 76cfd07d..38923b2f 100644 --- a/src/renderer/atlas/Types.ts +++ b/src/renderer/atlas/Types.ts @@ -3,10 +3,15 @@ * @license MIT */ +import { FontWeight } from 'xterm'; +import { IColorSet } from '../Types'; + export const DEFAULT_COLOR = 256; export const INVERTED_DEFAULT_COLOR = 257; export const DIM_OPACITY = 0.5; +export const CHAR_ATLAS_CELL_SPACING = 1; + export interface IGlyphIdentifier { chars: string; code: number; @@ -16,3 +21,16 @@ export interface IGlyphIdentifier { dim: boolean; italic: boolean; } + +export interface ICharAtlasConfig { + type: 'none' | 'static' | 'dynamic'; + devicePixelRatio: number; + fontSize: number; + fontFamily: string; + fontWeight: FontWeight; + fontWeightBold: FontWeight; + scaledCharWidth: number; + scaledCharHeight: number; + allowTransparency: boolean; + colors: IColorSet; +} diff --git a/src/shared/Types.ts b/src/shared/Types.ts deleted file mode 100644 index 0cded8a8..00000000 --- a/src/shared/Types.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) 2017 The xterm.js authors. All rights reserved. - * @license MIT - */ - -export interface IColor { - css: string; - rgba: number; // 32-bit int with rgba in each byte -} - -export interface IColorSet { - foreground: IColor; - background: IColor; - cursor: IColor; - cursorAccent: IColor; - selection: IColor; - ansi: IColor[]; -} diff --git a/src/shared/atlas/Types.ts b/src/shared/atlas/Types.ts deleted file mode 100644 index 25eaa716..00000000 --- a/src/shared/atlas/Types.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) 2017 The xterm.js authors. All rights reserved. - * @license MIT - */ - -import { FontWeight } from 'xterm'; -import { IColorSet } from '../Types'; - -export const CHAR_ATLAS_CELL_SPACING = 1; - -export interface ICharAtlasConfig { - type: 'none' | 'static' | 'dynamic'; - devicePixelRatio: number; - fontSize: number; - fontFamily: string; - fontWeight: FontWeight; - fontWeightBold: FontWeight; - scaledCharWidth: number; - scaledCharHeight: number; - allowTransparency: boolean; - colors: IColorSet; -} diff --git a/src/utils/TestUtils.test.ts b/src/utils/TestUtils.test.ts index a5ef4b9f..10033a33 100644 --- a/src/utils/TestUtils.test.ts +++ b/src/utils/TestUtils.test.ts @@ -7,7 +7,7 @@ import { IColorSet, IRenderer, IRenderDimensions, IColorManager } from '../rende import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, ILinkifier, IMouseHelper, ILinkMatcherOptions, CharacterJoinerHandler, IBufferLine, IBufferStringIterator } from '../Types'; import { ICircularList, XtermListener } from '../common/Types'; import { Buffer } from '../Buffer'; -import * as Browser from '../shared/utils/Browser'; +import * as Browser from '../core/Platform'; import { ITheme, IDisposable, IMarker } from 'xterm'; import { Terminal } from '../Terminal'; From 4d270bf72cc6afa6fde4f2e12e9762506974b4e9 Mon Sep 17 00:00:00 2001 From: Florian Wesch Date: Sun, 2 Dec 2018 15:38:50 +0100 Subject: [PATCH 04/18] Added info-beamer hosted Works pretty well. See https://community.infobeamer.com/t/174 for details. Wouldn't be able to add this feature without Xterm.js. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 551a94f4..c654f288 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,7 @@ computational environment for Jupyter, supporting interactive data science and s - [**Shellvault**](https://www.shellvault.io): The cloud-based SSH terminal you can access from anywhere. - [**Juno**](http://junolab.org/): A flexible Julia IDE, based on Atom. - [**webssh**](https://github.com/huashengdun/webssh): Web based ssh client. +- [**info-beamer hosted**](https://info-beamer.com): Uses Xterm.js to manage digital signage devices from the web dashboard. [And much more...](https://github.com/xtermjs/xterm.js/network/dependents) From 6ee9178302aa31d8c9dacf8ecf17681741539c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Tue, 4 Dec 2018 18:55:11 +0100 Subject: [PATCH 05/18] make typed array buffer default --- src/Buffer.ts | 8 ++++---- src/BufferLine.ts | 13 +++++++------ src/Terminal.ts | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Buffer.ts b/src/Buffer.ts index 0f75bdad..dd657a2a 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -7,7 +7,7 @@ import { CircularList } from './common/CircularList'; import { CharData, ITerminal, IBuffer, IBufferLine, BufferIndex, IBufferStringIterator, IBufferStringIteratorResult, IBufferLineConstructor } from './Types'; import { EventEmitter } from './common/EventEmitter'; import { IMarker } from 'xterm'; -import { BufferLine, BufferLineTypedArray } from './BufferLine'; +import { BufferLine, BufferLineJSArray } from './BufferLine'; import { DEFAULT_COLOR } from './renderer/atlas/Types'; export const DEFAULT_ATTR = (0 << 18) | (DEFAULT_COLOR << 9) | (256 << 0); @@ -57,9 +57,9 @@ export class Buffer implements IBuffer { } public setBufferLineFactory(type: string): void { - if (type === 'TypedArray') { - if (this._bufferLineConstructor !== BufferLineTypedArray) { - this._bufferLineConstructor = BufferLineTypedArray; + if (type === 'JsArray') { + if (this._bufferLineConstructor !== BufferLineJSArray) { + this._bufferLineConstructor = BufferLineJSArray; this._recreateLines(); } } else { diff --git a/src/BufferLine.ts b/src/BufferLine.ts index 7c697334..d1f1b23a 100644 --- a/src/BufferLine.ts +++ b/src/BufferLine.ts @@ -7,8 +7,9 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer'; /** * Class representing a terminal line. + * @deprecated */ -export class BufferLine implements IBufferLine { +export class BufferLineJSArray implements IBufferLine { protected _data: CharData[]; public isWrapped = false; public length: number; @@ -94,14 +95,14 @@ export class BufferLine implements IBufferLine { } } - public copyFrom(line: BufferLine): void { + public copyFrom(line: BufferLineJSArray): void { this._data = line._data.slice(0); this.length = line.length; this.isWrapped = line.isWrapped; } public clone(): IBufferLine { - const newLine = new BufferLine(0); + const newLine = new BufferLineJSArray(0); newLine.copyFrom(this); return newLine; } @@ -129,7 +130,7 @@ const enum Cell { * TODO: * - provide getData/setData to directly access the data */ -export class BufferLineTypedArray implements IBufferLine { +export class BufferLine implements IBufferLine { protected _data: Uint32Array | null = null; protected _combined: {[index: number]: string} = {}; public length: number; @@ -248,7 +249,7 @@ export class BufferLineTypedArray implements IBufferLine { } /** alter to a full copy of line */ - public copyFrom(line: BufferLineTypedArray): void { + public copyFrom(line: BufferLine): void { if (this.length !== line.length) { this._data = new Uint32Array(line._data); } else { @@ -265,7 +266,7 @@ export class BufferLineTypedArray implements IBufferLine { /** create a new clone */ public clone(): IBufferLine { - const newLine = new BufferLineTypedArray(0); + const newLine = new BufferLine(0); // creation of new typed array from another is actually pretty slow :( // still faster than copying values one by one newLine._data = new Uint32Array(this._data); diff --git a/src/Terminal.ts b/src/Terminal.ts index e374f2cd..2cfc1ca8 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -106,7 +106,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = { theme: null, rightClickSelectsWord: Browser.isMac, rendererType: 'canvas', - experimentalBufferLineImpl: 'JsArray' + experimentalBufferLineImpl: 'TypedArray' }; export class Terminal extends EventEmitter implements ITerminal, IDisposable, IInputHandlingTerminal { @@ -1179,7 +1179,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II */ public scroll(isWrapped: boolean = false): void { let newLine: IBufferLine; - const useRecycling = this.options.experimentalBufferLineImpl === 'TypedArray'; + const useRecycling = this.options.experimentalBufferLineImpl !== 'JsArray'; if (useRecycling) { newLine = this._blankLine; if (!newLine || newLine.length !== this.cols || newLine.get(0)[CHAR_DATA_ATTR_INDEX] !== this.eraseAttr()) { From 66ec57b431b0205a20a89f9ef9e0a1ff82813255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Tue, 4 Dec 2018 19:02:11 +0100 Subject: [PATCH 06/18] cleanup --- src/BufferLine.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/BufferLine.ts b/src/BufferLine.ts index d1f1b23a..c0c81a5c 100644 --- a/src/BufferLine.ts +++ b/src/BufferLine.ts @@ -7,7 +7,8 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer'; /** * Class representing a terminal line. - * @deprecated + * + * @deprecated to be removed with one of the next releases */ export class BufferLineJSArray implements IBufferLine { protected _data: CharData[]; @@ -120,15 +121,6 @@ const enum Cell { /** * Typed array based bufferline implementation. - * Note: Unlike the JS variant the access to the data - * via set/get is always a copy action. - * Sloppy ref style coding will not work anymore: - * line = new BufferLine(10); - * char = line.get(0); // char is a copy - * char[some_index] = 123; // will not update the line - * line.set(0, ch); // do this to update line data - * TODO: - * - provide getData/setData to directly access the data */ export class BufferLine implements IBufferLine { protected _data: Uint32Array | null = null; From 18902dd7894699e656789dd9904199b6ca766e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Tue, 4 Dec 2018 19:11:39 +0100 Subject: [PATCH 07/18] make linter happy --- src/BufferLine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BufferLine.ts b/src/BufferLine.ts index c0c81a5c..a95fe0f4 100644 --- a/src/BufferLine.ts +++ b/src/BufferLine.ts @@ -7,7 +7,7 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer'; /** * Class representing a terminal line. - * + * * @deprecated to be removed with one of the next releases */ export class BufferLineJSArray implements IBufferLine { From 6f4a6ef3082b424ba69e95db84aab36ccc827967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Tue, 4 Dec 2018 20:33:12 +0100 Subject: [PATCH 08/18] deprecate experimentalBufferLineImpl --- typings/xterm.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index c6b6b1e5..7528bb55 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -108,7 +108,7 @@ declare module 'xterm' { * - 'TypedArray': The new experimental implementation based on TypedArrays that is expected to * significantly boost performance and memory consumption. Use at your own risk. * - * This option will be removed in the future. + * @deprecated This option will be removed in the future. */ experimentalBufferLineImpl?: 'JsArray' | 'TypedArray'; From 7f181999854930c8fa123bcdf4dca4982d0e7c41 Mon Sep 17 00:00:00 2001 From: gou4shi1 Date: Thu, 6 Dec 2018 14:37:27 +0800 Subject: [PATCH 09/18] Fix build fail --- src/utils/MouseHelper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/MouseHelper.ts b/src/utils/MouseHelper.ts index 11efd647..7870f477 100644 --- a/src/utils/MouseHelper.ts +++ b/src/utils/MouseHelper.ts @@ -33,7 +33,7 @@ export class MouseHelper { * apply an offset to the x value such that the left half of the cell will * select that cell and the right half will select the next cell. */ - public getCoords(event: {pageX: number, pageY: number}, element: HTMLElement, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number, isSelection?: boolean): [number, number] { + public getCoords(event: {target: EventTarget, pageX: number, pageY: number}, element: HTMLElement, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number, isSelection?: boolean): [number, number] { // Coordinates cannot be measured if charMeasure has not been initialized if (!charMeasure.width || !charMeasure.height) { return null; From b5b2bcd0c911f4261abecd106a3b0f660ace621f Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 9 Dec 2018 09:08:11 -0800 Subject: [PATCH 10/18] Allow decimal line heights in demo --- demo/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/client.ts b/demo/client.ts index d5196d37..6c69899e 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -235,7 +235,7 @@ function initOptions(term: TerminalType): void { }); html += '
'; numberOptions.forEach(o => { - html += `
`; + html += `
`; }); html += '
'; Object.keys(stringOptions).forEach(o => { @@ -265,7 +265,7 @@ function initOptions(term: TerminalType): void { if (o === 'cols' || o === 'rows') { updateTerminalSize(); } else { - term.setOption(o, parseInt(input.value, 10)); + term.setOption(o, o === 'lineHeight' ? parseFloat(input.value) : parseInt(input.value, 10)); } }); }); From 693e17a5cbbea22e6bdcfeb98c71bb300dc9681d Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 9 Dec 2018 09:13:30 -0800 Subject: [PATCH 11/18] Add missing break in options code Atlas is reset as part of onResize, this should be safe --- src/Terminal.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Terminal.ts b/src/Terminal.ts index 2cfc1ca8..779d9bf5 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -464,6 +464,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II this.renderer.onResize(this.cols, this.rows); this.refresh(0, this.rows - 1); } + break; case 'rendererType': if (this.renderer) { this.unregister(this.renderer); From fe9eb7d31ebb0a5935eaf311d97dfbdeb5102477 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 9 Dec 2018 09:19:56 -0800 Subject: [PATCH 12/18] Call dispose when atlas is no longer used in cache Only runtime change is that this clears the bitmap commit timeout in DynamicCharAtlas --- src/renderer/atlas/CharAtlasCache.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/atlas/CharAtlasCache.ts b/src/renderer/atlas/CharAtlasCache.ts index 3cb0e1cd..388a181b 100644 --- a/src/renderer/atlas/CharAtlasCache.ts +++ b/src/renderer/atlas/CharAtlasCache.ts @@ -42,8 +42,6 @@ export function acquireCharAtlas( ): BaseCharAtlas { const newConfig = generateConfig(scaledCharWidth, scaledCharHeight, terminal, colors); - // TODO: Currently if a terminal changes configs it will not free the entry reference (until it's disposed) - // Check to see if the terminal already owns this config for (let i = 0; i < charAtlasCache.length; i++) { const entry = charAtlasCache[i]; @@ -54,6 +52,7 @@ export function acquireCharAtlas( } // The configs differ, release the terminal from the entry if (entry.ownedBy.length === 1) { + entry.atlas.dispose(); charAtlasCache.splice(i, 1); } else { entry.ownedBy.splice(ownedByIndex, 1); @@ -94,6 +93,7 @@ export function removeTerminalFromCache(terminal: ITerminal): void { if (index !== -1) { if (charAtlasCache[i].ownedBy.length === 1) { // Remove the cache entry if it's the only terminal + charAtlasCache[i].atlas.dispose(); charAtlasCache.splice(i, 1); } else { // Remove the reference from the cache entry From 6b9fb48898eb9d3741660d88deee1af747db5929 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 9 Dec 2018 09:59:33 -0800 Subject: [PATCH 13/18] Fix tests/lint, use element instead of event.target --- src/Types.ts | 2 +- src/utils/MouseHelper.test.ts | 20 +++++++------------- src/utils/MouseHelper.ts | 14 ++++++-------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/Types.ts b/src/Types.ts index e8578426..d0830fb1 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -246,7 +246,7 @@ export interface ILinkifierAccessor { } export interface IMouseHelper { - getCoords(event: { pageX: number, pageY: number }, element: HTMLElement, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number, isSelection?: boolean): [number, number]; + getCoords(event: { clientX: number, clientY: number }, element: HTMLElement, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number, isSelection?: boolean): [number, number]; getRawByteCoords(event: MouseEvent, element: HTMLElement, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number): { x: number, y: number }; } diff --git a/src/utils/MouseHelper.test.ts b/src/utils/MouseHelper.test.ts index ac3137f4..23fa7a67 100644 --- a/src/utils/MouseHelper.test.ts +++ b/src/utils/MouseHelper.test.ts @@ -37,34 +37,28 @@ describe('MouseHelper.getCoords', () => { describe('when charMeasure is not initialized', () => { it('should return null', () => { charMeasure = new MockCharMeasure(); - assert.equal(mouseHelper.getCoords({ pageX: 0, pageY: 0 }, document.createElement('div'), charMeasure, 1, 10, 10), null); - }); - }); - - describe('when pageX/pageY are not supported', () => { - it('should return null', () => { - assert.equal(mouseHelper.getCoords({ pageX: undefined, pageY: undefined }, document.createElement('div'), charMeasure, 1, 10, 10), null); + assert.equal(mouseHelper.getCoords({ clientX: 0, clientY: 0 }, document.createElement('div'), charMeasure, 1, 10, 10), null); }); }); it('should return the cell that was clicked', () => { let coords: [number, number]; - coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH / 2, pageY: CHAR_HEIGHT / 2 }, document.createElement('div'), charMeasure, 1, 10, 10); + coords = mouseHelper.getCoords({ clientX: CHAR_WIDTH / 2, clientY: CHAR_HEIGHT / 2 }, document.createElement('div'), charMeasure, 1, 10, 10); assert.deepEqual(coords, [1, 1]); - coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH, pageY: CHAR_HEIGHT }, document.createElement('div'), charMeasure, 1, 10, 10); + coords = mouseHelper.getCoords({ clientX: CHAR_WIDTH, clientY: CHAR_HEIGHT }, document.createElement('div'), charMeasure, 1, 10, 10); assert.deepEqual(coords, [1, 1]); - coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH, pageY: CHAR_HEIGHT + 1 }, document.createElement('div'), charMeasure, 1, 10, 10); + coords = mouseHelper.getCoords({ clientX: CHAR_WIDTH, clientY: CHAR_HEIGHT + 1 }, document.createElement('div'), charMeasure, 1, 10, 10); assert.deepEqual(coords, [1, 2]); - coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH + 1, pageY: CHAR_HEIGHT }, document.createElement('div'), charMeasure, 1, 10, 10); + coords = mouseHelper.getCoords({ clientX: CHAR_WIDTH + 1, clientY: CHAR_HEIGHT }, document.createElement('div'), charMeasure, 1, 10, 10); assert.deepEqual(coords, [2, 1]); }); it('should ensure the coordinates are returned within the terminal bounds', () => { let coords: [number, number]; - coords = mouseHelper.getCoords({ pageX: -1, pageY: -1 }, document.createElement('div'), charMeasure, 1, 10, 10); + coords = mouseHelper.getCoords({ clientX: -1, clientY: -1 }, document.createElement('div'), charMeasure, 1, 10, 10); assert.deepEqual(coords, [1, 1]); // Event are double the cols/rows - coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH * 20, pageY: CHAR_HEIGHT * 20 }, document.createElement('div'), charMeasure, 1, 10, 10); + coords = mouseHelper.getCoords({ clientX: CHAR_WIDTH * 20, clientY: CHAR_HEIGHT * 20 }, document.createElement('div'), charMeasure, 1, 10, 10); assert.deepEqual(coords, [10, 10], 'coordinates should never come back as larger than the terminal'); }); }); diff --git a/src/utils/MouseHelper.ts b/src/utils/MouseHelper.ts index 7870f477..967218b6 100644 --- a/src/utils/MouseHelper.ts +++ b/src/utils/MouseHelper.ts @@ -3,21 +3,19 @@ * @license MIT */ -import { ICharMeasure } from '../Types'; +import { ICharMeasure, IMouseHelper } from '../Types'; import { IRenderer } from '../renderer/Types'; -export class MouseHelper { +export class MouseHelper implements IMouseHelper { constructor(private _renderer: IRenderer) {} public setRenderer(renderer: IRenderer): void { this._renderer = renderer; } - public static getCoordsRelativeToElement(event: {target: EventTarget, clientX: number, clientY: number}, element: HTMLElement): [number, number] { - let rect = event.target.getBoundingClientRect(); - let x = event.clientX - rect.left; - let y = event.clientY - rect.top; - return [x, y]; + public static getCoordsRelativeToElement(event: {clientX: number, clientY: number}, element: HTMLElement): [number, number] { + const rect = element.getBoundingClientRect(); + return [event.clientX - rect.left, event.clientY - rect.top]; } /** @@ -33,7 +31,7 @@ export class MouseHelper { * apply an offset to the x value such that the left half of the cell will * select that cell and the right half will select the next cell. */ - public getCoords(event: {target: EventTarget, pageX: number, pageY: number}, element: HTMLElement, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number, isSelection?: boolean): [number, number] { + public getCoords(event: {clientX: number, clientY: number}, element: HTMLElement, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number, isSelection?: boolean): [number, number] { // Coordinates cannot be measured if charMeasure has not been initialized if (!charMeasure.width || !charMeasure.height) { return null; From 1c4a71f0df478144a1ca9f1e45420bcc39e23ab4 Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Sun, 9 Dec 2018 10:56:34 -0800 Subject: [PATCH 14/18] Optimize parsing of OSC_STRING to minimize string concatenation. --- src/EscapeSequenceParser.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/EscapeSequenceParser.ts b/src/EscapeSequenceParser.ts index b38c50f5..dbb14058 100644 --- a/src/EscapeSequenceParser.ts +++ b/src/EscapeSequenceParser.ts @@ -391,7 +391,11 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP } // normal transition & action lookup - transition = (code < 0xa0) ? (table[currentState << 8 | code]) : DEFAULT_TRANSITION; + transition = (code < 0xa0 + ? (table[currentState << 8 | code]) + : currentState === ParserState.OSC_STRING + ? (ParserAction.OSC_PUT << 4) | ParserState.OSC_STRING + : DEFAULT_TRANSITION); switch (transition >> 4) { case ParserAction.PRINT: print = (~print) ? print : i; @@ -423,10 +427,6 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP case ParserState.GROUND: print = (~print) ? print : i; break; - case ParserState.OSC_STRING: - osc += String.fromCharCode(code); - transition |= ParserState.OSC_STRING; - break; case ParserState.CSI_IGNORE: transition |= ParserState.CSI_IGNORE; break; @@ -517,7 +517,16 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP osc = ''; break; case ParserAction.OSC_PUT: - osc += data.charAt(i); + for (let j = i + 1; ; j++) { + if (j >= l + || ((code = data.charCodeAt(j)) <= 0x9f + && (table[ParserState.OSC_STRING << 8 | code] >> 4 + !== ParserAction.OSC_PUT))) { + osc += data.substring(i, j); + i = j - 1; + break; + } + } break; case ParserAction.OSC_END: if (osc && code !== 0x18 && code !== 0x1a) { From 2cb293ceb270823dae117d777e995408c563eda1 Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Sun, 9 Dec 2018 19:03:58 -0800 Subject: [PATCH 15/18] Further tweaks to optimize parsing of OSC_STRING. --- src/EscapeSequenceParser.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/EscapeSequenceParser.ts b/src/EscapeSequenceParser.ts index dbb14058..3fa3ba49 100644 --- a/src/EscapeSequenceParser.ts +++ b/src/EscapeSequenceParser.ts @@ -67,7 +67,8 @@ const PRINTABLES = r(0x20, 0x7f); const EXECUTABLES = r(0x00, 0x18); EXECUTABLES.push(0x19); EXECUTABLES.push.apply(EXECUTABLES, r(0x1c, 0x20)); -const DEFAULT_TRANSITION = ParserAction.ERROR << 4 | ParserState.GROUND; +// Pseudo-character placeholder for printable non-ascii characters. +const NON_ASCII_PRINTABLE = 0xA0; /** * VT500 compatible transition table. @@ -79,7 +80,7 @@ export const VT500_TRANSITION_TABLE = (function (): TransitionTable { const states: number[] = r(ParserState.GROUND, ParserState.DCS_PASSTHROUGH + 1); let state: any; - // table with default transition [any] --> DEFAULT_TRANSITION + // table with default transition for (state in states) { // NOTE: table lookup is capped at 0xa0 in parse to keep the table small for (let code = 0; code < 160; ++code) { @@ -184,6 +185,7 @@ export const VT500_TRANSITION_TABLE = (function (): TransitionTable { table.addMany(PRINTABLES, ParserState.DCS_PASSTHROUGH, ParserAction.DCS_PUT, ParserState.DCS_PASSTHROUGH); table.add(0x7f, ParserState.DCS_PASSTHROUGH, ParserAction.IGNORE, ParserState.DCS_PASSTHROUGH); table.addMany([0x1b, 0x9c], ParserState.DCS_PASSTHROUGH, ParserAction.DCS_UNHOOK, ParserState.GROUND); + table.add(NON_ASCII_PRINTABLE, ParserState.OSC_STRING, ParserAction.OSC_PUT, ParserState.OSC_STRING); return table; })(); @@ -391,11 +393,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP } // normal transition & action lookup - transition = (code < 0xa0 - ? (table[currentState << 8 | code]) - : currentState === ParserState.OSC_STRING - ? (ParserAction.OSC_PUT << 4) | ParserState.OSC_STRING - : DEFAULT_TRANSITION); + transition = table[currentState << 8 | (code < 0xa0 ? code : NON_ASCII_PRINTABLE)]; switch (transition >> 4) { case ParserAction.PRINT: print = (~print) ? print : i; @@ -519,9 +517,8 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP case ParserAction.OSC_PUT: for (let j = i + 1; ; j++) { if (j >= l - || ((code = data.charCodeAt(j)) <= 0x9f - && (table[ParserState.OSC_STRING << 8 | code] >> 4 - !== ParserAction.OSC_PUT))) { + || (code = data.charCodeAt(j)) < 0x20 + || (code > 0x7f && code <= 0x9f)) { osc += data.substring(i, j); i = j - 1; break; From 2d8f420db8db4ca1c53053da3cb385545b004e9d Mon Sep 17 00:00:00 2001 From: jerch Date: Mon, 10 Dec 2018 16:37:48 +0100 Subject: [PATCH 16/18] fix default transition for 0xa0 --- src/EscapeSequenceParser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EscapeSequenceParser.ts b/src/EscapeSequenceParser.ts index 3fa3ba49..f4898841 100644 --- a/src/EscapeSequenceParser.ts +++ b/src/EscapeSequenceParser.ts @@ -83,7 +83,7 @@ export const VT500_TRANSITION_TABLE = (function (): TransitionTable { // table with default transition for (state in states) { // NOTE: table lookup is capped at 0xa0 in parse to keep the table small - for (let code = 0; code < 160; ++code) { + for (let code = 0; code <= NON_ASCII_PRINTABLE; ++code) { table.add(code, state, ParserAction.ERROR, ParserState.GROUND); } } From 1c62980d202dc6ed14d4ad60337ea05e6a6a3638 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 10 Dec 2018 07:51:28 -0800 Subject: [PATCH 17/18] v3.9.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c84a0164..4aef95af 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "xterm", "description": "Full xterm terminal, in your browser", - "version": "3.8.0", + "version": "3.9.0", "main": "lib/public/Terminal.js", "types": "typings/xterm.d.ts", "repository": "https://github.com/xtermjs/xterm.js", From b9a22eb468d3645961584ea74cafd491a5776b4c Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 10 Dec 2018 16:46:57 -0800 Subject: [PATCH 18/18] Remove utils/ folder Part of #1507 --- src/Buffer.test.ts | 2 +- src/BufferSet.test.ts | 2 +- src/CharWidth.test.ts | 2 +- src/InputHandler.test.ts | 2 +- src/Linkifier.test.ts | 2 +- src/SelectionManager.test.ts | 2 +- src/SelectionManager.ts | 2 +- src/SelectionModel.test.ts | 2 +- src/Terminal.test.ts | 2 +- src/Terminal.ts | 4 ++-- src/{utils => common}/Clone.test.ts | 4 ++-- src/{utils => common}/Clone.ts | 4 ++-- src/renderer/CharacterJoinerRegistry.test.ts | 2 +- src/{utils => ui}/MouseHelper.test.ts | 0 src/{utils => ui}/MouseHelper.ts | 0 src/{utils => ui}/TestUtils.test.ts | 0 16 files changed, 16 insertions(+), 16 deletions(-) rename src/{utils => common}/Clone.test.ts (95%) rename src/{utils => common}/Clone.ts (90%) rename src/{utils => ui}/MouseHelper.test.ts (100%) rename src/{utils => ui}/MouseHelper.ts (100%) rename src/{utils => ui}/TestUtils.test.ts (100%) diff --git a/src/Buffer.test.ts b/src/Buffer.test.ts index db8a460d..2561ce36 100644 --- a/src/Buffer.test.ts +++ b/src/Buffer.test.ts @@ -7,7 +7,7 @@ import { assert, expect } from 'chai'; import { ITerminal } from './Types'; import { Buffer, DEFAULT_ATTR, CHAR_DATA_CHAR_INDEX } from './Buffer'; import { CircularList } from './common/CircularList'; -import { MockTerminal, TestTerminal } from './utils/TestUtils.test'; +import { MockTerminal, TestTerminal } from './ui/TestUtils.test'; import { BufferLine } from './BufferLine'; const INIT_COLS = 80; diff --git a/src/BufferSet.test.ts b/src/BufferSet.test.ts index 38f2ddab..26f9cd42 100644 --- a/src/BufferSet.test.ts +++ b/src/BufferSet.test.ts @@ -7,7 +7,7 @@ import { assert } from 'chai'; import { ITerminal } from './Types'; import { BufferSet } from './BufferSet'; import { Buffer } from './Buffer'; -import { MockTerminal } from './utils/TestUtils.test'; +import { MockTerminal } from './ui/TestUtils.test'; describe('BufferSet', () => { let terminal: ITerminal; diff --git a/src/CharWidth.test.ts b/src/CharWidth.test.ts index d4ddd24c..0747fdf1 100644 --- a/src/CharWidth.test.ts +++ b/src/CharWidth.test.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { TestTerminal } from './utils/TestUtils.test'; +import { TestTerminal } from './ui/TestUtils.test'; import { assert } from 'chai'; import { getStringCellWidth, wcwidth } from './CharWidth'; import { IBuffer } from './Types'; diff --git a/src/InputHandler.test.ts b/src/InputHandler.test.ts index b2fea06a..acc18ea5 100644 --- a/src/InputHandler.test.ts +++ b/src/InputHandler.test.ts @@ -5,7 +5,7 @@ import { assert, expect } from 'chai'; import { InputHandler } from './InputHandler'; -import { MockInputHandlingTerminal } from './utils/TestUtils.test'; +import { MockInputHandlingTerminal } from './ui/TestUtils.test'; import { NULL_CELL_CHAR, NULL_CELL_CODE, NULL_CELL_WIDTH, CHAR_DATA_CHAR_INDEX, CHAR_DATA_ATTR_INDEX, DEFAULT_ATTR } from './Buffer'; import { Terminal } from './Terminal'; import { IBufferLine } from './Types'; diff --git a/src/Linkifier.test.ts b/src/Linkifier.test.ts index 22e797aa..0ba1294a 100644 --- a/src/Linkifier.test.ts +++ b/src/Linkifier.test.ts @@ -7,7 +7,7 @@ import { assert } from 'chai'; import { IMouseZoneManager, IMouseZone } from './ui/Types'; import { ILinkMatcher, ITerminal, IBufferLine } from './Types'; import { Linkifier } from './Linkifier'; -import { MockBuffer, MockTerminal, TestTerminal } from './utils/TestUtils.test'; +import { MockBuffer, MockTerminal, TestTerminal } from './ui/TestUtils.test'; import { CircularList } from './common/CircularList'; import { BufferLine } from './BufferLine'; diff --git a/src/SelectionManager.test.ts b/src/SelectionManager.test.ts index 8735e894..2f74ccda 100644 --- a/src/SelectionManager.test.ts +++ b/src/SelectionManager.test.ts @@ -9,7 +9,7 @@ import { SelectionManager, SelectionMode } from './SelectionManager'; import { SelectionModel } from './SelectionModel'; import { BufferSet } from './BufferSet'; import { ITerminal, IBuffer, IBufferLine } from './Types'; -import { MockTerminal } from './utils/TestUtils.test'; +import { MockTerminal } from './ui/TestUtils.test'; import { BufferLine } from './BufferLine'; class TestMockTerminal extends MockTerminal { diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 3dc50271..4bac0400 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -5,7 +5,7 @@ import { ITerminal, ISelectionManager, IBuffer, CharData, IBufferLine } from './Types'; import { XtermListener } from './common/Types'; -import { MouseHelper } from './utils/MouseHelper'; +import { MouseHelper } from './ui/MouseHelper'; import * as Browser from './core/Platform'; import { CharMeasure } from './ui/CharMeasure'; import { EventEmitter } from './common/EventEmitter'; diff --git a/src/SelectionModel.test.ts b/src/SelectionModel.test.ts index 59b2ce75..8d4b30bb 100644 --- a/src/SelectionModel.test.ts +++ b/src/SelectionModel.test.ts @@ -7,7 +7,7 @@ import { assert } from 'chai'; import { ITerminal } from './Types'; import { SelectionModel } from './SelectionModel'; import { BufferSet } from './BufferSet'; -import { MockTerminal } from './utils/TestUtils.test'; +import { MockTerminal } from './ui/TestUtils.test'; class TestSelectionModel extends SelectionModel { constructor( diff --git a/src/Terminal.test.ts b/src/Terminal.test.ts index fd59144c..733d2b39 100644 --- a/src/Terminal.test.ts +++ b/src/Terminal.test.ts @@ -5,7 +5,7 @@ import { assert, expect } from 'chai'; import { Terminal } from './Terminal'; -import { MockViewport, MockCompositionHelper, MockRenderer } from './utils/TestUtils.test'; +import { MockViewport, MockCompositionHelper, MockRenderer } from './ui/TestUtils.test'; import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, DEFAULT_ATTR } from './Buffer'; const INIT_COLS = 80; diff --git a/src/Terminal.ts b/src/Terminal.ts index 779d9bf5..bc8fb103 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -39,8 +39,7 @@ import { CharMeasure } from './ui/CharMeasure'; import * as Browser from './core/Platform'; import { addDisposableDomListener } from './ui/Lifecycle'; import * as Strings from './Strings'; -import { MouseHelper } from './utils/MouseHelper'; -import { clone } from './utils/Clone'; +import { MouseHelper } from './ui/MouseHelper'; import { DEFAULT_BELL_SOUND, SoundManager } from './SoundManager'; import { DEFAULT_ANSI_COLORS } from './renderer/ColorManager'; import { MouseZoneManager } from './ui/MouseZoneManager'; @@ -52,6 +51,7 @@ import { DomRenderer } from './renderer/dom/DomRenderer'; import { IKeyboardEvent } from './common/Types'; import { evaluateKeyboardEvent } from './core/input/Keyboard'; import { KeyboardResultType, ICharset } from './core/Types'; +import { clone } from './common/Clone'; // Let it work inside Node.js for automated testing purposes. const document = (typeof window !== 'undefined') ? window.document : null; diff --git a/src/utils/Clone.test.ts b/src/common/Clone.test.ts similarity index 95% rename from src/utils/Clone.test.ts rename to src/common/Clone.test.ts index b24452c8..4b815ff3 100644 --- a/src/utils/Clone.test.ts +++ b/src/common/Clone.test.ts @@ -101,7 +101,7 @@ describe('clone', () => { test.a.b.c.d.e.f = 'bar'; // The values at a greater depth then 5 should not be cloned - assert.equal(cloned.a.b.c.d.e.f, 'bar'); + assert.equal((cloned as any).a.b.c.d.e.f, 'bar'); }); it('should allow an optional maximum depth to be set', () => { @@ -118,7 +118,7 @@ describe('clone', () => { test.a.b.c = 'bar'; // The values at a greater depth then 2 should not be cloned - assert.equal(cloned.a.b.c, 'bar'); + assert.equal((cloned as any).a.b.c, 'bar'); }); it('should not throw when cloning a recursive reference', () => { diff --git a/src/utils/Clone.ts b/src/common/Clone.ts similarity index 90% rename from src/utils/Clone.ts rename to src/common/Clone.ts index b09c0258..78bacbb5 100644 --- a/src/utils/Clone.ts +++ b/src/common/Clone.ts @@ -6,7 +6,7 @@ /* * A simple utility for cloning values */ -export const clone = (val: T, depth: number = 5): T => { +export function clone(val: T, depth: number = 5): T | null { if (typeof val !== 'object') { return val; } @@ -25,4 +25,4 @@ export const clone = (val: T, depth: number = 5): T => { } return clonedObject as T; -}; +} diff --git a/src/renderer/CharacterJoinerRegistry.test.ts b/src/renderer/CharacterJoinerRegistry.test.ts index 383d2a7f..0c29566a 100644 --- a/src/renderer/CharacterJoinerRegistry.test.ts +++ b/src/renderer/CharacterJoinerRegistry.test.ts @@ -1,6 +1,6 @@ import { assert } from 'chai'; -import { MockTerminal, MockBuffer } from '../utils/TestUtils.test'; +import { MockTerminal, MockBuffer } from '../ui/TestUtils.test'; import { CircularList } from '../common/CircularList'; import { ICharacterJoinerRegistry } from './Types'; diff --git a/src/utils/MouseHelper.test.ts b/src/ui/MouseHelper.test.ts similarity index 100% rename from src/utils/MouseHelper.test.ts rename to src/ui/MouseHelper.test.ts diff --git a/src/utils/MouseHelper.ts b/src/ui/MouseHelper.ts similarity index 100% rename from src/utils/MouseHelper.ts rename to src/ui/MouseHelper.ts diff --git a/src/utils/TestUtils.test.ts b/src/ui/TestUtils.test.ts similarity index 100% rename from src/utils/TestUtils.test.ts rename to src/ui/TestUtils.test.ts