Skip to content

Commit

Permalink
Separate bright and bold
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Apr 20, 2018
1 parent a3ce881 commit ef9873b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/renderer/BaseRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export abstract class BaseRenderLayer implements IRenderLayer {
protected drawChar(terminal: ITerminal, char: string, code: number, width: number, x: number, y: number, fg: number, bg: number, bold: boolean, dim: boolean): void {
let colorIndex = 0;
if (fg < 256) {
colorIndex = fg + 2;
colorIndex = fg + 2 + (bold && terminal.options.enableBold ? 16 : 0);
} else {
// If default color and bold
if (bold && terminal.options.enableBold) {
Expand Down Expand Up @@ -273,7 +273,7 @@ export abstract class BaseRenderLayer implements IRenderLayer {
if (bold && !terminal.options.enableBold) {
// Ignore default color as it's not touched above
if (colorIndex > 1) {
colorIndex -= 8;
colorIndex -= 16;
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/renderer/TextRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ export class TextRenderLayer extends BaseRenderLayer {
this._ctx.save();
if (flags & FLAGS.BOLD) {
this._ctx.font = this._getFont(terminal, true);
// Convert the FG color to the bold variant
if (fg < 8) {
fg += 8;
}
}

if (flags & FLAGS.UNDERLINE) {
Expand Down
22 changes: 17 additions & 5 deletions src/shared/atlas/CharAtlasGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function generateCharAtlas(context: Window, canvasFactory: (width: number
const cellHeight = config.scaledCharHeight + CHAR_ATLAS_CELL_SPACING;
const canvas = canvasFactory(
/*255 ascii chars*/255 * cellWidth,
(/*default+default bold*/2 + /*0-15*/16) * cellHeight
(/*default+default bold*/2 + /*0-15*/16 + /*0-15 bold*/16) * cellHeight
);
const ctx = canvas.getContext('2d', {alpha: config.allowTransparency});

Expand Down Expand Up @@ -64,10 +64,6 @@ export function generateCharAtlas(context: Window, canvasFactory: (width: number
// Colors 0-15
ctx.font = getFont(config.fontWeight, config);
for (let colorIndex = 0; colorIndex < 16; colorIndex++) {
// colors 8-15 are bold
if (colorIndex === 8) {
ctx.font = getFont(config.fontWeightBold, config);
}
const y = (colorIndex + 2) * cellHeight;
// Draw ascii characters
for (let i = 0; i < 256; i++) {
Expand All @@ -80,6 +76,22 @@ export function generateCharAtlas(context: Window, canvasFactory: (width: number
ctx.restore();
}
}

// Colors 0-15 bold
ctx.font = getFont(config.fontWeightBold, config);
for (let colorIndex = 0; colorIndex < 16; colorIndex++) {
const y = (colorIndex + 2 + 16) * cellHeight;
// Draw ascii characters
for (let i = 0; i < 256; i++) {
ctx.save();
ctx.beginPath();
ctx.rect(i * cellWidth, y, cellWidth, cellHeight);
ctx.clip();
ctx.fillStyle = config.colors.ansi[colorIndex].css;
ctx.fillText(String.fromCharCode(i), i * cellWidth, y);
ctx.restore();
}
}
ctx.restore();

// Support is patchy for createImageBitmap at the moment, pass a canvas back
Expand Down

0 comments on commit ef9873b

Please sign in to comment.