Skip to content

Commit

Permalink
Merge b79d73d into 739723f
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed May 19, 2019
2 parents 739723f + b79d73d commit 952927c
Show file tree
Hide file tree
Showing 36 changed files with 3,808 additions and 7 deletions.
8 changes: 6 additions & 2 deletions demo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ function initOptions(term: TerminalType): void {
bellSound: null,
bellStyle: ['none', 'sound'],
cursorStyle: ['block', 'underline', 'bar'],
experimentalCharAtlas: ['none', 'static', 'dynamic'],
experimentalCharAtlas: ['none', 'static', 'dynamic', 'webgl'],
fontFamily: null,
fontWeight: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
fontWeightBold: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
rendererType: ['dom', 'canvas']
rendererType: ['dom', 'canvas', 'webgl']
};
const options = Object.keys((<any>term)._core.options);
const booleanOptions = [];
Expand Down Expand Up @@ -283,6 +283,10 @@ function initOptions(term: TerminalType): void {
const input = <HTMLInputElement>document.getElementById(`opt-${o}`);
addDomListener(input, 'change', () => {
console.log('change', o, input.value);
if (o === 'rendererType' && input.value === 'webgl') {
term.setOption('experimentalCharAtlas', 'webgl');
setTimeout(() => (<HTMLSelectElement>document.getElementById(`opt-experimentalCharAtlas`)).value = 'webgl', 0);
}
term.setOption(o, input.value);
});
});
Expand Down
10 changes: 8 additions & 2 deletions src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,16 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II

}

public setRenderer(renderer: IRenderer): void {
this._renderCoordinator.setRenderer(renderer);
// this._renderCoordinator.onOptionsChanged();
this.refresh(0, this.rows - 1);
}

