diff --git a/fixtures/typings-test/typings-test.ts b/fixtures/typings-test/typings-test.ts index 4718110d..6761dcd5 100644 --- a/fixtures/typings-test/typings-test.ts +++ b/fixtures/typings-test/typings-test.ts @@ -159,6 +159,7 @@ namespace methods_core { t.setOption('cursorBlink', true); t.setOption('debug', true); t.setOption('disableStdin', true); + t.setOption('enableBold', true); t.setOption('fontWeight', 'normal'); t.setOption('fontWeight', 'bold'); t.setOption('fontWeightBold', 'normal'); diff --git a/src/Interfaces.ts b/src/Interfaces.ts index 6d1c36d3..5237fa5b 100644 --- a/src/Interfaces.ts +++ b/src/Interfaces.ts @@ -137,6 +137,7 @@ export interface ITerminalOptions { cursorStyle?: string; debug?: boolean; disableStdin?: boolean; + enableBold?: boolean; fontSize?: number; fontFamily?: string; fontWeight?: FontWeight; diff --git a/src/Terminal.ts b/src/Terminal.ts index 044f5351..70b7deaa 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -72,6 +72,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = { cursorStyle: 'block', bellSound: BELL_SOUND, bellStyle: 'none', + enableBold: true, fontFamily: 'courier-new, courier, monospace', fontSize: 15, fontWeight: 'normal', @@ -424,11 +425,12 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT this.renderer.clear(); this.charMeasure.measure(this.options); break; + case 'enableBold': case 'letterSpacing': case 'lineHeight': case 'fontWeight': case 'fontWeightBold': - const didCharSizeChange = (key === 'fontWeight' || key === 'fontWeightBold'); + const didCharSizeChange = (key === 'fontWeight' || key === 'fontWeightBold' || key === 'enableBold'); // 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 977cbf52..bf952d06 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -230,7 +230,7 @@ export abstract class BaseRenderLayer implements IRenderLayer { colorIndex = fg + 2; } else { // If default color and bold - if (bold) { + if (bold && terminal.options.enableBold) { colorIndex = 1; } } @@ -251,6 +251,13 @@ export abstract class BaseRenderLayer implements IRenderLayer { this._ctx.globalAlpha = DIM_OPACITY; } + // Draw the non-bold version of the same color if bold is not enabled + if (bold && !terminal.options.enableBold) { + // Ignore default color as it's not touched above + if (colorIndex > 1) { + colorIndex -= 8; + } + } this._ctx.drawImage(this._charAtlas, code * charAtlasCellWidth, @@ -262,7 +269,7 @@ export abstract class BaseRenderLayer implements IRenderLayer { charAtlasCellWidth, this._scaledCharHeight); } else { - this._drawUncachedChar(terminal, char, width, fg, x, y, bold, dim); + this._drawUncachedChar(terminal, char, width, fg, x, y, bold && terminal.options.enableBold, dim); } // This draws the atlas (for debugging purposes) // this._ctx.clearRect(0, 0, this._canvas.width, this._canvas.height); diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 7c8612cf..7f19a502 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -8,6 +8,11 @@ */ declare module 'xterm' { + /** + * A string representing text font weight. + */ + export type FontWeight = 'normal' | 'bold' | 'bolder' | 'lighter' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'; + /** * An object containing start up options for the terminal. */ @@ -57,6 +62,16 @@ declare module 'xterm' { */ fontFamily?: string; + /** + * The font weight used to render non-bold text. + */ + fontWeight?: FontWeight; + + /** + * The font weight used to render bold text. + */ + fontWeightBold?: FontWeight; + /** * The spacing in whole pixels between characters.. */