diff --git a/addons/xterm-addon-canvas/src/TextRenderLayer.ts b/addons/xterm-addon-canvas/src/TextRenderLayer.ts index d44e4b81..625bcce9 100644 --- a/addons/xterm-addon-canvas/src/TextRenderLayer.ts +++ b/addons/xterm-addon-canvas/src/TextRenderLayer.ts @@ -14,6 +14,7 @@ import { CellData } from 'common/buffer/CellData'; import { IOptionsService, IBufferService, IDecorationService } from 'common/services/Services'; import { ICharacterJoinerService } from 'browser/services/Services'; import { JoinedCellData } from 'browser/services/CharacterJoinerService'; +import { color, css } from 'common/Color'; /** * This CharData looks like a null character, which will forc a clear and render @@ -177,6 +178,12 @@ export class TextRenderLayer extends BaseRenderLayer { nextFillStyle = this._colors.ansi[cell.getBgColor()].css; } + // Apply dim to the background, this is relatively slow as the CSS is re-parsed but dim is + // rarely used + if (nextFillStyle && cell.isDim()) { + nextFillStyle = color.multiplyOpacity(css.toColor(nextFillStyle), 0.5).css; + } + // Get any decoration foreground/background overrides, this must be fetched before the early // exist but applied after inverse let isTop = false; diff --git a/addons/xterm-addon-canvas/src/atlas/DynamicCharAtlas.ts b/addons/xterm-addon-canvas/src/atlas/DynamicCharAtlas.ts index f5fc2c99..3098538d 100644 --- a/addons/xterm-addon-canvas/src/atlas/DynamicCharAtlas.ts +++ b/addons/xterm-addon-canvas/src/atlas/DynamicCharAtlas.ts @@ -225,13 +225,18 @@ export class DynamicCharAtlas extends BaseCharAtlas { // around the anti-aliased edges of the glyph, and it would look too dark. return TRANSPARENT_COLOR; } + let result: IColor; if (glyph.bg === INVERTED_DEFAULT_COLOR) { - return this._config.colors.foreground; + result = this._config.colors.foreground; + } else if (glyph.bg < 256) { + result = this._getColorFromAnsiIndex(glyph.bg); + } else { + result = this._config.colors.background; } - if (glyph.bg < 256) { - return this._getColorFromAnsiIndex(glyph.bg); + if (glyph.dim) { + result = color.blend(this._config.colors.background, color.multiplyOpacity(result, 0.5)); } - return this._config.colors.background; + return result; } private _getForegroundColor(glyph: IGlyphIdentifier): IColor { @@ -274,6 +279,7 @@ export class DynamicCharAtlas extends BaseCharAtlas { if (glyph.dim) { this._tmpCtx.globalAlpha = DIM_OPACITY; } + // Draw the character this._tmpCtx.fillText(glyph.chars, 0, this._config.scaledCharHeight); diff --git a/addons/xterm-addon-ligatures/README.md b/addons/xterm-addon-ligatures/README.md index 8f869d73..fad2a7ef 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 c19bf2f8..c4586b38 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[]; - public activate(terminal: Terminal): void { - enableLigatures(terminal); + private _terminal: Terminal | undefined; + private _characterJoinerId: number | undefined; + + constructor(options?: Partial) { + this._fallbackLigatures = (options?.fallbackLigatures || [ + '<--', '<---', '<<-', '<-', '->', '->>', '-->', '--->', + '<==', '<===', '<<=', '<=', '=>', '=>>', '==>', '===>', '>=', '>>=', + '<->', '<-->', '<--->', '<---->', '<=>', '<==>', '<===>', '<====>', '-------->', + '<~~', '<~', '~>', '~~>', '::', ':::', '==', '!=', '===', '!==', + ':=', ':-', ':+', '<*', '<*>', '*>', '<|', '<|>', '|>', '+:', '-:', '=:', ':>', + '++', '+++', ' ---> + * <== <=== <<= <= => =>> ==> ===> >= >>= + * <-> <--> <---> <----> <=> <==> <===> <====> --------> + * <~~ <~ ~> ~~> :: ::: == != === !== + * := :- :+ <* <*> *> <| <|> |> +: -: =: :> + * ++ +++