private _createRenderer(): IRenderer {
switch (this.options.rendererType) {
case 'canvas': return new Renderer(this, this._colorManager.colors); break;
case 'dom': return new DomRenderer(this, this._colorManager.colors); break;
case 'canvas': return new Renderer(this, this._colorManager.colors);
case 'dom': return new DomRenderer(this, this._colorManager.colors);
default: throw new Error(`Unrecognized rendererType "${this.options.rendererType}"`);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export class TestTerminal extends Terminal {
}

export class MockTerminal implements ITerminal {
setRenderer(renderer: any): void {
throw new Error('Method not implemented.');
}
onCursorMove: IEvent<void>;
onLineFeed: IEvent<void>;
onSelectionChange: IEvent<void>;
Expand Down
2 changes: 2 additions & 0 deletions src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export interface IPublicTerminal extends IDisposable, IEventEmitter {
setOption(key: string, value: any): void;
refresh(start: number, end: number): void;
reset(): void;
setRenderer(renderer: any): void;
}

export interface IBufferAccessor {
Expand Down Expand Up @@ -358,6 +359,7 @@ export interface IBufferSet {

export interface ISelectionManager {
selectionText: string;
hasSelection: boolean;
selectionStart: [number, number];
selectionEnd: [number, number];

Expand Down
32 changes: 31 additions & 1 deletion src/core/buffer/BufferLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
* @license MIT
*/

import { CharData, IBufferLine, ICellData, IColorRGB, IAttributeData } from '../Types';
import { stringFromCodePoint } from '../input/TextDecoder';
import { DEFAULT_COLOR } from '../../common/Types';

export const DEFAULT_ATTR = (0 << 18) | (DEFAULT_COLOR << 9) | (256 << 0);

// TODO: This is duplicated from renderer, should be removed after chardata workaround is fixed
export const enum FLAGS {
BOLD = 1,
UNDERLINE = 2,
BLINK = 4,
INVERSE = 8,
INVISIBLE = 16,
DIM = 32,
ITALIC = 64
}

export const CHAR_DATA_ATTR_INDEX = 0;
export const CHAR_DATA_CHAR_INDEX = 1;
export const CHAR_DATA_WIDTH_INDEX = 2;
Expand Down Expand Up @@ -345,8 +357,26 @@ export class BufferLine implements IBufferLine {
public get(index: number): CharData {
const content = this._data[index * CELL_SIZE + Cell.CONTENT];
const cp = content & Content.CODEPOINT_MASK;

// TODO: Need to move WebGL over to the new system and remove this block
const cell = new CellData();
this.loadCell(index, cell);
const oldBg = cell.getBgColor() === -1 ? 256 : cell.getBgColor();
const oldFg = cell.getFgColor() === -1 ? 256 : cell.getFgColor();
const oldAttr =
(cell.isBold() ? FLAGS.BOLD : 0) |
(cell.isUnderline() ? FLAGS.UNDERLINE : 0) |
(cell.isBlink() ? FLAGS.BLINK : 0) |
(cell.isInverse() ? FLAGS.INVERSE : 0) |
(cell.isDim() ? FLAGS.DIM : 0) |
(cell.isItalic() ? FLAGS.ITALIC : 0);
const attrCompat =
oldBg |
(oldFg << 9) |
(oldAttr << 18);

return [
this._data[index * CELL_SIZE + Cell.FG],
attrCompat,
(content & Content.IS_COMBINED_MASK)
? this._combined[index]
: (cp) ? stringFromCodePoint(cp) : '',
Expand Down
8 changes: 8 additions & 0 deletions src/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Terminal as TerminalCore } from '../Terminal';
import * as Strings from '../Strings';
import { IEvent } from '../common/EventEmitter2';
import { AddonManager } from './AddonManager';
import { WebglRendererAddon } from '../renderer/webgl/WebglRendererAddon';

export class Terminal implements ITerminalApi {
private _core: ITerminal;
Expand All @@ -31,6 +32,7 @@ export class Terminal implements ITerminalApi {
public get onResize(): IEvent<{ cols: number, rows: number }> { return this._core.onResize; }

public get element(): HTMLElement { return this._core.element; }
public get screenElement(): HTMLElement { return this._core.screenElement; }
public get textarea(): HTMLTextAreaElement { return this._core.textarea; }
public get rows(): number { return this._core.rows; }
public get cols(): number { return this._core.cols; }
Expand Down Expand Up @@ -183,6 +185,12 @@ export class Terminal implements ITerminalApi {
public loadAddon(addon: ITerminalAddon): void {
return this._addonManager.loadAddon(this, addon);
}
public setRenderer(renderer: any): void {
this._core.setRenderer(renderer);
}
public loadWebgl(preserveDrawingBuffer?: boolean): void {
this.loadAddon(new WebglRendererAddon(preserveDrawingBuffer));
}
public static get strings(): ILocalizableStrings {
return Strings;
}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/LinkRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class LinkRenderLayer extends BaseRenderLayer {

constructor(container: HTMLElement, zIndex: number, colors: IColorSet, terminal: ILinkifierAccessor) {
super(container, 'link', zIndex, true, colors);
// TODO: Need to expose link-related renderer API
terminal.linkifier.onLinkHover(e => this._onLinkHover(e));
terminal.linkifier.onLinkLeave(e => this._onLinkLeave(e));
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/atlas/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface IGlyphIdentifier {
}

export interface ICharAtlasConfig {
type: 'none' | 'static' | 'dynamic';
type: 'none' | 'static' | 'dynamic' | 'webgl';
devicePixelRatio: number;
fontSize: number;
fontFamily: string;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/dom/DomRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class DomRenderer extends Disposable implements IRenderer {
actualCellHeight: null
};
this._updateDimensions();
this._injectCss();

this._rowFactory = new DomRendererRowFactory(_terminal.options, document);

Expand Down
14 changes: 14 additions & 0 deletions src/renderer/webgl/ColorUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @license MIT
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
*/

import { IColor } from 'xterm';

export function getLuminance(color: IColor): number {
// Coefficients taken from: https://www.w3.org/TR/AERT/#color-contrast
const r = color.rgba >> 24 & 0xff;
const g = color.rgba >> 16 & 0xff;
const b = color.rgba >> 8 & 0xff;
return (0.299 * r + 0.587 * g + 0.114 * b) / 255;
}
Loading

0 comments on commit 952927c

Please sign in to comment.