Files

56 lines
2.6 KiB
Markdown
Raw Permalink Normal View History

2023-11-01 10:35:10 -07:00
## @xterm/addon-ligatures
2020-04-27 11:24:37 +05:30
2020-05-03 06:26:23 -07:00
Add support for programming ligatures to [xterm.js] when running in environments with access to [Node.js] APIs (such as [Electron]).
2020-04-27 11:24:37 +05:30
### Requirements
2020-04-27 11:24:37 +05:30
2020-05-03 06:26:23 -07:00
* [Node.js] 8.x or higher (present in [Electron] 1.8.3 or higher)
* [xterm.js] 4.0.0 or higher using the default canvas renderer
2020-04-27 11:24:37 +05:30
### Install
2020-04-27 11:24:37 +05:30
```bash
2023-11-01 10:35:10 -07:00
npm install --save @xterm/addon-ligatures
2020-04-27 11:24:37 +05:30
```
### Usage
2020-04-27 11:24:37 +05:30
```ts
2023-11-01 06:50:08 -07:00
import { Terminal } from '@xterm/xterm';
2023-11-01 10:35:10 -07:00
import { LigaturesAddon } from '@xterm/addon-ligatures';
2020-04-27 11:24:37 +05:30
const terminal = new Terminal();
const ligaturesAddon = new LigaturesAddon();
terminal.open(containerElement);
terminal.loadAddon(ligaturesAddon);
2020-04-27 11:24:37 +05:30
```
### How It Works
2020-04-27 11:24:37 +05:30
2020-05-03 06:26:23 -07:00
In a browser environment, font ligature information is read directly by the web browser and used to render text correctly without any intervention from the developer. As of version 3, xterm.js uses the canvas to render characters individually, resulting in a significant performance boost. However, this means that it can no longer lean on the browser to determine when to draw font ligatures.
2020-04-27 11:24:37 +05:30
2020-05-03 06:26:23 -07:00
This package locates the font file on disk for the font currently in use by the terminal and parses the ligature information out of it (via the [font-ligatures] package). As text is rendered in xterm.js, this package annotates it with the locations of ligatures, allowing xterm.js to render it correctly.
2020-04-27 11:24:37 +05:30
2020-05-03 06:26:23 -07:00
Since this package depends on being able to find and resolve a system font from disk, it has to have system access that isn't available in the web browser. As a result, this package is mainly useful in environments that combine browser and Node.js runtimes (such as [Electron]).
2020-04-27 11:24:37 +05:30
### Fallback Ligatures
When ligatures cannot be fetched from the environment, a set of "fallback" ligatures is used to get the most common ligatures working. These fallback ligatures can be customized with options passed to `LigatureAddon.constructor`.
### Fonts
2020-04-27 11:24:37 +05:30
This package makes use of the following fonts for testing:
* [Fira Code][Fira Code] - [Licensed under the OFL][Fira Code License] by Nikita Prokopov, Mozilla Foundation with reserved names Fira Code, Fira Mono, and Fira Sans
* [Iosevka] - [Licensed under the OFL][Iosevka License] by Belleve Invis with reserved name Iosevka
2020-04-27 11:24:37 +05:30
[xterm.js]: https://github.com/xtermjs/xterm.js
[Electron]: https://electronjs.org/
[Node.js]: https://nodejs.org/
[font-ligatures]: https://github.com/princjef/font-ligatures
[Fira Code]: https://github.com/tonsky/FiraCode
[Fira Code License]: https://github.com/tonsky/FiraCode/blob/master/LICENSE
[Iosevka]: https://github.com/be5invis/Iosevka
[Iosevka License]: https://github.com/be5invis/Iosevka/blob/master/LICENSE.md