|
5 | 5 |
|
6 | 6 | import { Terminal } from 'xterm'; |
7 | 7 | import { enableLigatures } from '.'; |
| 8 | +import { ILigatureOptions } from './Types'; |
8 | 9 |
|
9 | 10 | export interface ITerminalAddon { |
10 | 11 | activate(terminal: Terminal): void; |
11 | 12 | dispose(): void; |
12 | 13 | } |
13 | 14 |
|
14 | 15 | export class LigaturesAddon implements ITerminalAddon { |
15 | | - constructor() {} |
| 16 | + private readonly _fallbackLigatures: string[]; |
| 17 | + |
| 18 | + private _terminal: Terminal | undefined; |
| 19 | + private _characterJoinerId: number | undefined; |
| 20 | + |
| 21 | + constructor(options?: Partial<ILigatureOptions>) { |
| 22 | + this._fallbackLigatures = (options?.fallbackLigatures || [ |
| 23 | + '<--', '<---', '<<-', '<-', '->', '->>', '-->', '--->', |
| 24 | + '<==', '<===', '<<=', '<=', '=>', '=>>', '==>', '===>', '>=', '>>=', |
| 25 | + '<->', '<-->', '<--->', '<---->', '<=>', '<==>', '<===>', '<====>', '-------->', |
| 26 | + '<~~', '<~', '~>', '~~>', '::', ':::', '==', '!=', '===', '!==', |
| 27 | + ':=', ':-', ':+', '<*', '<*>', '*>', '<|', '<|>', '|>', '+:', '-:', '=:', ':>', |
| 28 | + '++', '+++', '<!--', '<!---', '<***>' |
| 29 | + ]).sort((a, b) => b.length - a.length); |
| 30 | + } |
16 | 31 |
|
17 | 32 | public activate(terminal: Terminal): void { |
18 | | - enableLigatures(terminal); |
| 33 | + this._terminal = terminal; |
| 34 | + this._characterJoinerId = enableLigatures(terminal, this._fallbackLigatures); |
19 | 35 | } |
20 | 36 |
|
21 | | - public dispose(): void {} |
| 37 | + public dispose(): void { |
| 38 | + if (this._characterJoinerId !== undefined) { |
| 39 | + this._terminal?.deregisterCharacterJoiner(this._characterJoinerId); |
| 40 | + this._characterJoinerId = undefined; |
| 41 | + } |
| 42 | + } |
22 | 43 | } |
23 | | - |
|
0 commit comments