From a622b97a9454324e8bb6aa5f1b4baa6de591ea62 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 13 Oct 2017 13:13:38 -0700 Subject: [PATCH 1/3] Support enableBold option --- src/Interfaces.ts | 1 + src/Terminal.ts | 2 ++ src/renderer/BaseRenderLayer.ts | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Interfaces.ts b/src/Interfaces.ts index 2c77e8d3f..c6faf3737 100644 --- a/src/Interfaces.ts +++ b/src/Interfaces.ts @@ -135,6 +135,7 @@ export interface ITerminalOptions { cursorStyle?: string; debug?: boolean; disableStdin?: boolean; + enableBold?: boolean; fontSize?: number; fontFamily?: string; geometry?: [number, number]; diff --git a/src/Terminal.ts b/src/Terminal.ts index 8486f2650..da4bdc54f 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -77,6 +77,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = { cursorStyle: 'block', bellSound: BellSound, bellStyle: 'none', + enableBold: true, fontFamily: 'courier-new, courier, monospace', fontSize: 15, lineHeight: 1.0, @@ -410,6 +411,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.renderer.clear(); this.charMeasure.measure(this.options); break; + case 'enableBold': case 'lineHeight': // When the font changes the size of the cells may change which requires a renderer clear this.renderer.clear(); diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index fa1846b60..232a58f25 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -230,14 +230,14 @@ export abstract class BaseRenderLayer implements IRenderLayer { colorIndex = fg + 2; } else { // If default color and bold - if (bold) { + if (bold && terminal.options.enableBold) { colorIndex = 1; } } const isAscii = code < 256; // A color is basic if it is one of the standard normal or bold weight // colors of the characters held in the char atlas. Note that this excludes - // the normal weight light color characters + // the normal weight _light_ color characters. const isBasicColor = (colorIndex > 1 && fg < 16) && (fg < 8 || bold); const isDefaultColor = fg >= 256; const isDefaultBackground = bg >= 256; @@ -245,10 +245,22 @@ export abstract class BaseRenderLayer implements IRenderLayer { // ImageBitmap's draw about twice as fast as from a canvas const charAtlasCellWidth = this._scaledCharWidth + CHAR_ATLAS_CELL_SPACING; const charAtlasCellHeight = this._scaledCharHeight + CHAR_ATLAS_CELL_SPACING; + // Apply alpha to dim the character if (dim) { this._ctx.globalAlpha = DIM_OPACITY; } + + // Draw the non-bold version of the same color if bold is not enabled + if (bold && !terminal.options.enableBold) { + if (colorIndex === 1) { + // The default color + colorIndex = 0; + } else { + colorIndex -= 8; + } + } + this._ctx.drawImage(this._charAtlas, code * charAtlasCellWidth, colorIndex * charAtlasCellHeight, charAtlasCellWidth, this._scaledCharHeight, x * this._scaledCharWidth, y * this._scaledLineHeight + this._scaledLineDrawY, charAtlasCellWidth, this._scaledCharHeight); @@ -274,7 +286,7 @@ export abstract class BaseRenderLayer implements IRenderLayer { private _drawUncachedChar(terminal: ITerminal, char: string, width: number, fg: number, x: number, y: number, bold: boolean, dim: boolean): void { this._ctx.save(); this._ctx.font = `${terminal.options.fontSize * window.devicePixelRatio}px ${terminal.options.fontFamily}`; - if (bold) { + if (bold && terminal.options.enableBold) { this._ctx.font = `bold ${this._ctx.font}`; } this._ctx.textBaseline = 'top'; From a1fcafd50ce86a12340c95a4a824a4df3bbe7ab2 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 13 Oct 2017 13:20:22 -0700 Subject: [PATCH 2/3] Fix default color with bold disabled --- src/renderer/BaseRenderLayer.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index 232a58f25..58517dbc2 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -253,10 +253,8 @@ export abstract class BaseRenderLayer implements IRenderLayer { // Draw the non-bold version of the same color if bold is not enabled if (bold && !terminal.options.enableBold) { - if (colorIndex === 1) { - // The default color - colorIndex = 0; - } else { + // Ignore default color as it's not touched above + if (colorIndex > 1) { colorIndex -= 8; } } From 899929afc69fad8cfcee277e80994b11e05bd812 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 13 Oct 2017 13:30:12 -0700 Subject: [PATCH 3/3] Add enableBold typings --- fixtures/typings-test/typings-test.ts | 2 ++ typings/xterm.d.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fixtures/typings-test/typings-test.ts b/fixtures/typings-test/typings-test.ts index 928ca2389..9b8e4da27 100644 --- a/fixtures/typings-test/typings-test.ts +++ b/fixtures/typings-test/typings-test.ts @@ -140,6 +140,7 @@ namespace methods_core { const r18: (data: string) => void = t.getOption('handler'); const r19: string = t.getOption('bellSound'); const r20: string = t.getOption('bellStyle'); + const r21: boolean = t.getOption('enableBold'); } { const t: Terminal = new Terminal(); @@ -152,6 +153,7 @@ namespace methods_core { t.setOption('cursorBlink', true); t.setOption('debug', true); t.setOption('disableStdin', true); + t.setOption('enableBold', true); t.setOption('popOnBell', true); t.setOption('screenKeys', true); t.setOption('useFlowControl', true); diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index de2a261b3..d1fd14de9 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -41,6 +41,11 @@ interface ITerminalOptions { */ disableStdin?: boolean; + /** + * Whether to enable the rendering of bold text. + */ + enableBold?: boolean; + /** * The font size used to render text. */ @@ -397,7 +402,7 @@ declare module 'xterm' { * Retrieves an option's value from the terminal. * @param key The option key. */ - getOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell'): boolean; + getOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell'): boolean; /** * Retrieves an option's value from the terminal. * @param key The option key. @@ -447,7 +452,7 @@ declare module 'xterm' { * @param key The option key. * @param value The option value. */ - setOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell', value: boolean): void; + setOption(key: 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'debug' | 'disableStdin' | 'enableBold' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell', value: boolean): void; /** * Sets an option on the terminal. * @param key The option key.