Files

38 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

## @xterm/addon-webgl
2019-09-09 09:28:33 -07:00
An addon for [xterm.js](https://github.com/xtermjs/xterm.js) that enables a WebGL2-based renderer. This addon requires xterm.js v4+.
2019-09-09 09:28:33 -07:00
### Install
```bash
npm install --save @xterm/addon-webgl
2019-09-09 09:28:33 -07:00
```
### Usage
```ts
import { Terminal } from '@xterm/xterm';
import { WebglAddon } from '@xterm/addon-webgl';
2019-09-09 09:28:33 -07:00
const terminal = new Terminal();
2022-07-28 04:37:42 -07:00
terminal.open(element);
2019-09-09 09:28:33 -07:00
terminal.loadAddon(new WebglAddon());
```
See the full [API](https://github.com/xtermjs/xterm.js/blob/master/addons/addon-webgl/typings/addon-webgl.d.ts) for more advanced usage.
2021-04-01 15:45:10 -07:00
### Handling Context Loss
2021-04-01 16:57:19 -07:00
The browser may drop WebGL contexts for various reasons like OOM or after the system has been suspended. There is an API exposed that fires the `webglcontextlost` event fired on the canvas so embedders can handle it however they wish. An easy, but suboptimal way, to handle this is by disposing of WebglAddon when the event fires:
2021-04-01 15:45:10 -07:00
```ts
const terminal = new Terminal();
const addon = new WebglAddon();
addon.onContextLoss(e => {
addon.dispose();
});
terminal.loadAddon(addon);
```
Read more about handling WebGL context losses on the [Khronos wiki](https://www.khronos.org/webgl/wiki/HandlingContextLost).