From 1473afd1b660b6812f761edea156bac60207d803 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 6 Jun 2019 12:40:06 -0700 Subject: [PATCH 1/2] Add addon docs to README Fixes #2192 --- README.md | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 0f430355..71e6bd06 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.* -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 on 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 it and call `Terminal.loadAddon`: -#### Importing Addons in TypeScript +```ts +import { Terminal } from 'xterm`; +import { WebLinksAddon } from 'xterm-addon-web-links`; -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 -import { Terminal } from 'xterm'; -import { fit } from 'xterm/lib/addons/fit/fit'; -const xterm = new Terminal(); - -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: From c4db8879ac640dccc5e17020fa5c5c14c094077a Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 6 Jun 2019 12:54:50 -0700 Subject: [PATCH 2/2] Improve grammar, add old addon link --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 71e6bd06..0b5a00ed 100644 --- a/README.md +++ b/README.md @@ -56,15 +56,15 @@ import { Terminal } from 'xterm'; ### Addons -⚠️ *This section describes the new addon format introduced in v3.14.0.* +⚠️ *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* -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 on your project: +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: ```bash npm i -S xterm-addon-web-links ``` -Then import it and call `Terminal.loadAddon`: +Then import the addon, instantiate it and call `Terminal.loadAddon`: ```ts import { Terminal } from 'xterm`;