Support enableBold option

This commit is contained in:
Daniel Imms
2017-10-13 13:13:38 -07:00
parent c1ec68091a
commit a622b97a94
3 changed files with 18 additions and 3 deletions
+1
View File
@@ -135,6 +135,7 @@ export interface ITerminalOptions {
cursorStyle?: string; cursorStyle?: string;
debug?: boolean; debug?: boolean;
disableStdin?: boolean; disableStdin?: boolean;
enableBold?: boolean;
fontSize?: number; fontSize?: number;
fontFamily?: string; fontFamily?: string;
geometry?: [number, number]; geometry?: [number, number];
+2
View File
@@ -77,6 +77,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = {
cursorStyle: 'block', cursorStyle: 'block',
bellSound: BellSound, bellSound: BellSound,
bellStyle: 'none', bellStyle: 'none',
enableBold: true,
fontFamily: 'courier-new, courier, monospace', fontFamily: 'courier-new, courier, monospace',
fontSize: 15, fontSize: 15,
lineHeight: 1.0, lineHeight: 1.0,
@@ -410,6 +411,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
this.renderer.clear(); this.renderer.clear();
this.charMeasure.measure(this.options); this.charMeasure.measure(this.options);
break; break;
case 'enableBold':
case 'lineHeight': case 'lineHeight':
// When the font changes the size of the cells may change which requires a renderer clear // When the font changes the size of the cells may change which requires a renderer clear
this.renderer.clear(); this.renderer.clear();
+15 -3
View File
@@ -230,14 +230,14 @@ export abstract class BaseRenderLayer implements IRenderLayer {
colorIndex = fg + 2; colorIndex = fg + 2;
} else { } else {
// If default color and bold // If default color and bold
if (bold) { if (bold && terminal.options.enableBold) {
colorIndex = 1; colorIndex = 1;
} }
} }
const isAscii = code < 256; const isAscii = code < 256;
// A color is basic if it is one of the standard normal or bold weight // 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 // 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 isBasicColor = (colorIndex > 1 && fg < 16) && (fg < 8 || bold);
const isDefaultColor = fg >= 256; const isDefaultColor = fg >= 256;
const isDefaultBackground = bg >= 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 // ImageBitmap's draw about twice as fast as from a canvas
const charAtlasCellWidth = this._scaledCharWidth + CHAR_ATLAS_CELL_SPACING; const charAtlasCellWidth = this._scaledCharWidth + CHAR_ATLAS_CELL_SPACING;
const charAtlasCellHeight = this._scaledCharHeight + CHAR_ATLAS_CELL_SPACING; const charAtlasCellHeight = this._scaledCharHeight + CHAR_ATLAS_CELL_SPACING;
// Apply alpha to dim the character // Apply alpha to dim the character
if (dim) { if (dim) {
this._ctx.globalAlpha = DIM_OPACITY; 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, this._ctx.drawImage(this._charAtlas,
code * charAtlasCellWidth, colorIndex * charAtlasCellHeight, charAtlasCellWidth, this._scaledCharHeight, code * charAtlasCellWidth, colorIndex * charAtlasCellHeight, charAtlasCellWidth, this._scaledCharHeight,
x * this._scaledCharWidth, y * this._scaledLineHeight + this._scaledLineDrawY, 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 { private _drawUncachedChar(terminal: ITerminal, char: string, width: number, fg: number, x: number, y: number, bold: boolean, dim: boolean): void {
this._ctx.save(); this._ctx.save();
this._ctx.font = `${terminal.options.fontSize * window.devicePixelRatio}px ${terminal.options.fontFamily}`; 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.font = `bold ${this._ctx.font}`;
} }
this._ctx.textBaseline = 'top'; this._ctx.textBaseline = 'top';