diff --git a/README.md b/README.md index 0f430355..aa89c700 100644 --- a/README.md +++ b/README.md @@ -56,34 +56,33 @@ import { Terminal } from 'xterm'; ### Addons -Addons are JavaScript modules that extend the `Terminal` prototype with new methods and attributes to provide additional functionality. There are a handful available in the main repository in the `src/addons` directory and you can even write your own by using the [public API](https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts). +⚠️ *This section describes the new addon format introduced in v3.14.0, see [here](https://github.com/xtermjs/xterm.js/blob/3.14.2/README.md#addons) for the instructions on the old format* -To use an addon, just import the JavaScript module and pass it to `Terminal`'s `applyAddon` method: +Addons are separate modules that extend the `Terminal` by building on the [xterm.js API](https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts). To use an addon you first need to install it in your project: -```javascript -import { Terminal } from 'xterm'; -import * as fit from 'xterm/lib/addons/fit/fit'; - -Terminal.applyAddon(fit); - -var xterm = new Terminal(); // Instantiate the terminal -xterm.fit(); // Use the `fit` method, provided by the `fit` addon +```bash +npm i -S xterm-addon-web-links ``` -You will also need to include the addon's CSS file if it has one in the folder. +Then import the addon, instantiate it and call `Terminal.loadAddon`: -#### Importing Addons in TypeScript - -There are currently no typings for addons if they are accessed via extending Terminal prototype, so you will need to upcast if using TypeScript, eg. `(xterm as any).fit()`. Alternatively, you can import the addon function and enhance the terminal on demand. This has better typing support and is friendly to treeshaking. - -```typescript +```ts import { Terminal } from 'xterm'; -import { fit } from 'xterm/lib/addons/fit/fit'; -const xterm = new Terminal(); +import { WebLinksAddon } from 'xterm-addon-web-links'; -fit(xterm); // Fit the terminal when necessary +const terminal = new Terminal(); +// Load WebLinksAddon on terminal, this is all that's needed to get web links +// working in the terminal. +terminal.loadAddon(new WebLinksAddon()); ``` +The xterm.js team maintains the following addons but they can be built by anyone: + +- [`xterm-addon-attach`](https://github.com/xtermjs/xterm.js/tree/master/addons/xterm-addon-attach): Attaches to a server running a process via a websocket +- [`xterm-addon-fit`](https://github.com/xtermjs/xterm.js/tree/master/addons/xterm-addon-fit): Fits the terminal to the containing element +- [`xterm-addon-search`](https://github.com/xtermjs/xterm.js/tree/master/addons/xterm-addon-search): Adds search functionality +- [`xterm-addon-web-links`](https://github.com/xtermjs/xterm.js/tree/master/addons/xterm-addon-web-links): Adds web link detection and interaction + ## Browser Support Since xterm.js is typically implemented as a developer tool, only modern browsers are supported officially. Here is a list of the versions we aim to support: diff --git a/demo/server.js b/demo/server.js index 4b3f1bda..3b170813 100644 --- a/demo/server.js +++ b/demo/server.js @@ -40,7 +40,7 @@ function startServer() { var cols = parseInt(req.query.cols), rows = parseInt(req.query.rows), term = pty.spawn(process.platform === 'win32' ? 'cmd.exe' : 'bash', [], { - name: 'xterm-color', + name: 'xterm-256color', cols: cols || 80, rows: rows || 24, cwd: process.env.PWD, diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 1a4ef187..57f866c9 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1818,7 +1818,7 @@ export class InputHandler extends Disposable implements IInputHandler { this._terminal.applicationCursor = false; this._terminal.buffer.scrollTop = 0; this._terminal.buffer.scrollBottom = this._terminal.rows - 1; - this._terminal.curAttrData = DEFAULT_ATTR_DATA; + this._terminal.curAttrData = DEFAULT_ATTR_DATA.clone(); this._terminal.buffer.x = this._terminal.buffer.y = 0; // ? this._terminal.charset = null; this._terminal.glevel = 0; // ?? diff --git a/src/core/buffer/BufferLine.ts b/src/core/buffer/BufferLine.ts index ce3b54b7..91c3a8d1 100644 --- a/src/core/buffer/BufferLine.ts +++ b/src/core/buffer/BufferLine.ts @@ -217,7 +217,7 @@ export class AttributeData implements IAttributeData { } } -export const DEFAULT_ATTR_DATA = new AttributeData(); +export const DEFAULT_ATTR_DATA = Object.freeze(new AttributeData()); /** * CellData - represents a single Cell in the terminal buffer. diff --git a/yarn.lock b/yarn.lock index ab7f1bbb..9a7bfe1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1605,9 +1605,9 @@ esprima@^3.1.3: integrity sha1-/cpRzuYTOJXjyI1TXOSdv/YqRjM= esprima@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804" - integrity sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw== + version "4.0.1" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" + integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== esrecurse@^4.1.0: version "4.2.1" @@ -2545,14 +2545,6 @@ js-yaml@3.13.1, js-yaml@^3.13.1: argparse "^1.0.7" esprima "^4.0.0" -js-yaml@^3.7.0: - version "3.12.0" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1" - integrity sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A== - dependencies: - argparse "^1.0.7" - esprima "^4.0.0" - jsbn@~0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"