mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Merge branch 'master' into underline-dotted
This commit is contained in:
@@ -127,6 +127,11 @@
|
||||
{ "selector": "typeLike", "format": ["PascalCase"] },
|
||||
{ "selector": "interface", "format": ["PascalCase"], "prefix": ["I"] }
|
||||
],
|
||||
"@typescript-eslint/no-confusing-void-expression": [
|
||||
"warn",
|
||||
{ "ignoreArrowShorthand": true }
|
||||
],
|
||||
"@typescript-eslint/no-useless-constructor": "warn",
|
||||
"@typescript-eslint/prefer-namespace-keyword": "warn",
|
||||
"@typescript-eslint/type-annotation-spacing": "warn",
|
||||
"@typescript-eslint/quotes": [
|
||||
|
||||
@@ -32,7 +32,6 @@ jobs:
|
||||
./addons/xterm-addon-canvas/out-test/* \
|
||||
./addons/xterm-addon-fit/out/* \
|
||||
./addons/xterm-addon-fit/out-test/* \
|
||||
./addons/xterm-addon-image/inwasm-builds/out/* \
|
||||
./addons/xterm-addon-image/out/* \
|
||||
./addons/xterm-addon-image/out-test/* \
|
||||
./addons/xterm-addon-ligatures/out/* \
|
||||
@@ -73,6 +72,39 @@ jobs:
|
||||
- name: Lint API
|
||||
run: yarn lint-api
|
||||
|
||||
test-unit-coverage:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js 18.x
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.x
|
||||
cache: 'yarn'
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
yarn --frozen-lockfile
|
||||
yarn install-addons
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: build-artifacts
|
||||
- name: Unzip artifacts (Linux, macOS)
|
||||
if: runner.os != 'Windows'
|
||||
run: unzip -o compressed-build.zip
|
||||
- name: Unzip artifacts (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
run: 7z x compressed-build.zip -aoa -o${{ github.workspace }}
|
||||
- name: Print directory structure
|
||||
run: ls -R
|
||||
- name: Unit test coverage
|
||||
run: |
|
||||
yarn test-unit-coverage --forbid-only
|
||||
EXIT_CODE=$?
|
||||
./node_modules/.bin/nyc report --reporter=cobertura
|
||||
exit $EXIT_CODE
|
||||
|
||||
test-unit-parallel:
|
||||
timeout-minutes: 20
|
||||
strategy:
|
||||
|
||||
@@ -3,24 +3,24 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { ReadonlyColorSet } from 'browser/Types';
|
||||
import { CellColorResolver } from 'browser/renderer/shared/CellColorResolver';
|
||||
import { acquireTextureAtlas } from 'browser/renderer/shared/CharAtlasCache';
|
||||
import { TEXT_BASELINE } from 'browser/renderer/shared/Constants';
|
||||
import { tryDrawCustomChar } from 'browser/renderer/shared/CustomGlyphs';
|
||||
import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
|
||||
import { IRasterizedGlyph, IRenderDimensions, ISelectionRenderModel, ITextureAtlas } from 'browser/renderer/shared/Types';
|
||||
import { createSelectionRenderModel } from 'browser/renderer/shared/SelectionRenderModel';
|
||||
import { IRasterizedGlyph, IRenderDimensions, ISelectionRenderModel, ITextureAtlas } from 'browser/renderer/shared/Types';
|
||||
import { ICoreBrowserService, IThemeService } from 'browser/services/Services';
|
||||
import { ReadonlyColorSet } from 'browser/Types';
|
||||
import { EventEmitter, forwardEvent } from 'common/EventEmitter';
|
||||
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
|
||||
import { isSafari } from 'common/Platform';
|
||||
import { ICellData } from 'common/Types';
|
||||
import { CellData } from 'common/buffer/CellData';
|
||||
import { WHITESPACE_CELL_CODE } from 'common/buffer/Constants';
|
||||
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
|
||||
import { ICellData, IDisposable } from 'common/Types';
|
||||
import { Terminal } from 'xterm';
|
||||
import { IRenderLayer } from './Types';
|
||||
import { CellColorResolver } from 'browser/renderer/shared/CellColorResolver';
|
||||
import { Disposable, toDisposable } from 'common/Lifecycle';
|
||||
import { isSafari } from 'common/Platform';
|
||||
import { EventEmitter, forwardEvent } from 'common/EventEmitter';
|
||||
|
||||
export abstract class BaseRenderLayer extends Disposable implements IRenderLayer {
|
||||
private _canvas: HTMLCanvasElement;
|
||||
@@ -37,7 +37,7 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
|
||||
private _bitmapGenerator: (BitmapGenerator | undefined)[] = [];
|
||||
|
||||
protected _charAtlas!: ITextureAtlas;
|
||||
private _charAtlasDisposable?: IDisposable;
|
||||
protected _charAtlasDisposable = this.register(new MutableDisposable());
|
||||
|
||||
public get canvas(): HTMLCanvasElement { return this._canvas; }
|
||||
public get cacheCanvas(): HTMLCanvasElement { return this._charAtlas?.pages[0].canvas!; }
|
||||
@@ -74,7 +74,6 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
|
||||
|
||||
this.register(toDisposable(() => {
|
||||
this._canvas.remove();
|
||||
this._charAtlas?.dispose();
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -122,9 +121,8 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
|
||||
if (this._deviceCharWidth <= 0 && this._deviceCharHeight <= 0) {
|
||||
return;
|
||||
}
|
||||
this._charAtlasDisposable?.dispose();
|
||||
this._charAtlas = acquireTextureAtlas(this._terminal, this._optionsService.rawOptions, colorSet, this._deviceCellWidth, this._deviceCellHeight, this._deviceCharWidth, this._deviceCharHeight, this._coreBrowserService.dpr);
|
||||
this._charAtlasDisposable = forwardEvent(this._charAtlas.onAddTextureAtlasCanvas, this._onAddTextureAtlasCanvas);
|
||||
this._charAtlasDisposable.value = forwardEvent(this._charAtlas.onAddTextureAtlasCanvas, this._onAddTextureAtlasCanvas);
|
||||
this._charAtlas.warmUp();
|
||||
for (let i = 0; i < this._charAtlas.pages.length; i++) {
|
||||
this._bitmapGenerator[i] = new BitmapGenerator(this._charAtlas.pages[i].canvas);
|
||||
|
||||
@@ -7,7 +7,7 @@ import { CursorBlinkStateManager } from 'browser/renderer/shared/CursorBlinkStat
|
||||
import { IRenderDimensions, IRequestRedrawEvent } from 'browser/renderer/shared/Types';
|
||||
import { ICoreBrowserService, IThemeService } from 'browser/services/Services';
|
||||
import { IEventEmitter } from 'common/EventEmitter';
|
||||
import { toDisposable } from 'common/Lifecycle';
|
||||
import { MutableDisposable } from 'common/Lifecycle';
|
||||
import { isFirefox } from 'common/Platform';
|
||||
import { ICellData } from 'common/Types';
|
||||
import { CellData } from 'common/buffer/CellData';
|
||||
@@ -26,7 +26,7 @@ interface ICursorState {
|
||||
export class CursorRenderLayer extends BaseRenderLayer {
|
||||
private _state: ICursorState;
|
||||
private _cursorRenderers: {[key: string]: (x: number, y: number, cell: ICellData) => void};
|
||||
private _cursorBlinkStateManager: CursorBlinkStateManager | undefined;
|
||||
private _cursorBlinkStateManager: MutableDisposable<CursorBlinkStateManager> = this.register(new MutableDisposable());
|
||||
private _cell: ICellData = new CellData();
|
||||
|
||||
constructor(
|
||||
@@ -57,10 +57,6 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
||||
};
|
||||
this.register(optionsService.onOptionChange(() => this._handleOptionsChanged()));
|
||||
this._handleOptionsChanged();
|
||||
this.register(toDisposable(() => {
|
||||
this._cursorBlinkStateManager?.dispose();
|
||||
this._cursorBlinkStateManager = undefined;
|
||||
}));
|
||||
}
|
||||
|
||||
public resize(dim: IRenderDimensions): void {
|
||||
@@ -77,28 +73,27 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
||||
|
||||
public reset(): void {
|
||||
this._clearCursor();
|
||||
this._cursorBlinkStateManager?.restartBlinkAnimation();
|
||||
this._cursorBlinkStateManager.value?.restartBlinkAnimation();
|
||||
this._handleOptionsChanged();
|
||||
}
|
||||
|
||||
public handleBlur(): void {
|
||||
this._cursorBlinkStateManager?.pause();
|
||||
this._cursorBlinkStateManager.value?.pause();
|
||||
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
|
||||
}
|
||||
|
||||
public handleFocus(): void {
|
||||
this._cursorBlinkStateManager?.resume();
|
||||
this._cursorBlinkStateManager.value?.resume();
|
||||
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
|
||||
}
|
||||
|
||||
private _handleOptionsChanged(): void {
|
||||
if (this._optionsService.rawOptions.cursorBlink) {
|
||||
if (!this._cursorBlinkStateManager) {
|
||||
this._cursorBlinkStateManager = new CursorBlinkStateManager(() => this._render(true), this._coreBrowserService);
|
||||
if (!this._cursorBlinkStateManager.value) {
|
||||
this._cursorBlinkStateManager.value = new CursorBlinkStateManager(() => this._render(true), this._coreBrowserService);
|
||||
}
|
||||
} else {
|
||||
this._cursorBlinkStateManager?.dispose();
|
||||
this._cursorBlinkStateManager = undefined;
|
||||
this._cursorBlinkStateManager.clear();
|
||||
}
|
||||
// Request a refresh from the terminal as management of rendering is being
|
||||
// moved back to the terminal
|
||||
@@ -106,14 +101,14 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
||||
}
|
||||
|
||||
public handleCursorMove(): void {
|
||||
this._cursorBlinkStateManager?.restartBlinkAnimation();
|
||||
this._cursorBlinkStateManager.value?.restartBlinkAnimation();
|
||||
}
|
||||
|
||||
public handleGridChanged(startRow: number, endRow: number): void {
|
||||
if (!this._cursorBlinkStateManager || this._cursorBlinkStateManager.isPaused) {
|
||||
if (!this._cursorBlinkStateManager.value || this._cursorBlinkStateManager.value.isPaused) {
|
||||
this._render(false);
|
||||
} else {
|
||||
this._cursorBlinkStateManager.restartBlinkAnimation();
|
||||
this._cursorBlinkStateManager.value.restartBlinkAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +154,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
||||
}
|
||||
|
||||
// Don't draw the cursor if it's blinking
|
||||
if (this._cursorBlinkStateManager && !this._cursorBlinkStateManager.isCursorVisible) {
|
||||
if (this._cursorBlinkStateManager.value && !this._cursorBlinkStateManager.value.isCursorVisible) {
|
||||
this._clearCursor();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@ const MINIMUM_ROWS = 1;
|
||||
export class FitAddon implements ITerminalAddon {
|
||||
private _terminal: Terminal | undefined;
|
||||
|
||||
constructor() {}
|
||||
|
||||
public activate(terminal: Terminal): void {
|
||||
this._terminal = terminal;
|
||||
}
|
||||
|
||||
@@ -41,9 +41,7 @@ describe('FitAddon', () => {
|
||||
});
|
||||
|
||||
describe('proposeDimensions', () => {
|
||||
afterEach(async () => {
|
||||
return await unloadFit();
|
||||
});
|
||||
afterEach(() => unloadFit());
|
||||
|
||||
it('default', async function(): Promise<any> {
|
||||
await loadFit();
|
||||
@@ -82,9 +80,7 @@ describe('FitAddon', () => {
|
||||
});
|
||||
|
||||
describe('fit', () => {
|
||||
afterEach(async () => {
|
||||
return await unloadFit();
|
||||
});
|
||||
afterEach(() => unloadFit());
|
||||
|
||||
it('default', async function(): Promise<any> {
|
||||
await loadFit();
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -1,210 +0,0 @@
|
||||
(module
|
||||
(type (;0;) (func (result i32)))
|
||||
(import "env" "memory" (memory (;0;) 1))
|
||||
(func (;0;) (type 0) (result i32)
|
||||
(local i32 i32 i32 i32 i32)
|
||||
i32.const 5128
|
||||
i32.load
|
||||
i32.const 5152
|
||||
i32.add
|
||||
local.set 1
|
||||
i32.const 5124
|
||||
i32.load
|
||||
local.tee 0
|
||||
i32.const 5120
|
||||
i32.load
|
||||
i32.const 1
|
||||
i32.sub
|
||||
i32.const -4
|
||||
i32.and
|
||||
local.tee 2
|
||||
i32.lt_s
|
||||
if ;; label = @1
|
||||
local.get 2
|
||||
i32.const 5152
|
||||
i32.add
|
||||
local.set 3
|
||||
local.get 0
|
||||
i32.const 5152
|
||||
i32.add
|
||||
local.set 0
|
||||
loop ;; label = @2
|
||||
local.get 0
|
||||
i32.load8_u offset=3
|
||||
i32.const 2
|
||||
i32.shl
|
||||
i32.load offset=4096
|
||||
local.get 0
|
||||
i32.load8_u offset=2
|
||||
i32.const 2
|
||||
i32.shl
|
||||
i32.load offset=3072
|
||||
local.get 0
|
||||
i32.load8_u offset=1
|
||||
i32.const 2
|
||||
i32.shl
|
||||
i32.load offset=2048
|
||||
local.get 0
|
||||
i32.load8_u
|
||||
i32.const 2
|
||||
i32.shl
|
||||
i32.load offset=1024
|
||||
i32.or
|
||||
i32.or
|
||||
i32.or
|
||||
local.tee 4
|
||||
i32.const 16777215
|
||||
i32.gt_u
|
||||
if ;; label = @3
|
||||
i32.const 1
|
||||
return
|
||||
end
|
||||
local.get 1
|
||||
local.get 4
|
||||
i32.store
|
||||
local.get 1
|
||||
i32.const 3
|
||||
i32.add
|
||||
local.set 1
|
||||
local.get 0
|
||||
i32.const 4
|
||||
i32.add
|
||||
local.tee 0
|
||||
local.get 3
|
||||
i32.lt_u
|
||||
br_if 0 (;@2;)
|
||||
end
|
||||
end
|
||||
i32.const 5124
|
||||
local.get 2
|
||||
i32.store
|
||||
i32.const 5128
|
||||
local.get 1
|
||||
i32.const 5152
|
||||
i32.sub
|
||||
i32.store
|
||||
i32.const 0)
|
||||
(func (;1;) (type 0) (result i32)
|
||||
(local i32 i32 i32 i32 i32 i32)
|
||||
block ;; label = @1
|
||||
i32.const 5120
|
||||
i32.load
|
||||
local.tee 1
|
||||
i32.const 5124
|
||||
i32.load
|
||||
local.tee 0
|
||||
i32.sub
|
||||
i32.const 5
|
||||
i32.ge_s
|
||||
if ;; label = @2
|
||||
i32.const 1
|
||||
local.set 3
|
||||
call 0
|
||||
br_if 1 (;@1;)
|
||||
i32.const 5120
|
||||
i32.load
|
||||
local.set 1
|
||||
i32.const 5124
|
||||
i32.load
|
||||
local.set 0
|
||||
end
|
||||
i32.const 1
|
||||
local.set 3
|
||||
local.get 1
|
||||
local.get 0
|
||||
i32.sub
|
||||
local.tee 4
|
||||
i32.const 2
|
||||
i32.lt_s
|
||||
br_if 0 (;@1;)
|
||||
local.get 0
|
||||
i32.const 5153
|
||||
i32.add
|
||||
i32.load8_u
|
||||
i32.const 2
|
||||
i32.shl
|
||||
i32.load offset=2048
|
||||
local.get 0
|
||||
i32.const 5152
|
||||
i32.add
|
||||
i32.load8_u
|
||||
i32.const 2
|
||||
i32.shl
|
||||
i32.load offset=1024
|
||||
i32.or
|
||||
local.set 1
|
||||
block ;; label = @2
|
||||
local.get 4
|
||||
i32.const 2
|
||||
i32.eq
|
||||
if ;; label = @3
|
||||
i32.const 1
|
||||
local.set 2
|
||||
br 1 (;@2;)
|
||||
end
|
||||
i32.const 1
|
||||
local.set 2
|
||||
local.get 0
|
||||
i32.load8_u offset=5154
|
||||
local.tee 5
|
||||
i32.const 61
|
||||
i32.ne
|
||||
if ;; label = @3
|
||||
i32.const 2
|
||||
local.set 2
|
||||
local.get 5
|
||||
i32.const 2
|
||||
i32.shl
|
||||
i32.load offset=3072
|
||||
local.get 1
|
||||
i32.or
|
||||
local.set 1
|
||||
end
|
||||
local.get 4
|
||||
i32.const 4
|
||||
i32.ne
|
||||
br_if 0 (;@2;)
|
||||
local.get 0
|
||||
i32.load8_u offset=5155
|
||||
local.tee 0
|
||||
i32.const 61
|
||||
i32.eq
|
||||
br_if 0 (;@2;)
|
||||
local.get 2
|
||||
i32.const 1
|
||||
i32.add
|
||||
local.set 2
|
||||
local.get 0
|
||||
i32.const 2
|
||||
i32.shl
|
||||
i32.load offset=4096
|
||||
local.get 1
|
||||
i32.or
|
||||
local.set 1
|
||||
end
|
||||
local.get 1
|
||||
i32.const 16777215
|
||||
i32.gt_u
|
||||
br_if 0 (;@1;)
|
||||
i32.const 5128
|
||||
i32.load
|
||||
i32.const 5152
|
||||
i32.add
|
||||
local.get 1
|
||||
i32.store
|
||||
i32.const 5128
|
||||
i32.const 5128
|
||||
i32.load
|
||||
local.get 2
|
||||
i32.add
|
||||
local.tee 0
|
||||
i32.store
|
||||
local.get 0
|
||||
i32.const 5136
|
||||
i32.load
|
||||
i32.ne
|
||||
local.set 3
|
||||
end
|
||||
local.get 3)
|
||||
(export "dec" (func 0))
|
||||
(export "end" (func 1)))
|
||||
@@ -17,8 +17,7 @@
|
||||
"xterm.js"
|
||||
],
|
||||
"scripts": {
|
||||
"inwasm": "inwasm out/*.wasm.js",
|
||||
"prepackage": "../../node_modules/.bin/tsc -p . && inwasm -f out/*.wasm.js",
|
||||
"prepackage": "../../node_modules/.bin/tsc -p .",
|
||||
"package": "../../node_modules/.bin/webpack",
|
||||
"prepublishOnly": "npm run package"
|
||||
},
|
||||
@@ -26,7 +25,7 @@
|
||||
"xterm": "^5.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"inwasm": "^0.0.13",
|
||||
"sixel": "^0.16.0"
|
||||
"sixel": "^0.16.0",
|
||||
"xterm-wasm-parts": "^0.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { IImageAddonOptions, IOscHandler, IResetHandler, ITerminalExt } from './Types';
|
||||
import { ImageRenderer } from './ImageRenderer';
|
||||
import { ImageStorage, CELL_SIZE_DEFAULT } from './ImageStorage';
|
||||
import { Base64Decoder } from './base64.wasm';
|
||||
import Base64Decoder from 'xterm-wasm-parts/lib/base64/Base64Decoder.wasm';
|
||||
import { HeaderParser, IHeaderFields, HeaderState } from './IIPHeaderParser';
|
||||
import { imageType, UNSUPPORTED_TYPE } from './IIPMetrics';
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { toRGBA8888 } from 'sixel/lib/Colors';
|
||||
import { IDisposable } from 'xterm';
|
||||
import { ICellSize, ITerminalExt, IImageSpec, IRenderDimensions, IRenderService } from './Types';
|
||||
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
|
||||
|
||||
|
||||
const PLACEHOLDER_LENGTH = 4096;
|
||||
@@ -17,12 +18,12 @@ const PLACEHOLDER_HEIGHT = 24;
|
||||
* - add canvas layer to DOM (browser only for now)
|
||||
* - draw image tiles onRender
|
||||
*/
|
||||
export class ImageRenderer implements IDisposable {
|
||||
export class ImageRenderer extends Disposable implements IDisposable {
|
||||
public canvas: HTMLCanvasElement | undefined;
|
||||
private _ctx: CanvasRenderingContext2D | null | undefined;
|
||||
private _placeholder: HTMLCanvasElement | undefined;
|
||||
private _placeholderBitmap: ImageBitmap | undefined;
|
||||
private _optionsRefresh: IDisposable | undefined;
|
||||
private _optionsRefresh = this.register(new MutableDisposable());
|
||||
private _oldOpen: ((parent: HTMLElement) => void) | undefined;
|
||||
private _renderService: IRenderService | undefined;
|
||||
private _oldSetRenderer: ((renderer: any) => void) | undefined;
|
||||
@@ -68,6 +69,7 @@ export class ImageRenderer implements IDisposable {
|
||||
|
||||
|
||||
constructor(private _terminal: ITerminalExt) {
|
||||
super();
|
||||
this._oldOpen = this._terminal._core.open;
|
||||
this._terminal._core.open = (parent: HTMLElement): void => {
|
||||
this._oldOpen?.call(this._terminal._core, parent);
|
||||
@@ -77,32 +79,29 @@ export class ImageRenderer implements IDisposable {
|
||||
this._open();
|
||||
}
|
||||
// hack to spot fontSize changes
|
||||
this._optionsRefresh = this._terminal._core.optionsService.onOptionChange(option => {
|
||||
this._optionsRefresh.value = this._terminal._core.optionsService.onOptionChange(option => {
|
||||
if (option === 'fontSize') {
|
||||
this.rescaleCanvas();
|
||||
this._renderService?.refreshRows(0, this._terminal.rows);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public dispose(): void {
|
||||
this._optionsRefresh?.dispose();
|
||||
this.removeLayerFromDom();
|
||||
if (this._terminal._core && this._oldOpen) {
|
||||
this._terminal._core.open = this._oldOpen;
|
||||
this._oldOpen = undefined;
|
||||
}
|
||||
if (this._renderService && this._oldSetRenderer) {
|
||||
this._renderService.setRenderer = this._oldSetRenderer;
|
||||
this._oldSetRenderer = undefined;
|
||||
}
|
||||
this._renderService = undefined;
|
||||
this.canvas = undefined;
|
||||
this._ctx = undefined;
|
||||
this._placeholderBitmap?.close();
|
||||
this._placeholderBitmap = undefined;
|
||||
this._placeholder = undefined;
|
||||
this.register(toDisposable(() => {
|
||||
this.removeLayerFromDom();
|
||||
if (this._terminal._core && this._oldOpen) {
|
||||
this._terminal._core.open = this._oldOpen;
|
||||
this._oldOpen = undefined;
|
||||
}
|
||||
if (this._renderService && this._oldSetRenderer) {
|
||||
this._renderService.setRenderer = this._oldSetRenderer;
|
||||
this._oldSetRenderer = undefined;
|
||||
}
|
||||
this._renderService = undefined;
|
||||
this.canvas = undefined;
|
||||
this._ctx = undefined;
|
||||
this._placeholderBitmap?.close();
|
||||
this._placeholderBitmap = undefined;
|
||||
this._placeholder = undefined;
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
import { ThroughputRuntimeCase, perfContext } from 'xterm-benchmark';
|
||||
import { Base64Decoder } from './base64.wasm';
|
||||
|
||||
// eslint-disable-next-line
|
||||
declare const Buffer: any;
|
||||
|
||||
function toBytes(s: string): Uint8Array {
|
||||
const bytes = new Uint8Array(s.length);
|
||||
for (let i = 0; i < s.length; ++i) {
|
||||
bytes[i] = s.charCodeAt(i) & 0xFF;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
const d256 = 'ABCD'.repeat(64);
|
||||
const d4096 = 'ABCD'.repeat(64 * 16);
|
||||
const d65536 = 'ABCD'.repeat(64 * 16 * 16);
|
||||
const d1M = 'ABCD'.repeat(64 * 16 * 16 * 16);
|
||||
const b256 = toBytes(d256);
|
||||
const b4096 = toBytes(d4096);
|
||||
const b65536 = toBytes(d65536);
|
||||
const b1M = toBytes(d1M);
|
||||
const dec = new Base64Decoder(4000000);
|
||||
|
||||
|
||||
const RUNS = 100;
|
||||
|
||||
perfContext('Base64', () => {
|
||||
perfContext('Node - Buffer', () => {
|
||||
new ThroughputRuntimeCase('decode - 256', () => {
|
||||
Buffer.from(d256, 'base64');
|
||||
return { payloadSize: d256.length };
|
||||
}, { repeat: RUNS }).showAverageThroughput();
|
||||
|
||||
new ThroughputRuntimeCase('decode - 4096', () => {
|
||||
Buffer.from(d4096, 'base64');
|
||||
return { payloadSize: d4096.length };
|
||||
}, { repeat: RUNS }).showAverageThroughput();
|
||||
|
||||
new ThroughputRuntimeCase('decode - 65536', () => {
|
||||
Buffer.from(d65536, 'base64');
|
||||
return { payloadSize: d65536.length };
|
||||
}, { repeat: RUNS }).showAverageThroughput();
|
||||
|
||||
new ThroughputRuntimeCase('decode - 1048576', () => {
|
||||
Buffer.from(d1M, 'base64');
|
||||
return { payloadSize: d1M.length };
|
||||
}, { repeat: RUNS }).showAverageThroughput();
|
||||
});
|
||||
|
||||
perfContext('Base64Decoder', () => {
|
||||
new ThroughputRuntimeCase('decode - 256', () => {
|
||||
dec.init(192);
|
||||
dec.put(b256, 0, b256.length);
|
||||
dec.end();
|
||||
return { payloadSize: b256.length };
|
||||
}, { repeat: RUNS }).showAverageThroughput();
|
||||
|
||||
new ThroughputRuntimeCase('decode - 4096', () => {
|
||||
dec.init(3072);
|
||||
dec.put(b4096, 0, b4096.length);
|
||||
dec.end();
|
||||
return { payloadSize: b4096.length };
|
||||
}, { repeat: RUNS }).showAverageThroughput();
|
||||
|
||||
new ThroughputRuntimeCase('decode - 65536', () => {
|
||||
dec.init(49152);
|
||||
dec.put(b65536, 0, b65536.length);
|
||||
dec.end();
|
||||
return { payloadSize: b65536.length };
|
||||
}, { repeat: RUNS }).showAverageThroughput();
|
||||
|
||||
new ThroughputRuntimeCase('decode - 1048576', () => {
|
||||
dec.init(786432);
|
||||
dec.put(b1M, 0, b1M.length);
|
||||
dec.end();
|
||||
return { payloadSize: b1M.length };
|
||||
}, { repeat: RUNS }).showAverageThroughput();
|
||||
});
|
||||
});
|
||||
@@ -1,156 +0,0 @@
|
||||
import { assert } from 'chai';
|
||||
import { Base64Decoder } from './base64.wasm';
|
||||
|
||||
// eslint-disable-next-line
|
||||
declare const Buffer: any;
|
||||
|
||||
|
||||
// some helpers
|
||||
function toBs(bytes: Uint8Array): string {
|
||||
let bs = '';
|
||||
for (let i = 0; i < bytes.length; ++i) bs += String.fromCharCode(bytes[i]);
|
||||
return bs;
|
||||
}
|
||||
function fromBs(bs: string): Uint8Array {
|
||||
const r = new Uint8Array(bs.length);
|
||||
for (let i = 0; i < r.length; ++i) r[i] = bs.charCodeAt(i);
|
||||
return r;
|
||||
}
|
||||
function encNative(bytes: Uint8Array): string {
|
||||
return typeof Buffer !== 'undefined' ? Buffer.from(bytes).toString('base64') : btoa(toBs(bytes));
|
||||
}
|
||||
function rtrim(x: string, c: string): string {
|
||||
let end = x.length - 1;
|
||||
while (c.indexOf(x[end]) >= 0) end -= 1;
|
||||
return x.slice(0, end + 1);
|
||||
}
|
||||
const MAP = new Uint8Array(
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||
.split('')
|
||||
.map(el => el.charCodeAt(0))
|
||||
);
|
||||
|
||||
|
||||
describe('Base64Decoder', () => {
|
||||
describe('decoding', () => {
|
||||
it('single bytes', function() {
|
||||
this.timeout(20000);
|
||||
const dec = new Base64Decoder(0);
|
||||
for (let i = 0; i < 256; ++i) {
|
||||
dec.init(1);
|
||||
const inp = new Uint8Array([i]);
|
||||
const data = fromBs(encNative(inp));
|
||||
assert.strictEqual(dec.put(data, 0, data.length), 0);
|
||||
assert.strictEqual(dec.end(), 0);
|
||||
assert.deepEqual(dec.data8, inp);
|
||||
}
|
||||
});
|
||||
for (let a = 0; a < 256; ++a) {
|
||||
it(`1+2 bytes (${a})`, function() {
|
||||
const dec = new Base64Decoder(0);
|
||||
for (let b = 0; b < 256; ++b) {
|
||||
dec.init(2);
|
||||
const inp = new Uint8Array([a, b]);
|
||||
const data = fromBs(encNative(inp));
|
||||
assert.strictEqual(dec.put(data, 0, data.length), 0);
|
||||
assert.strictEqual(dec.end(), 0);
|
||||
assert.deepEqual(dec.data8, inp);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (let a = 0; a < 256; ++a) {
|
||||
it(`2+3 bytes (${a})`, function() {
|
||||
const dec = new Base64Decoder(0);
|
||||
for (let b = 0; b < 256; ++b) {
|
||||
dec.init(3);
|
||||
const inp = new Uint8Array([0, a, b]);
|
||||
const data = fromBs(encNative(inp));
|
||||
assert.strictEqual(dec.put(data, 0, data.length), 0);
|
||||
assert.strictEqual(dec.end(), 0);
|
||||
assert.deepEqual(dec.data8, inp);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (let a = 0; a < 256; ++a) {
|
||||
it(`3+4 bytes (${a})`, function() {
|
||||
const dec = new Base64Decoder(0);
|
||||
for (let b = 0; b < 256; ++b) {
|
||||
dec.init(4);
|
||||
const inp = new Uint8Array([0, 0, a, b]);
|
||||
const data = fromBs(encNative(inp));
|
||||
assert.strictEqual(dec.put(data, 0, data.length), 0);
|
||||
assert.strictEqual(dec.end(), 0);
|
||||
assert.deepEqual(dec.data8, inp);
|
||||
}
|
||||
});
|
||||
}
|
||||
it('padding', () => {
|
||||
const dec = new Base64Decoder(0);
|
||||
const d = fromBs('Hello, here comes the mouse');
|
||||
const encData = [];
|
||||
const encDataTrimmed = [];
|
||||
for (let i = 1; i < d.length; ++i) {
|
||||
encData.push(encNative(d.slice(0, i)));
|
||||
encDataTrimmed.push(rtrim(encNative(d.slice(0, i)), '='));
|
||||
}
|
||||
for (let i = 0; i < encData.length; ++i) {
|
||||
// with padding
|
||||
dec.init(i + 1);
|
||||
let enc = fromBs(encData[i]);
|
||||
assert.strictEqual(dec.put(enc, 0, enc.length), 0);
|
||||
assert.strictEqual(dec.end(), 0);
|
||||
assert.deepEqual(dec.data8, d.slice(0, i + 1));
|
||||
// w'o padding
|
||||
dec.init(i + 1);
|
||||
enc = fromBs(encDataTrimmed[i]);
|
||||
assert.strictEqual(dec.put(enc, 0, enc.length), 0);
|
||||
assert.strictEqual(dec.end(), 0);
|
||||
assert.deepEqual(dec.data8, d.slice(0, i + 1));
|
||||
}
|
||||
});
|
||||
it('exit on false byte', function() {
|
||||
this.timeout(20000);
|
||||
const dec = new Base64Decoder(0);
|
||||
for (let pos = 0; pos < 8; ++pos) {
|
||||
const inp = new Uint8Array([65, 65, 65, 65, 65, 65, 65, 65]);
|
||||
for (let i = 0; i < 256; ++i) {
|
||||
dec.release();
|
||||
dec.init(6);
|
||||
inp[pos] = i;
|
||||
dec.put(inp, 0, 8);
|
||||
assert.strictEqual(dec.end(), MAP.includes(i) ? 0 : 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
describe('memory', () => {
|
||||
it('always release (keepSize 0)', () => {
|
||||
const dec = new Base64Decoder(0);
|
||||
dec.init(16);
|
||||
dec.put(fromBs('A'.repeat(16)), 0, 16);
|
||||
dec.end();
|
||||
assert.strictEqual(dec.data8.length, 12);
|
||||
dec.release();
|
||||
assert.strictEqual(dec.data8.length, 0);
|
||||
assert.isNull((dec as any)._mem);
|
||||
});
|
||||
it('keep 1 page (keepSize 65536)', () => {
|
||||
const dec = new Base64Decoder(65536);
|
||||
dec.init(384);
|
||||
dec.put(fromBs('A'.repeat(512)), 0, 512);
|
||||
dec.end();
|
||||
assert.strictEqual(dec.data8.length, 384);
|
||||
dec.release();
|
||||
assert.strictEqual(dec.data8.length, 0);
|
||||
assert.isNotNull((dec as any)._mem);
|
||||
// grow to 2 pages + free afterwards
|
||||
dec.init(65536);
|
||||
dec.put(fromBs('A'.repeat(65536)), 0, 65536);
|
||||
dec.end();
|
||||
assert.strictEqual(dec.data8.length, 49152);
|
||||
dec.release();
|
||||
assert.strictEqual(dec.data8.length, 0);
|
||||
assert.isNull((dec as any)._mem);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,372 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2023 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
import { InWasm, IWasmInstance, OutputMode, OutputType } from 'inwasm';
|
||||
|
||||
|
||||
// memory addresses in uint32
|
||||
const enum P32 {
|
||||
D0 = 256,
|
||||
D1 = 512,
|
||||
D2 = 768,
|
||||
D3 = 1024,
|
||||
STATE = 1280,
|
||||
STATE_WP = 1280,
|
||||
STATE_SP = 1281,
|
||||
STATE_DP = 1282,
|
||||
STATE_ESIZE = 1283,
|
||||
STATE_BSIZE = 1284,
|
||||
STATE_DATA = 1288 // 16 aligned
|
||||
}
|
||||
|
||||
/**
|
||||
* wasm base64 decoder.
|
||||
*/
|
||||
const wasmDecode = InWasm({
|
||||
name: 'decode',
|
||||
type: OutputType.INSTANCE,
|
||||
mode: OutputMode.SYNC,
|
||||
srctype: 'Clang-C',
|
||||
imports: {
|
||||
env: { memory: new WebAssembly.Memory({ initial: 1 }) }
|
||||
},
|
||||
exports: {
|
||||
dec: () => 0,
|
||||
end: () => 0
|
||||
},
|
||||
compile: {
|
||||
switches: ['-Wl,-z,stack-size=0', '-Wl,--stack-first']
|
||||
},
|
||||
code: `
|
||||
typedef struct {
|
||||
unsigned int wp;
|
||||
unsigned int sp;
|
||||
unsigned int dp;
|
||||
unsigned int e_size;
|
||||
unsigned int b_size;
|
||||
unsigned int dummy[3];
|
||||
unsigned char data[0];
|
||||
} State;
|
||||
|
||||
unsigned int *D0 = (unsigned int *) ${P32.D0*4};
|
||||
unsigned int *D1 = (unsigned int *) ${P32.D1*4};
|
||||
unsigned int *D2 = (unsigned int *) ${P32.D2*4};
|
||||
unsigned int *D3 = (unsigned int *) ${P32.D3*4};
|
||||
State *state = (State *) ${P32.STATE*4};
|
||||
|
||||
__attribute__((noinline)) int dec() {
|
||||
unsigned int nsp = (state->wp - 1) & ~3;
|
||||
unsigned char *src = state->data + state->sp;
|
||||
unsigned char *end = state->data + nsp;
|
||||
unsigned char *dst = state->data + state->dp;
|
||||
unsigned int accu;
|
||||
|
||||
while (src < end) {
|
||||
if ((accu = D0[src[0]] | D1[src[1]] | D2[src[2]] | D3[src[3]]) >> 24) return 1;
|
||||
*((unsigned int *) dst) = accu;
|
||||
dst += 3;
|
||||
src += 4;
|
||||
}
|
||||
state->sp = nsp;
|
||||
state->dp = dst - state->data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int end() {
|
||||
int rem = state->wp - state->sp;
|
||||
if (rem > 4 && dec()) return 1;
|
||||
rem = state->wp - state->sp;
|
||||
if (rem < 2) return 1;
|
||||
|
||||
unsigned char *src = state->data + state->sp;
|
||||
unsigned int accu = D0[src[0]] | D1[src[1]];
|
||||
int dp = 1;
|
||||
if (rem > 2 && src[2] != 61) {
|
||||
accu |= D2[src[2]];
|
||||
dp++;
|
||||
}
|
||||
if (rem == 4 && src[3] != 61) {
|
||||
accu |= D3[src[3]];
|
||||
dp++;
|
||||
}
|
||||
if (accu >> 24) return 1;
|
||||
*((unsigned int *) (state->data + state->dp)) = accu;
|
||||
state->dp += dp;
|
||||
return state->dp != state->b_size;
|
||||
}
|
||||
`
|
||||
});
|
||||
|
||||
// SIMD version - commented out for now due to missing Safari support
|
||||
// const wasmDecode = InWasm({
|
||||
// name: 'decode',
|
||||
// type: OutputType.INSTANCE,
|
||||
// mode: OutputMode.SYNC,
|
||||
// srctype: 'Clang-C',
|
||||
// imports: {
|
||||
// env: { memory: new WebAssembly.Memory({ initial: 1 }) }
|
||||
// },
|
||||
// exports: {
|
||||
// dec: () => 0,
|
||||
// end: () => 0
|
||||
// },
|
||||
// compile: {
|
||||
// switches: ['-msimd128', '-Wl,-z,stack-size=0', '-Wl,--stack-first']
|
||||
// },
|
||||
// code: `
|
||||
// #include <wasm_simd128.h>
|
||||
// typedef struct {
|
||||
// unsigned int wp;
|
||||
// unsigned int sp;
|
||||
// unsigned int dp;
|
||||
// unsigned int e_size;
|
||||
// unsigned int b_size;
|
||||
// unsigned int dummy[3];
|
||||
// unsigned char data[0];
|
||||
// } State;
|
||||
//
|
||||
// unsigned int *D0 = (unsigned int *) ${P32.D0*4};
|
||||
// unsigned int *D1 = (unsigned int *) ${P32.D1*4};
|
||||
// unsigned int *D2 = (unsigned int *) ${P32.D2*4};
|
||||
// unsigned int *D3 = (unsigned int *) ${P32.D3*4};
|
||||
// State *state = (State *) ${P32.STATE*4};
|
||||
//
|
||||
// #define packed_byte(x) wasm_i8x16_splat((char) x)
|
||||
// #define packed_dword(x) wasm_i32x4_splat(x)
|
||||
// #define masked(x, mask) wasm_v128_and(x, wasm_i32x4_splat(mask))
|
||||
//
|
||||
// int dec4() {
|
||||
// unsigned int nsp = (state->wp - 1) & ~3;
|
||||
// unsigned char *src = state->data + state->sp;
|
||||
// unsigned char *end = state->data + nsp;
|
||||
// unsigned char *dst = state->data + state->dp;
|
||||
// unsigned int accu;
|
||||
//
|
||||
// while (src < end) {
|
||||
// if ((accu = D0[src[0]] | D1[src[1]] | D2[src[2]] | D3[src[3]]) >> 24) return 1;
|
||||
// *((unsigned int *) dst) = accu;
|
||||
// dst += 3;
|
||||
// src += 4;
|
||||
// }
|
||||
// state->sp = nsp;
|
||||
// state->dp = dst - state->data;
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// int dec() {
|
||||
// unsigned int nsp = (state->wp - 1) & ~15;
|
||||
// unsigned char *src = state->data + state->sp;
|
||||
// unsigned char *end = state->data + nsp;
|
||||
// unsigned char *dst = state->data + state->dp;
|
||||
// unsigned int accu;
|
||||
//
|
||||
// v128_t err = wasm_i8x16_splat(0);
|
||||
//
|
||||
// while (src < end) {
|
||||
// v128_t data = wasm_v128_load((v128_t *) src);
|
||||
//
|
||||
// // wasm-simd rewrite of http://0x80.pl/notesen/2016-01-17-sse-base64-decoding.html#vector-lookup-pshufb
|
||||
// const v128_t higher_nibble = wasm_u32x4_shr(data, 4) & packed_byte(0x0f);
|
||||
// const char linv = 1;
|
||||
// const char hinv = 0;
|
||||
//
|
||||
// const v128_t lower_bound_LUT = wasm_i8x16_make(
|
||||
// /* 0 */ linv, /* 1 */ linv, /* 2 */ 0x2b, /* 3 */ 0x30,
|
||||
// /* 4 */ 0x41, /* 5 */ 0x50, /* 6 */ 0x61, /* 7 */ 0x70,
|
||||
// /* 8 */ linv, /* 9 */ linv, /* a */ linv, /* b */ linv,
|
||||
// /* c */ linv, /* d */ linv, /* e */ linv, /* f */ linv
|
||||
// );
|
||||
// const v128_t upper_bound_LUT = wasm_i8x16_make(
|
||||
// /* 0 */ hinv, /* 1 */ hinv, /* 2 */ 0x2b, /* 3 */ 0x39,
|
||||
// /* 4 */ 0x4f, /* 5 */ 0x5a, /* 6 */ 0x6f, /* 7 */ 0x7a,
|
||||
// /* 8 */ hinv, /* 9 */ hinv, /* a */ hinv, /* b */ hinv,
|
||||
// /* c */ hinv, /* d */ hinv, /* e */ hinv, /* f */ hinv
|
||||
// );
|
||||
// // the difference between the shift and lower bound
|
||||
// const v128_t shift_LUT = wasm_i8x16_make(
|
||||
// /* 0 */ 0x00, /* 1 */ 0x00, /* 2 */ 0x3e - 0x2b, /* 3 */ 0x34 - 0x30,
|
||||
// /* 4 */ 0x00 - 0x41, /* 5 */ 0x0f - 0x50, /* 6 */ 0x1a - 0x61, /* 7 */ 0x29 - 0x70,
|
||||
// /* 8 */ 0x00, /* 9 */ 0x00, /* a */ 0x00, /* b */ 0x00,
|
||||
// /* c */ 0x00, /* d */ 0x00, /* e */ 0x00, /* f */ 0x00
|
||||
// );
|
||||
//
|
||||
// const v128_t upper_bound = wasm_i8x16_swizzle(upper_bound_LUT, higher_nibble);
|
||||
// const v128_t lower_bound = wasm_i8x16_swizzle(lower_bound_LUT, higher_nibble);
|
||||
//
|
||||
// const v128_t below = wasm_i8x16_lt(data, lower_bound);
|
||||
// const v128_t above = wasm_i8x16_gt(data, upper_bound);
|
||||
// const v128_t eq_2f = wasm_i8x16_eq(data, packed_byte(0x2f));
|
||||
//
|
||||
// // in_range = not (below or above) or eq_2f
|
||||
// // outside = not in_range = below or above and not eq_2f (from deMorgan law)
|
||||
// const v128_t outside = wasm_v128_andnot(eq_2f, above | below);
|
||||
// err = wasm_v128_or(err, outside);
|
||||
//
|
||||
// const v128_t shift = wasm_i8x16_swizzle(shift_LUT, higher_nibble);
|
||||
// const v128_t t0 = wasm_i8x16_add(data, shift);
|
||||
// v128_t v = wasm_i8x16_add(t0, wasm_v128_and(eq_2f, packed_byte(-3)));
|
||||
//
|
||||
// // pack bytes
|
||||
// const v128_t ca = masked(v, 0x003f003f);
|
||||
// const v128_t db = masked(v, 0x3f003f00);
|
||||
// const v128_t t00 = wasm_v128_or(wasm_u32x4_shr(db, 8), wasm_i32x4_shl(ca, 6));
|
||||
// v128_t res = wasm_v128_or(wasm_u32x4_shr(t00, 16), wasm_i32x4_shl(t00, 12));
|
||||
// res = wasm_i8x16_swizzle(res, wasm_i8x16_const(2, 1, 0, 6, 5, 4, 10, 9, 8, 14, 13, 12, 16, 16, 16, 16));
|
||||
//
|
||||
// wasm_v128_store((v128_t *) dst, res);
|
||||
// dst += 12;
|
||||
// src += 16;
|
||||
// }
|
||||
//
|
||||
// if (wasm_i8x16_bitmask(err) != 0) return 1;
|
||||
//
|
||||
// state->sp = nsp;
|
||||
// state->dp = dst - state->data;
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// int end() {
|
||||
// int rem = state->wp - state->sp;
|
||||
// if (rem > 4 && dec4()) return 1;
|
||||
// rem = state->wp - state->sp;
|
||||
// if (rem < 2) return 1;
|
||||
//
|
||||
// unsigned char *src = state->data + state->sp;
|
||||
// unsigned int accu = D0[src[0]] | D1[src[1]];
|
||||
// int dp = 1;
|
||||
// if (rem > 2 && src[2] != 61) {
|
||||
// accu |= D2[src[2]];
|
||||
// dp++;
|
||||
// }
|
||||
// if (rem == 4 && src[3] != 61) {
|
||||
// accu |= D3[src[3]];
|
||||
// dp++;
|
||||
// }
|
||||
// if (accu >> 24) return 1;
|
||||
// *((unsigned int *) (state->data + state->dp)) = accu;
|
||||
// state->dp += dp;
|
||||
// return state->dp != state->b_size;
|
||||
// }
|
||||
// `
|
||||
// });
|
||||
|
||||
// FIXME: currently broken in inwasm
|
||||
type ExtractDefinition<Type> = Type extends () => IWasmInstance<infer X> ? X : never;
|
||||
type DecodeDefinition = ExtractDefinition<typeof wasmDecode>;
|
||||
|
||||
// base64 map
|
||||
const MAP = new Uint8Array(
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||
.split('')
|
||||
.map(el => el.charCodeAt(0))
|
||||
);
|
||||
|
||||
// init decoder maps in LE order
|
||||
const D = new Uint32Array(1024);
|
||||
D.fill(0xFF000000);
|
||||
for (let i = 0; i < MAP.length; ++i) D[MAP[i]] = i << 2;
|
||||
for (let i = 0; i < MAP.length; ++i) D[256 + MAP[i]] = i >> 4 | ((i << 4) & 0xFF) << 8;
|
||||
for (let i = 0; i < MAP.length; ++i) D[512 + MAP[i]] = (i >> 2) << 8 | ((i << 6) & 0xFF) << 16;
|
||||
for (let i = 0; i < MAP.length; ++i) D[768 + MAP[i]] = i << 16;
|
||||
|
||||
const EMPTY = new Uint8Array(0);
|
||||
|
||||
/**
|
||||
* base64 streamline inplace decoder.
|
||||
*
|
||||
* Features / assumptions:
|
||||
* - optimized uint32 read/write (only LE support!)
|
||||
* - lazy chunkwise decoding
|
||||
* - errors out on any non base64 chars (no support for NL formatted base64)
|
||||
* - decodes in wasm
|
||||
* - inplace decoding to save memory
|
||||
* - supports a keepSize for lazy memory release
|
||||
*/
|
||||
export class Base64Decoder {
|
||||
private _d!: Uint8Array;
|
||||
private _m32!: Uint32Array;
|
||||
private _inst!: IWasmInstance<DecodeDefinition>;
|
||||
private _mem!: WebAssembly.Memory;
|
||||
|
||||
constructor(public keepSize: number) {}
|
||||
|
||||
/**
|
||||
* Currently decoded bytes (borrowed).
|
||||
* Must be accessed before calling `release` or `init`.
|
||||
*/
|
||||
public get data8(): Uint8Array {
|
||||
return this._inst ? this._d.subarray(0, this._m32[P32.STATE_DP]) : EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release memory conditionally based on `keepSize`.
|
||||
* If memory gets released, also the wasm instance will be freed and recreated on next `init`,
|
||||
* otherwise the instance will be reused.
|
||||
*/
|
||||
public release(): void {
|
||||
if (!this._inst) return;
|
||||
if (this._mem.buffer.byteLength > this.keepSize) {
|
||||
this._inst = this._m32 = this._d = this._mem = null!;
|
||||
} else {
|
||||
this._m32[P32.STATE_WP] = 0;
|
||||
this._m32[P32.STATE_SP] = 0;
|
||||
this._m32[P32.STATE_DP] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the decoder for new base64 data.
|
||||
* Must be called before doing any decoding attempts.
|
||||
* `size` is the amount of decoded bytes to be expected.
|
||||
* The method will either spawn a new wasm instance or grow
|
||||
* the needed memory of an existing instance.
|
||||
*/
|
||||
public init(size: number): void {
|
||||
let m = this._m32;
|
||||
const bytes = (Math.ceil(size / 3) + P32.STATE_DATA) * 4;
|
||||
if (!this._inst) {
|
||||
this._mem = new WebAssembly.Memory({ initial: Math.ceil(bytes / 65536) });
|
||||
this._inst = wasmDecode({ env: { memory: this._mem } });
|
||||
m = new Uint32Array(this._mem.buffer, 0);
|
||||
m.set(D, P32.D0);
|
||||
this._d = new Uint8Array(this._mem.buffer, P32.STATE_DATA * 4);
|
||||
} else if (this._mem.buffer.byteLength < bytes) {
|
||||
this._mem.grow(Math.ceil((bytes - this._mem.buffer.byteLength) / 65536));
|
||||
m = new Uint32Array(this._mem.buffer, 0);
|
||||
this._d = new Uint8Array(this._mem.buffer, P32.STATE_DATA * 4);
|
||||
}
|
||||
m[P32.STATE_BSIZE] = size;
|
||||
m[P32.STATE_ESIZE] = Math.ceil(size / 3) * 4;
|
||||
m[P32.STATE_WP] = 0;
|
||||
m[P32.STATE_SP] = 0;
|
||||
m[P32.STATE_DP] = 0;
|
||||
this._m32 = m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put bytes in `data` from `start` to `end` (exclusive) into the decoder.
|
||||
* Also decodes base64 data inplace once the payload exceeds 2^17 bytes.
|
||||
* Returns 1 on error, else 0.
|
||||
*/
|
||||
public put(data: Uint8Array | Uint16Array | Uint32Array, start: number, end: number): number {
|
||||
if (!this._inst) return 1;
|
||||
const m = this._m32;
|
||||
if (end - start + m[P32.STATE_WP] > m[P32.STATE_ESIZE]) return 1;
|
||||
this._d.set(data.subarray(start, end), m[P32.STATE_WP]);
|
||||
m[P32.STATE_WP] += end - start;
|
||||
// max chunk in input handler is 2^17, try to run in "tandem mode"
|
||||
// also assures that we dont run into illegal offsets in the wasm part
|
||||
return m[P32.STATE_WP] - m[P32.STATE_SP] >= 131072 ? this._inst.exports.dec() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* End the current decoding.
|
||||
* Decodes leftover payload and finally checks for the correct amount of
|
||||
* decoded bytes by comparing to the value given to `init`.
|
||||
* Returns 1 on error, else 0.
|
||||
*/
|
||||
public end(): number {
|
||||
return this._inst ? this._inst.exports.end() : 1;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { Terminal, IDisposable, ITerminalAddon, IDecoration } from 'xterm';
|
||||
import { EventEmitter } from 'common/EventEmitter';
|
||||
import { Disposable, toDisposable, disposeArray } from 'common/Lifecycle';
|
||||
import { Disposable, toDisposable, disposeArray, MutableDisposable } from 'common/Lifecycle';
|
||||
|
||||
export interface ISearchOptions {
|
||||
regex?: boolean;
|
||||
@@ -66,7 +66,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
|
||||
private _cachedSearchTerm: string | undefined;
|
||||
private _highlightedLines: Set<number> = new Set();
|
||||
private _highlightDecorations: IHighlight[] = [];
|
||||
private _selectedDecoration: IHighlight | undefined;
|
||||
private _selectedDecoration: MutableDisposable<IHighlight> = this.register(new MutableDisposable());
|
||||
private _highlightLimit: number;
|
||||
private _lastSearchOptions: ISearchOptions | undefined;
|
||||
private _highlightTimeout: number | undefined;
|
||||
@@ -110,7 +110,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
|
||||
}
|
||||
|
||||
public clearDecorations(retainCachedSearchTerm?: boolean): void {
|
||||
this.clearActiveDecoration();
|
||||
this._selectedDecoration.clear();
|
||||
disposeArray(this._highlightDecorations);
|
||||
this._highlightDecorations = [];
|
||||
this._highlightedLines.clear();
|
||||
@@ -119,11 +119,6 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
|
||||
}
|
||||
}
|
||||
|
||||
public clearActiveDecoration(): void {
|
||||
this._selectedDecoration?.dispose();
|
||||
this._selectedDecoration = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the next instance of the term, then scroll to and select it. If it
|
||||
* doesn't exist, do nothing.
|
||||
@@ -320,8 +315,8 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
|
||||
private _fireResults(searchOptions?: ISearchOptions): void {
|
||||
if (searchOptions?.decorations) {
|
||||
let resultIndex = -1;
|
||||
if (this._selectedDecoration) {
|
||||
const selectedMatch = this._selectedDecoration.match;
|
||||
if (this._selectedDecoration.value) {
|
||||
const selectedMatch = this._selectedDecoration.value.match;
|
||||
for (let i = 0; i < this._highlightDecorations.length; i++) {
|
||||
const match = this._highlightDecorations[i].match;
|
||||
if (match.row === selectedMatch.row && match.col === selectedMatch.col && match.size === selectedMatch.size) {
|
||||
@@ -642,7 +637,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
|
||||
*/
|
||||
private _selectResult(result: ISearchResult | undefined, options?: ISearchDecorationOptions, noScroll?: boolean): boolean {
|
||||
const terminal = this._terminal!;
|
||||
this.clearActiveDecoration();
|
||||
this._selectedDecoration.clear();
|
||||
if (!result) {
|
||||
terminal.clearSelection();
|
||||
return false;
|
||||
@@ -666,7 +661,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
|
||||
disposables.push(marker);
|
||||
disposables.push(decoration.onRender((e) => this._applyStyles(e, options.activeMatchBorder, true)));
|
||||
disposables.push(decoration.onDispose(() => disposeArray(disposables)));
|
||||
this._selectedDecoration = { decoration, match: result, dispose() { decoration.dispose(); } };
|
||||
this._selectedDecoration.value = { decoration, match: result, dispose() { decoration.dispose(); } };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,8 +414,6 @@ class StringSerializeHandler extends BaseSerializeHandler {
|
||||
export class SerializeAddon implements ITerminalAddon {
|
||||
private _terminal: Terminal | undefined;
|
||||
|
||||
constructor() { }
|
||||
|
||||
public activate(terminal: Terminal): void {
|
||||
this._terminal = terminal;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import { CellData } from 'common/buffer/CellData';
|
||||
import { Attributes, Content, NULL_CELL_CHAR, NULL_CELL_CODE } from 'common/buffer/Constants';
|
||||
import { traceCall } from 'common/services/LogService';
|
||||
import { ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
|
||||
import { IDisposable, Terminal } from 'xterm';
|
||||
import { Terminal } from 'xterm';
|
||||
import { GlyphRenderer } from './GlyphRenderer';
|
||||
import { RectangleRenderer } from './RectangleRenderer';
|
||||
import { COMBINED_CHAR_BIT_MASK, RENDER_MODEL_BG_OFFSET, RENDER_MODEL_EXT_OFFSET, RENDER_MODEL_FG_OFFSET, RENDER_MODEL_INDICIES_PER_CELL, RenderModel } from './RenderModel';
|
||||
@@ -31,7 +31,7 @@ import { IRenderLayer } from './renderLayer/Types';
|
||||
export class WebglRenderer extends Disposable implements IRenderer {
|
||||
private _renderLayers: IRenderLayer[];
|
||||
private _cursorBlinkStateManager: MutableDisposable<CursorBlinkStateManager> = new MutableDisposable();
|
||||
private _charAtlasDisposable: IDisposable | undefined;
|
||||
private _charAtlasDisposable = this.register(new MutableDisposable());
|
||||
private _charAtlas: ITextureAtlas | undefined;
|
||||
private _devicePixelRatio: number;
|
||||
|
||||
@@ -41,8 +41,8 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
|
||||
private _canvas: HTMLCanvasElement;
|
||||
private _gl: IWebGL2RenderingContext;
|
||||
private _rectangleRenderer?: RectangleRenderer;
|
||||
private _glyphRenderer?: GlyphRenderer;
|
||||
private _rectangleRenderer: MutableDisposable<RectangleRenderer> = this.register(new MutableDisposable());
|
||||
private _glyphRenderer: MutableDisposable<GlyphRenderer> = this.register(new MutableDisposable());
|
||||
|
||||
public readonly dimensions: IRenderDimensions;
|
||||
|
||||
@@ -128,7 +128,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
|
||||
this._core.screenElement!.appendChild(this._canvas);
|
||||
|
||||
[this._rectangleRenderer, this._glyphRenderer] = this._initializeWebGLState();
|
||||
[this._rectangleRenderer.value, this._glyphRenderer.value] = this._initializeWebGLState();
|
||||
|
||||
this._isAttached = this._coreBrowserService.window.document.body.contains(this._core.screenElement!);
|
||||
|
||||
@@ -182,10 +182,10 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
this._core.screenElement!.style.width = `${this.dimensions.css.canvas.width}px`;
|
||||
this._core.screenElement!.style.height = `${this.dimensions.css.canvas.height}px`;
|
||||
|
||||
this._rectangleRenderer?.setDimensions(this.dimensions);
|
||||
this._rectangleRenderer?.handleResize();
|
||||
this._glyphRenderer?.setDimensions(this.dimensions);
|
||||
this._glyphRenderer?.handleResize();
|
||||
this._rectangleRenderer.value?.setDimensions(this.dimensions);
|
||||
this._rectangleRenderer.value?.handleResize();
|
||||
this._glyphRenderer.value?.setDimensions(this.dimensions);
|
||||
this._glyphRenderer.value?.handleResize();
|
||||
|
||||
this._refreshCharAtlas();
|
||||
|
||||
@@ -241,17 +241,13 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
* Initializes members dependent on WebGL context state.
|
||||
*/
|
||||
private _initializeWebGLState(): [RectangleRenderer, GlyphRenderer] {
|
||||
// Dispose any previous rectangle and glyph renderers before creating new ones.
|
||||
this._rectangleRenderer?.dispose();
|
||||
this._glyphRenderer?.dispose();
|
||||
|
||||
this._rectangleRenderer = this.register(new RectangleRenderer(this._terminal, this._gl, this.dimensions, this._themeService));
|
||||
this._glyphRenderer = this.register(new GlyphRenderer(this._terminal, this._gl, this.dimensions));
|
||||
this._rectangleRenderer.value = new RectangleRenderer(this._terminal, this._gl, this.dimensions, this._themeService);
|
||||
this._glyphRenderer.value = new GlyphRenderer(this._terminal, this._gl, this.dimensions);
|
||||
|
||||
// Update dimensions and acquire char atlas
|
||||
this.handleCharSizeChanged();
|
||||
|
||||
return [this._rectangleRenderer, this._glyphRenderer];
|
||||
return [this._rectangleRenderer.value, this._glyphRenderer.value];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,16 +271,15 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
this._coreBrowserService.dpr
|
||||
);
|
||||
if (this._charAtlas !== atlas) {
|
||||
this._charAtlasDisposable?.dispose();
|
||||
this._onChangeTextureAtlas.fire(atlas.pages[0].canvas);
|
||||
this._charAtlasDisposable = getDisposeArrayDisposable([
|
||||
this._charAtlasDisposable.value = getDisposeArrayDisposable([
|
||||
forwardEvent(atlas.onAddTextureAtlasCanvas, this._onAddTextureAtlasCanvas),
|
||||
forwardEvent(atlas.onRemoveTextureAtlasCanvas, this._onRemoveTextureAtlasCanvas)
|
||||
]);
|
||||
}
|
||||
this._charAtlas = atlas;
|
||||
this._charAtlas.warmUp();
|
||||
this._glyphRenderer?.setAtlas(this._charAtlas);
|
||||
this._glyphRenderer.value?.setAtlas(this._charAtlas);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -295,7 +290,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
private _clearModel(clearGlyphRenderer: boolean): void {
|
||||
this._model.clear();
|
||||
if (clearGlyphRenderer) {
|
||||
this._glyphRenderer?.clear();
|
||||
this._glyphRenderer.value?.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,14 +335,14 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
l.handleGridChanged(this._terminal, start, end);
|
||||
}
|
||||
|
||||
if (!this._glyphRenderer || !this._rectangleRenderer) {
|
||||
if (!this._glyphRenderer.value || !this._rectangleRenderer.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Tell renderer the frame is beginning
|
||||
// upon a model clear also refresh the full viewport model
|
||||
// (also triggered by an atlas page merge, part of #4480)
|
||||
if (this._glyphRenderer.beginFrame()) {
|
||||
if (this._glyphRenderer.value.beginFrame()) {
|
||||
this._clearModel(true);
|
||||
this._updateModel(0, this._terminal.rows - 1);
|
||||
} else {
|
||||
@@ -356,10 +351,10 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
}
|
||||
|
||||
// Render
|
||||
this._rectangleRenderer?.renderBackgrounds();
|
||||
this._glyphRenderer?.render(this._model);
|
||||
this._rectangleRenderer.value.renderBackgrounds();
|
||||
this._glyphRenderer.value.render(this._model);
|
||||
if (!this._cursorBlinkStateManager.value || this._cursorBlinkStateManager.value.isCursorVisible) {
|
||||
this._rectangleRenderer?.renderCursor();
|
||||
this._rectangleRenderer.value.renderCursor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,7 +497,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
this._model.cells[i + RENDER_MODEL_FG_OFFSET] = this._cellColorResolver.result.fg;
|
||||
this._model.cells[i + RENDER_MODEL_EXT_OFFSET] = this._cellColorResolver.result.ext;
|
||||
|
||||
this._glyphRenderer!.updateCell(x, y, code, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext, chars, lastBg);
|
||||
this._glyphRenderer.value!.updateCell(x, y, code, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext, chars, lastBg);
|
||||
|
||||
if (isJoined) {
|
||||
// Restore work cell
|
||||
@@ -511,7 +506,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
// Null out non-first cells
|
||||
for (x++; x < lastCharX; x++) {
|
||||
j = ((y * terminal.cols) + x) * RENDER_MODEL_INDICIES_PER_CELL;
|
||||
this._glyphRenderer!.updateCell(x, y, NULL_CELL_CODE, 0, 0, 0, NULL_CELL_CHAR, 0);
|
||||
this._glyphRenderer.value!.updateCell(x, y, NULL_CELL_CODE, 0, 0, 0, NULL_CELL_CHAR, 0);
|
||||
this._model.cells[j] = NULL_CELL_CODE;
|
||||
this._model.cells[j + RENDER_MODEL_BG_OFFSET] = this._cellColorResolver.result.bg;
|
||||
this._model.cells[j + RENDER_MODEL_FG_OFFSET] = this._cellColorResolver.result.fg;
|
||||
@@ -521,9 +516,9 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
}
|
||||
}
|
||||
if (modelUpdated) {
|
||||
this._rectangleRenderer!.updateBackgrounds(this._model);
|
||||
this._rectangleRenderer.value!.updateBackgrounds(this._model);
|
||||
}
|
||||
this._rectangleRenderer!.updateCursor(this._model);
|
||||
this._rectangleRenderer.value!.updateCursor(this._model);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,7 +49,6 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
|
||||
}));
|
||||
this.register(toDisposable(() => {
|
||||
this._canvas.remove();
|
||||
this._charAtlas?.dispose();
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -1106,7 +1106,7 @@ describe('WebGL Renderer Integration Tests', async () => {
|
||||
|
||||
async function getCellColor(col: number, row: number): Promise<number[]> {
|
||||
await page.evaluate(`
|
||||
window.gl = window.term._core._renderService._renderer._gl;
|
||||
window.gl = window.term._core._renderService._renderer.value._gl;
|
||||
window.result = new Uint8Array(4);
|
||||
window.d = window.term._core._renderService.dimensions;
|
||||
window.gl.readPixels(
|
||||
@@ -1120,7 +1120,7 @@ async function getCellColor(col: number, row: number): Promise<number[]> {
|
||||
|
||||
async function getCellPixels(col: number, row: number): Promise<number[]> {
|
||||
await page.evaluate(`
|
||||
window.gl = window.term._core._renderService._renderer._gl;
|
||||
window.gl = window.term._core._renderService._renderer.value._gl;
|
||||
window.result = new Uint8Array(window.d.device.cell.width * window.d.device.cell.height * 4);
|
||||
window.d = window.term._core._renderService.dimensions;
|
||||
window.gl.readPixels(
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user