diff --git a/addons/xterm-addon-webgl/.gitignore b/addons/xterm-addon-webgl/.gitignore new file mode 100644 index 00000000..a9f4ed54 --- /dev/null +++ b/addons/xterm-addon-webgl/.gitignore @@ -0,0 +1,2 @@ +lib +node_modules \ No newline at end of file diff --git a/addons/xterm-addon-webgl/.npmignore b/addons/xterm-addon-webgl/.npmignore new file mode 100644 index 00000000..e8fc8237 --- /dev/null +++ b/addons/xterm-addon-webgl/.npmignore @@ -0,0 +1,4 @@ +**/*.api.js +**/*.api.ts +tsconfig.json +.yarnrc diff --git a/addons/xterm-addon-webgl/LICENSE b/addons/xterm-addon-webgl/LICENSE new file mode 100644 index 00000000..b9dc26fe --- /dev/null +++ b/addons/xterm-addon-webgl/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018, The xterm.js authors (https://github.com/xtermjs/xterm.js) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/addons/xterm-addon-webgl/package.json b/addons/xterm-addon-webgl/package.json new file mode 100644 index 00000000..34c678dd --- /dev/null +++ b/addons/xterm-addon-webgl/package.json @@ -0,0 +1,20 @@ +{ + "name": "xterm-addon-webgl", + "version": "0.1.0-beta6", + "author": { + "name": "The xterm.js authors", + "url": "https://xtermjs.org/" + }, + "main": "lib/xterm-addon-webgl.js", + "types": "typings/xterm-addon-webgl.d.ts", + "license": "MIT", + "scripts": { + "build": "../../node_modules/.bin/tsc -p src", + "prepackage": "npm run build", + "package": "../../node_modules/.bin/webpack", + "prepublishOnly": "npm run package" + }, + "peerDependencies": { + "xterm": "^3.14.0" + } +} diff --git a/src/renderer/webgl/ColorUtils.ts b/addons/xterm-addon-webgl/src/ColorUtils.ts similarity index 100% rename from src/renderer/webgl/ColorUtils.ts rename to addons/xterm-addon-webgl/src/ColorUtils.ts diff --git a/src/renderer/webgl/GlyphRenderer.ts b/addons/xterm-addon-webgl/src/GlyphRenderer.ts similarity index 99% rename from src/renderer/webgl/GlyphRenderer.ts rename to addons/xterm-addon-webgl/src/GlyphRenderer.ts index 768060e4..50357b28 100644 --- a/src/renderer/webgl/GlyphRenderer.ts +++ b/addons/xterm-addon-webgl/src/GlyphRenderer.ts @@ -9,7 +9,7 @@ import { IWebGL2RenderingContext, IWebGLVertexArrayObject, IRenderModel, IRaster import { INDICIES_PER_CELL } from './WebglRenderer'; import { COMBINED_CHAR_BIT_MASK } from './RenderModel'; import { fill, slice } from 'common/TypedArrayUtils'; -import { NULL_CELL_CODE, WHITESPACE_CELL_CODE } from '../../common/buffer/Constants'; +import { NULL_CELL_CODE, WHITESPACE_CELL_CODE } from 'common/buffer/Constants'; import { getLuminance } from './ColorUtils'; import { Terminal, IBufferLine } from 'xterm'; import { IColorSet } from 'browser/Types'; diff --git a/src/renderer/webgl/Platform.ts b/addons/xterm-addon-webgl/src/Platform.ts similarity index 100% rename from src/renderer/webgl/Platform.ts rename to addons/xterm-addon-webgl/src/Platform.ts diff --git a/src/renderer/webgl/RectangleRenderer.ts b/addons/xterm-addon-webgl/src/RectangleRenderer.ts similarity index 99% rename from src/renderer/webgl/RectangleRenderer.ts rename to addons/xterm-addon-webgl/src/RectangleRenderer.ts index 54fddc7d..401f4568 100644 --- a/src/renderer/webgl/RectangleRenderer.ts +++ b/addons/xterm-addon-webgl/src/RectangleRenderer.ts @@ -8,7 +8,7 @@ import { IRenderModel, IWebGLVertexArrayObject, IWebGL2RenderingContext, ISelect import { fill } from 'common/TypedArrayUtils'; import { INVERTED_DEFAULT_COLOR } from './atlas/Types'; import { is256Color } from './atlas/CharAtlasUtils'; -import { DEFAULT_COLOR } from '../../common/buffer/Constants'; +import { DEFAULT_COLOR } from 'common/buffer/Constants'; import { Terminal } from 'xterm'; import { IColorSet, IColor } from 'browser/Types'; import { IRenderDimensions } from 'browser/renderer/Types'; diff --git a/src/renderer/webgl/RenderModel.ts b/addons/xterm-addon-webgl/src/RenderModel.ts similarity index 100% rename from src/renderer/webgl/RenderModel.ts rename to addons/xterm-addon-webgl/src/RenderModel.ts diff --git a/src/renderer/webgl/Types.ts b/addons/xterm-addon-webgl/src/Types.ts similarity index 100% rename from src/renderer/webgl/Types.ts rename to addons/xterm-addon-webgl/src/Types.ts diff --git a/src/renderer/webgl/WebglRenderer.api.ts b/addons/xterm-addon-webgl/src/WebglRenderer.api.ts similarity index 99% rename from src/renderer/webgl/WebglRenderer.api.ts rename to addons/xterm-addon-webgl/src/WebglRenderer.api.ts index 62a4c7cf..14c27719 100644 --- a/src/renderer/webgl/WebglRenderer.api.ts +++ b/addons/xterm-addon-webgl/src/WebglRenderer.api.ts @@ -5,7 +5,7 @@ import * as puppeteer from 'puppeteer'; import { assert } from 'chai'; -import { ITerminalOptions } from '../../Types'; +import { ITerminalOptions } from '../../../src/Types'; const APP = 'http://127.0.0.1:3000/test'; diff --git a/src/renderer/webgl/WebglRenderer.ts b/addons/xterm-addon-webgl/src/WebglRenderer.ts similarity index 99% rename from src/renderer/webgl/WebglRenderer.ts rename to addons/xterm-addon-webgl/src/WebglRenderer.ts index 8a310abc..a743bfd9 100644 --- a/src/renderer/webgl/WebglRenderer.ts +++ b/addons/xterm-addon-webgl/src/WebglRenderer.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { ITerminal } from '../../Types'; +import { ITerminal } from '../../../src/Types'; import { GlyphRenderer } from './GlyphRenderer'; import { LinkRenderLayer } from './renderLayer/LinkRenderLayer'; import { CursorRenderLayer } from './renderLayer/CursorRenderLayer'; diff --git a/src/renderer/webgl/WebglRendererAddon.ts b/addons/xterm-addon-webgl/src/WebglRendererAddon.ts similarity index 100% rename from src/renderer/webgl/WebglRendererAddon.ts rename to addons/xterm-addon-webgl/src/WebglRendererAddon.ts diff --git a/src/renderer/webgl/WebglUtils.ts b/addons/xterm-addon-webgl/src/WebglUtils.ts similarity index 100% rename from src/renderer/webgl/WebglUtils.ts rename to addons/xterm-addon-webgl/src/WebglUtils.ts diff --git a/src/renderer/webgl/atlas/BaseCharAtlas.ts b/addons/xterm-addon-webgl/src/atlas/BaseCharAtlas.ts similarity index 100% rename from src/renderer/webgl/atlas/BaseCharAtlas.ts rename to addons/xterm-addon-webgl/src/atlas/BaseCharAtlas.ts diff --git a/src/renderer/webgl/atlas/CharAtlasCache.ts b/addons/xterm-addon-webgl/src/atlas/CharAtlasCache.ts similarity index 100% rename from src/renderer/webgl/atlas/CharAtlasCache.ts rename to addons/xterm-addon-webgl/src/atlas/CharAtlasCache.ts diff --git a/src/renderer/webgl/atlas/CharAtlasUtils.ts b/addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts similarity index 96% rename from src/renderer/webgl/atlas/CharAtlasUtils.ts rename to addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts index 0554746d..1c43dd70 100644 --- a/src/renderer/webgl/atlas/CharAtlasUtils.ts +++ b/addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts @@ -4,7 +4,7 @@ */ import { ICharAtlasConfig } from './Types'; -import { DEFAULT_COLOR } from '../../../common/buffer/Constants'; +import { DEFAULT_COLOR } from 'common/buffer/Constants'; import { Terminal, FontWeight } from 'xterm'; import { IColorSet } from 'browser/Types'; diff --git a/src/renderer/webgl/atlas/Types.ts b/addons/xterm-addon-webgl/src/atlas/Types.ts similarity index 100% rename from src/renderer/webgl/atlas/Types.ts rename to addons/xterm-addon-webgl/src/atlas/Types.ts diff --git a/src/renderer/webgl/atlas/WebglCharAtlas.ts b/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts similarity index 99% rename from src/renderer/webgl/atlas/WebglCharAtlas.ts rename to addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts index 48ec0bf4..9a833fdf 100644 --- a/src/renderer/webgl/atlas/WebglCharAtlas.ts +++ b/addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts @@ -6,7 +6,7 @@ import { DIM_OPACITY, IGlyphIdentifier, INVERTED_DEFAULT_COLOR, ICharAtlasConfig } from './Types'; import { BaseCharAtlas } from './BaseCharAtlas'; import { IRasterizedGlyph, IBoundingBox, IRasterizedGlyphSet } from '../Types'; -import { FLAGS, DEFAULT_COLOR, DEFAULT_ATTR } from '../../../common/buffer/Constants'; +import { FLAGS, DEFAULT_COLOR, DEFAULT_ATTR } from 'common/buffer/Constants'; import { is256Color } from './CharAtlasUtils'; import { IColor } from 'browser/Types'; diff --git a/src/renderer/webgl/renderLayer/BaseRenderLayer.ts b/addons/xterm-addon-webgl/src/renderLayer/BaseRenderLayer.ts similarity index 99% rename from src/renderer/webgl/renderLayer/BaseRenderLayer.ts rename to addons/xterm-addon-webgl/src/renderLayer/BaseRenderLayer.ts index 0604da8f..263a0d21 100644 --- a/src/renderer/webgl/renderLayer/BaseRenderLayer.ts +++ b/addons/xterm-addon-webgl/src/renderLayer/BaseRenderLayer.ts @@ -4,8 +4,8 @@ */ import { IRenderLayer } from './Types'; -import { ICellData } from '../../../common/Types'; -import { DEFAULT_COLOR, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_CODE } from '../../../common/buffer/Constants'; +import { ICellData } from 'common/Types'; +import { DEFAULT_COLOR, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_CODE } from 'common/buffer/Constants'; import { DIM_OPACITY, INVERTED_DEFAULT_COLOR, IGlyphIdentifier } from '../atlas/Types'; import { BaseCharAtlas } from '../atlas/BaseCharAtlas'; import { acquireCharAtlas } from '../atlas/CharAtlasCache'; diff --git a/src/renderer/webgl/renderLayer/CursorRenderLayer.ts b/addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts similarity index 99% rename from src/renderer/webgl/renderLayer/CursorRenderLayer.ts rename to addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts index 3f24c6f0..b0bf581f 100644 --- a/src/renderer/webgl/renderLayer/CursorRenderLayer.ts +++ b/addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts @@ -5,8 +5,8 @@ import { Terminal } from 'xterm'; import { BaseRenderLayer } from './BaseRenderLayer'; -import { ICellData } from '../../../common/Types'; -import { CellData } from '../../../common/buffer/CellData'; +import { ICellData } from 'common/Types'; +import { CellData } from 'common/buffer/CellData'; import { IColorSet } from 'browser/Types'; import { IRenderDimensions } from 'browser/renderer/Types'; diff --git a/src/renderer/webgl/renderLayer/LinkRenderLayer.ts b/addons/xterm-addon-webgl/src/renderLayer/LinkRenderLayer.ts similarity index 96% rename from src/renderer/webgl/renderLayer/LinkRenderLayer.ts rename to addons/xterm-addon-webgl/src/renderLayer/LinkRenderLayer.ts index 50a3e111..1ae22cf6 100644 --- a/src/renderer/webgl/renderLayer/LinkRenderLayer.ts +++ b/addons/xterm-addon-webgl/src/renderLayer/LinkRenderLayer.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { ILinkifierEvent, ILinkifierAccessor } from '../../../Types'; +import { ILinkifierEvent, ILinkifierAccessor } from '../../../../src/Types'; import { Terminal } from 'xterm'; import { BaseRenderLayer } from './BaseRenderLayer'; import { INVERTED_DEFAULT_COLOR } from '../atlas/Types'; diff --git a/src/renderer/webgl/renderLayer/Types.ts b/addons/xterm-addon-webgl/src/renderLayer/Types.ts similarity index 100% rename from src/renderer/webgl/renderLayer/Types.ts rename to addons/xterm-addon-webgl/src/renderLayer/Types.ts diff --git a/addons/xterm-addon-webgl/src/tsconfig.json b/addons/xterm-addon-webgl/src/tsconfig.json new file mode 100644 index 00000000..34149159 --- /dev/null +++ b/addons/xterm-addon-webgl/src/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "lib": [ + "dom", + "es6", + ], + "rootDir": ".", + "outDir": "../out", + "sourceMap": true, + "removeComments": true, + "baseUrl": ".", + "paths": { + "common/*": [ "../../../src/common/*" ], + "browser/*": [ "../../../src/browser/*" ] + } + }, + "include": [ + "./**/*", + "../../../typings/xterm.d.ts" + ], + "references": [ + { "path": "../../../src/common" }, + { "path": "../../../src/browser" } + ] +} diff --git a/addons/xterm-addon-webgl/typings/xterm-addon-webgl.d.ts b/addons/xterm-addon-webgl/typings/xterm-addon-webgl.d.ts new file mode 100644 index 00000000..94bc5297 --- /dev/null +++ b/addons/xterm-addon-webgl/typings/xterm-addon-webgl.d.ts @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { Terminal, ILinkMatcherOptions, IDisposable, ITerminalAddon } from 'xterm'; + +declare module 'xterm-addon-search' { + /** + * Options for a search. + */ + export interface ISearchOptions { + /** + * Whether the search term is a regex. + */ + regex?: boolean; + + /** + * Whether to search for a whole word, the result is only valid if it's + * suppounded in "non-word" characters such as `_`, `(`, `)` or space. + */ + wholeWord?: boolean; + + /** + * Whether the search is case sensitive. + */ + caseSensitive?: boolean; + + /** + * Whether to do an indcremental search, this will expand the selection if it + * still matches the term the user typed. Note that this only affects + * `findNext`, not `findPrevious`. + */ + incremental?: boolean; + } + + /** + * An xterm.js addon that provides search functionality. + */ + export class SearchAddon implements ITerminalAddon { + /** + * Activates the addon + * @param terminal The terminal the addon is being loaded in. + */ + public activate(terminal: Terminal): void; + + /** + * Disposes the addon. + */ + public dispose(): void; + + /** + * Search forwards for the next result that matches the search term and + * options. + * @param term The search term. + * @param searchOptions The options for the search. + */ + public findNext(term: string, searchOptions?: ISearchOptions): boolean; + + /** + * Search backwards for the previous result that matches the search term and + * options. + * @param term The search term. + * @param searchOptions The options for the search. + */ + public findPrevious(term: string, searchOptions?: ISearchOptions): boolean; + } +} diff --git a/addons/xterm-addon-webgl/webpack.config.js b/addons/xterm-addon-webgl/webpack.config.js new file mode 100644 index 00000000..825f6734 --- /dev/null +++ b/addons/xterm-addon-webgl/webpack.config.js @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2019 The xterm.js authors. All rights reserved. + * @license MIT + */ + +const path = require('path'); + +const addonName = 'WebglAddon'; +const mainFile = 'xterm-addon-weblg.js'; + +module.exports = { + entry: `./out/${addonName}.js`, + devtool: 'source-map', + module: { + rules: [ + { + test: /\.js$/, + use: ["source-map-loader"], + enforce: "pre", + exclude: /node_modules/ + } + ] + }, + output: { + filename: mainFile, + path: path.resolve('./lib'), + library: addonName, + libraryTarget: 'umd' + }, + mode: 'production' +}; diff --git a/demo/client.ts b/demo/client.ts index e0d55d57..03d1bb73 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -13,6 +13,7 @@ import { AttachAddon } from '../addons/xterm-addon-attach/out/AttachAddon'; import { FitAddon } from '../addons/xterm-addon-fit/out/FitAddon'; import { SearchAddon, ISearchOptions } from '../addons/xterm-addon-search/out/SearchAddon'; import { WebLinksAddon } from '../addons/xterm-addon-web-links/out/WebLinksAddon'; +import { WebglRendererAddon } from '../addons/xterm-addon-webgl/out/WebglRendererAddon'; // Use webpacked version (yarn package) // import { Terminal } from '../lib/xterm'; @@ -43,6 +44,8 @@ let socketURL; let socket; let pid; +(window).webgl = () => term.loadAddon(new WebglRendererAddon()); + const terminalContainer = document.getElementById('terminal-container'); const actionElements = { findNext: document.querySelector('#find-next'), diff --git a/src/public/Terminal.ts b/src/public/Terminal.ts index 23869218..0dae4def 100644 --- a/src/public/Terminal.ts +++ b/src/public/Terminal.ts @@ -11,7 +11,6 @@ import { Terminal as TerminalCore } from '../Terminal'; import * as Strings from '../browser/LocalizableStrings'; import { IEvent } from 'common/EventEmitter'; import { AddonManager } from './AddonManager'; -import { WebglRendererAddon } from '../renderer/webgl/WebglRendererAddon'; export class Terminal implements ITerminalApi { private _core: ITerminal; @@ -161,9 +160,6 @@ export class Terminal implements ITerminalApi { public loadAddon(addon: ITerminalAddon): void { return this._addonManager.loadAddon(this, addon); } - public loadWebgl(preserveDrawingBuffer?: boolean): void { - this.loadAddon(new WebglRendererAddon(preserveDrawingBuffer)); - } public static get strings(): ILocalizableStrings { return Strings; } diff --git a/tsconfig.all.json b/tsconfig.all.json index d2670811..bc633fe6 100644 --- a/tsconfig.all.json +++ b/tsconfig.all.json @@ -8,5 +8,6 @@ { "path": "./addons/xterm-addon-fit/src" }, { "path": "./addons/xterm-addon-search/src" }, { "path": "./addons/xterm-addon-web-links/src" } + { "path": "./addons/xterm-addon-webgl/src" } ] }