2 * Copyright (c) 2017 The xterm.js authors. All rights reserved.
6 import { IRenderDimensions } from 'browser/renderer/Types';
7 import { BaseRenderLayer } from './BaseRenderLayer';
8 import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants';
9 import { is256Color } from 'browser/renderer/atlas/CharAtlasUtils';
10 import { IColorSet, ILinkifierEvent, ILinkifier } from 'browser/Types';
11 import { IBufferService, IOptionsService } from 'common/services/Services';
13 export class LinkRenderLayer extends BaseRenderLayer {
14 private _state: ILinkifierEvent | undefined;
17 container: HTMLElement,
21 linkifier: ILinkifier,
22 readonly bufferService: IBufferService,
23 readonly optionsService: IOptionsService
25 super(container, 'link', zIndex, true, colors, rendererId, bufferService, optionsService);
26 linkifier.onLinkHover(e => this._onLinkHover(e));
27 linkifier.onLinkLeave(e => this._onLinkLeave(e));
30 public resize(dim: IRenderDimensions): void {
32 // Resizing the canvas discards the contents of the canvas so clear state
33 this._state = undefined;
36 public reset(): void {
37 this._clearCurrentLink();
40 private _clearCurrentLink(): void {
42 this._clearCells(this._state.x1, this._state.y1, this._state.cols - this._state.x1, 1);
43 const middleRowCount = this._state.y2 - this._state.y1 - 1;
44 if (middleRowCount > 0) {
45 this._clearCells(0, this._state.y1 + 1, this._state.cols, middleRowCount);
47 this._clearCells(0, this._state.y2, this._state.x2, 1);
48 this._state = undefined;
52 private _onLinkHover(e: ILinkifierEvent): void {
53 if (e.fg === INVERTED_DEFAULT_COLOR) {
54 this._ctx.fillStyle = this._colors.background.css;
55 } else if (e.fg && is256Color(e.fg)) {
57 this._ctx.fillStyle = this._colors.ansi[e.fg].css;
59 this._ctx.fillStyle = this._colors.foreground.css;
64 this._fillBottomLineAtCells(e.x1, e.y1, e.x2 - e.x1);
67 this._fillBottomLineAtCells(e.x1, e.y1, e.cols - e.x1);
68 for (let y = e.y1 + 1; y < e.y2; y++) {
69 this._fillBottomLineAtCells(0, y, e.cols);
71 this._fillBottomLineAtCells(0, e.y2, e.x2);
76 private _onLinkLeave(e: ILinkifierEvent): void {
77 this._clearCurrentLink();