From f8a9eb1db6e8a5fd8a0a650aa0fc96a995a81cf5 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 29 Jul 2022 10:18:21 -0700 Subject: [PATCH 1/3] Support fallback ligatures and correctly dispose of char joiner --- addons/xterm-addon-ligatures/README.md | 11 ++++---- .../src/LigaturesAddon.ts | 28 ++++++++++++++++--- addons/xterm-addon-ligatures/src/Types.d.ts | 8 ++++++ addons/xterm-addon-ligatures/src/index.ts | 24 ++++++++++++---- .../typings/xterm-addon-ligatures.d.ts | 26 ++++++++++++++++- 5 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 addons/xterm-addon-ligatures/src/Types.d.ts diff --git a/addons/xterm-addon-ligatures/README.md b/addons/xterm-addon-ligatures/README.md index 8f869d73cd..fad2a7efab 100644 --- a/addons/xterm-addon-ligatures/README.md +++ b/addons/xterm-addon-ligatures/README.md @@ -33,15 +33,16 @@ This package locates the font file on disk for the font currently in use by the 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]). +### 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 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 +* [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 [xterm.js]: https://github.com/xtermjs/xterm.js [Electron]: https://electronjs.org/ diff --git a/addons/xterm-addon-ligatures/src/LigaturesAddon.ts b/addons/xterm-addon-ligatures/src/LigaturesAddon.ts index c19bf2f819..c4586b3890 100644 --- a/addons/xterm-addon-ligatures/src/LigaturesAddon.ts +++ b/addons/xterm-addon-ligatures/src/LigaturesAddon.ts @@ -5,6 +5,7 @@ import { Terminal } from 'xterm'; import { enableLigatures } from '.'; +import { ILigatureOptions } from './Types'; export interface ITerminalAddon { activate(terminal: Terminal): void; @@ -12,12 +13,31 @@ export interface ITerminalAddon { } export class LigaturesAddon implements ITerminalAddon { - constructor() {} + private readonly _fallbackLigatures: string[]; + + private _terminal: Terminal | undefined; + private _characterJoinerId: number | undefined; + + constructor(options?: Partial) { + this._fallbackLigatures = (options?.fallbackLigatures || [ + '<--', '<---', '<<-', '<-', '->', '->>', '-->', '--->', + '<==', '<===', '<<=', '<=', '=>', '=>>', '==>', '===>', '>=', '>>=', + '<->', '<-->', '<--->', '<---->', '<=>', '<==>', '<===>', '<====>', '-------->', + '<~~', '<~', '~>', '~~>', '::', ':::', '==', '!=', '===', '!==', + ':=', ':-', ':+', '<*', '<*>', '*>', '<|', '<|>', '|>', '+:', '-:', '=:', ':>', + '++', '+++', ' ---> + * <== <=== <<= <= => =>> ==> ===> >= >>= + * <-> <--> <---> <----> <=> <==> <===> <====> --------> + * <~~ <~ ~> ~~> :: ::: == != === !== + * := :- :+ <* <*> *> <| <|> |> +: -: =: :> + * ++ +++