Use a switch for color mode conditions

This commit is contained in:
Daniel
2019-11-10 00:29:50 -08:00
parent a2da8f9fbb
commit b13e9066bd
2 changed files with 45 additions and 32 deletions
@@ -280,17 +280,21 @@ export class RectangleRenderer {
if (fg & FgFlags.INVERSE) {
// Inverted color
rgba = this._colors.foreground.rgba;
} else if ((bg & Attributes.CM_MASK) === Attributes.CM_P16 || (bg & Attributes.CM_MASK) === Attributes.CM_P256) {
// 256 palette
rgba = this._colors.ansi[bg & Attributes.PCOLOR_MASK].rgba;
} else if (colorMode === Attributes.CM_RGB) {
// True color
// TODO: Use a switch instead?
rgba = (bg & Attributes.RGB_MASK) << 8;
} else {
// Default color
rgba = this._colors.background.rgba;
switch (colorMode) {
case Attributes.CM_P16:
case Attributes.CM_P256:
rgba = this._colors.ansi[bg & Attributes.PCOLOR_MASK].rgba;
break;
case Attributes.CM_RGB:
rgba = (bg & Attributes.RGB_MASK) << 8;
break;
case Attributes.CM_DEFAULT:
default:
rgba = this._colors.background.rgba;
}
}
if (vertices.attributes.length < offset + 4) {
vertices.attributes = expandFloat32Array(vertices.attributes, this._terminal.rows * this._terminal.cols * INDICES_PER_RECTANGLE);
}
@@ -299,7 +303,6 @@ export class RectangleRenderer {
const r = ((rgba >> 24) & 0xFF) / 255;
const g = ((rgba >> 16) & 0xFF) / 255;
const b = ((rgba >> 8 ) & 0xFF) / 255;
console.log(r, g, b);
this._addRectangle(vertices.attributes, offset, x1, y1, (endX - startX) * this._dimensions.scaledCellWidth, this._dimensions.scaledCellHeight, r, g, b, 1);
}
@@ -185,36 +185,46 @@ export class WebglCharAtlas implements IDisposable {
return TRANSPARENT_COLOR;
} else if (fg & FgFlags.INVERSE) {
return this._config.colors.foreground;
} else if (is256Color(bg)) {
return this._getColorFromAnsiIndex(bg & Attributes.PCOLOR_MASK);
} else if ((bg & Attributes.CM_MASK) === Attributes.CM_RGB) {
// TODO: Use a switch for the color mode?
// True color
const rgb = bg & Attributes.RGB_MASK;
const arr = AttributeData.toColorRGB(rgb);
// TODO: This object creation is slow
return {
rgba: rgb << 8,
css: `#${toPaddedHex(arr[0])}${toPaddedHex(arr[1])}${toPaddedHex(arr[2])}`
};
}
return this._config.colors.background;
const colorMode = bg & Attributes.CM_MASK;
switch (colorMode) {
case Attributes.CM_P16:
case Attributes.CM_P256:
return this._getColorFromAnsiIndex(bg & Attributes.PCOLOR_MASK);
case Attributes.CM_RGB:
const rgb = bg & Attributes.RGB_MASK;
const arr = AttributeData.toColorRGB(rgb);
// TODO: This object creation is slow
return {
rgba: rgb << 8,
css: `#${toPaddedHex(arr[0])}${toPaddedHex(arr[1])}${toPaddedHex(arr[2])}`
};
case Attributes.CM_DEFAULT:
default:
return this._config.colors.background;
}
}
private _getForegroundColor(fg: number): { css: string } {
// TODO: Just return the string value
if (fg & FgFlags.INVERSE) {
return this._config.colors.background;
} else if (is256Color(fg)) {
return this._getColorFromAnsiIndex(fg & Attributes.PCOLOR_MASK);
} else if ((fg & Attributes.CM_MASK) === Attributes.CM_RGB) {
// TODO: Use a switch for the color mode?
// TODO: True color
const rgb = fg & Attributes.RGB_MASK;
const arr = AttributeData.toColorRGB(rgb);
return { css: `#${toPaddedHex(arr[0])}${toPaddedHex(arr[1])}${toPaddedHex(arr[2])}` };
}
return this._config.colors.foreground;
const colorMode = fg & Attributes.CM_MASK;
switch (colorMode) {
case Attributes.CM_P16:
case Attributes.CM_P256:
return this._getColorFromAnsiIndex(fg & Attributes.PCOLOR_MASK);
case Attributes.CM_RGB:
const rgb = fg & Attributes.RGB_MASK;
const arr = AttributeData.toColorRGB(rgb);
return { css: `#${toPaddedHex(arr[0])}${toPaddedHex(arr[1])}${toPaddedHex(arr[2])}` };
case Attributes.CM_DEFAULT:
default:
return this._config.colors.foreground;
}
}
private _drawToCache(code: number, bg: number, fg: number): IRasterizedGlyph;