diff --git a/.eslintrc.json b/.eslintrc.json index 427c7a16..3a60f5bc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -14,6 +14,7 @@ "test/benchmark/tsconfig.json", "addons/xterm-addon-attach/src/tsconfig.json", "addons/xterm-addon-attach/test/tsconfig.json", + "addons/xterm-addon-canvas/src/tsconfig.json", "addons/xterm-addon-fit/src/tsconfig.json", "addons/xterm-addon-fit/test/tsconfig.json", "addons/xterm-addon-ligatures/src/tsconfig.json", diff --git a/addons/xterm-addon-canvas/.gitignore b/addons/xterm-addon-canvas/.gitignore new file mode 100644 index 00000000..a9f4ed54 --- /dev/null +++ b/addons/xterm-addon-canvas/.gitignore @@ -0,0 +1,2 @@ +lib +node_modules \ No newline at end of file diff --git a/addons/xterm-addon-canvas/.npmignore b/addons/xterm-addon-canvas/.npmignore new file mode 100644 index 00000000..b203232a --- /dev/null +++ b/addons/xterm-addon-canvas/.npmignore @@ -0,0 +1,29 @@ +# Blacklist - exclude everything except npm defaults such as LICENSE, etc +* +!*/ + +# Whitelist - lib/ +!lib/**/*.d.ts + +!lib/**/*.js +!lib/**/*.js.map + +!lib/**/*.css + +# Whitelist - src/ +!src/**/*.ts +!src/**/*.d.ts + +!src/**/*.js +!src/**/*.js.map + +!src/**/*.css + +# Blacklist - src/ test files +src/**/*.test.ts +src/**/*.test.d.ts +src/**/*.test.js +src/**/*.test.js.map + +# Whitelist - typings/ +!typings/*.d.ts diff --git a/addons/xterm-addon-canvas/LICENSE b/addons/xterm-addon-canvas/LICENSE new file mode 100644 index 00000000..b9dc26fe --- /dev/null +++ b/addons/xterm-addon-canvas/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-canvas/README.md b/addons/xterm-addon-canvas/README.md new file mode 100644 index 00000000..deec04c6 --- /dev/null +++ b/addons/xterm-addon-canvas/README.md @@ -0,0 +1,3 @@ +## xterm-addon-canvas + +TODO: Doc diff --git a/addons/xterm-addon-canvas/package.json b/addons/xterm-addon-canvas/package.json new file mode 100644 index 00000000..3d08e9db --- /dev/null +++ b/addons/xterm-addon-canvas/package.json @@ -0,0 +1,27 @@ +{ + "name": "xterm-addon-canvas", + "version": "0.12.0", + "author": { + "name": "The xterm.js authors", + "url": "https://xtermjs.org/" + }, + "main": "lib/xterm-addon-canvas.js", + "types": "typings/xterm-addon-canvas.d.ts", + "repository": "https://github.com/xtermjs/xterm.js", + "license": "MIT", + "keywords": [ + "terminal", + "canvas", + "xterm", + "xterm.js" + ], + "scripts": { + "build": "../../node_modules/.bin/tsc -p .", + "prepackage": "npm run build", + "package": "../../node_modules/.bin/webpack", + "prepublishOnly": "npm run package" + }, + "peerDependencies": { + "xterm": "^4.0.0" + } +} diff --git a/addons/xterm-addon-canvas/src/CanvasAddon.ts b/addons/xterm-addon-canvas/src/CanvasAddon.ts new file mode 100644 index 00000000..34fffb84 --- /dev/null +++ b/addons/xterm-addon-canvas/src/CanvasAddon.ts @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2022 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { ITerminalAddon, Terminal } from 'xterm'; + +export class CanvasAddon implements ITerminalAddon { + private _terminal?: Terminal; + // private _renderer?: WebglRenderer; + // private _onContextLoss = new EventEmitter(); + // public get onContextLoss(): IEvent { return this._onContextLoss.event; } + + public activate(terminal: Terminal): void { + // if (!terminal.element) { + // throw new Error('Cannot activate WebglAddon before Terminal.open'); + // } + // if (isSafari) { + // throw new Error('Webgl is not currently supported on Safari'); + // } + this._terminal = terminal; + // const renderService: IRenderService = (terminal as any)._core._renderService; + // const characterJoinerService: ICharacterJoinerService = (terminal as any)._core._characterJoinerService; + // const decorationService: IDecorationService = (terminal as any)._core._decorationService; + // const colors: IColorSet = (terminal as any)._core._colorManager.colors; + // this._renderer = new WebglRenderer(terminal, colors, characterJoinerService, decorationService, this._preserveDrawingBuffer); + // this._renderer.onContextLoss(() => this._onContextLoss.fire()); + // renderService.setRenderer(this._renderer); + } + + public dispose(): void { + // if (!this._terminal) { + // throw new Error('Cannot dispose WebglAddon because it is activated'); + // } + // const renderService: IRenderService = (this._terminal as any)._core._renderService; + // renderService.setRenderer((this._terminal as any)._core._createRenderer()); + // renderService.onResize(this._terminal.cols, this._terminal.rows); + // this._renderer?.dispose(); + // this._renderer = undefined; + } + + // public get textureAtlas(): HTMLCanvasElement | undefined { + // return this._renderer?.textureAtlas; + // } + + // public clearTextureAtlas(): void { + // this._renderer?.clearCharAtlas(); + // } +} diff --git a/addons/xterm-addon-canvas/src/tsconfig.json b/addons/xterm-addon-canvas/src/tsconfig.json new file mode 100644 index 00000000..b0c9f6be --- /dev/null +++ b/addons/xterm-addon-canvas/src/tsconfig.json @@ -0,0 +1,40 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "lib": [ + "dom", + "es6", + ], + "rootDir": ".", + "outDir": "../out", + "sourceMap": true, + "removeComments": true, + "baseUrl": ".", + "paths": { + "common/*": [ + "../../../src/common/*" + ], + "browser/*": [ + "../../../src/browser/*" + ] + }, + "strict": true, + "downlevelIteration": true, + "types": [ + "../../../node_modules/@types/mocha" + ] + }, + "include": [ + "./**/*", + "../../../typings/xterm.d.ts" + ], + "references": [ + { + "path": "../../../src/common" + }, + { + "path": "../../../src/browser" + } + ] +} diff --git a/addons/xterm-addon-canvas/tsconfig.json b/addons/xterm-addon-canvas/tsconfig.json new file mode 100644 index 00000000..b711f30a --- /dev/null +++ b/addons/xterm-addon-canvas/tsconfig.json @@ -0,0 +1,7 @@ +{ + "files": [], + "include": [], + "references": [ + { "path": "./src" } + ] +} diff --git a/addons/xterm-addon-canvas/typings/xterm-addon-canvas.d.ts b/addons/xterm-addon-canvas/typings/xterm-addon-canvas.d.ts new file mode 100644 index 00000000..7bbbd63d --- /dev/null +++ b/addons/xterm-addon-canvas/typings/xterm-addon-canvas.d.ts @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { Terminal, ITerminalAddon, IEvent } from 'xterm'; + +declare module 'xterm-addon-canvas' { + /** + * An xterm.js addon that provides search functionality. + */ + export class CanvasAddon implements ITerminalAddon { + public textureAtlas?: HTMLCanvasElement; + + constructor(); + + /** + * Activates the addon. + * @param terminal The terminal the addon is being loaded in. + */ + public activate(terminal: Terminal): void; + + /** + * Disposes the addon. + */ + public dispose(): void; + + /** + * Clears the terminal's texture atlas and triggers a redraw. + */ + public clearTextureAtlas(): void; + } +} diff --git a/addons/xterm-addon-canvas/webpack.config.js b/addons/xterm-addon-canvas/webpack.config.js new file mode 100644 index 00000000..9c98760a --- /dev/null +++ b/addons/xterm-addon-canvas/webpack.config.js @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2019 The xterm.js authors. All rights reserved. + * @license MIT + */ + +const path = require('path'); + +const addonName = 'CanvasAddon'; +const mainFile = 'xterm-addon-canvas.js'; + +module.exports = { + entry: `./out/${addonName}.js`, + devtool: 'source-map', + module: { + rules: [ + { + test: /\.js$/, + use: ["source-map-loader"], + enforce: "pre", + exclude: /node_modules/ + } + ] + }, + resolve: { + modules: ['./node_modules'], + extensions: [ '.js' ], + alias: { + common: path.resolve('../../out/common'), + browser: path.resolve('../../out/browser') + } + }, + output: { + filename: mainFile, + path: path.resolve('./lib'), + library: addonName, + libraryTarget: 'umd' + }, + mode: 'production' +};