Use the proper bg/fg colors for inverse attr

This commit is contained in:
Daniel Imms
2017-09-01 21:09:07 -07:00
parent 1f444b1913
commit 70764a74af
3 changed files with 13 additions and 10 deletions
+3 -4
View File
@@ -3,7 +3,7 @@ import { IBuffer, ICharMeasure, ITerminal } from '../Interfaces';
import { CHAR_DATA_ATTR_INDEX } from '../Buffer';
import { GridCache } from './GridCache';
import { FLAGS } from './Types';
import { BaseRenderLayer } from './BaseRenderLayer';
import { BaseRenderLayer, INVERTED_DEFAULT_COLOR } from './BaseRenderLayer';
export class BackgroundRenderLayer extends BaseRenderLayer {
private _state: GridCache<number>;
@@ -39,9 +39,8 @@ export class BackgroundRenderLayer extends BaseRenderLayer {
// If inverse flag is on, the background should become the foreground.
if (flags & FLAGS.INVERSE) {
bg = (attr >> 9) & 0x1ff;
// TODO: Is this case still needed
if (bg === 257) {
bg = 15;
bg = INVERTED_DEFAULT_COLOR;
}
}
@@ -50,7 +49,7 @@ export class BackgroundRenderLayer extends BaseRenderLayer {
if (needsRefresh) {
if (bg < 256) {
this._ctx.save();
this._ctx.fillStyle = this.colors.ansi[bg];
this._ctx.fillStyle = (bg === INVERTED_DEFAULT_COLOR ? this.colors.foreground : this.colors.ansi[bg]);
this.fillCells(x, y, 1, 1);
this._ctx.restore();
this._state.cache[x][y] = bg;
+7 -3
View File
@@ -2,6 +2,8 @@ import { IRenderLayer, IColorSet } from './Interfaces';
import { ITerminal, ITerminalOptions } from '../Interfaces';
import { acquireCharAtlas } from '../utils/CharAtlas';
export const INVERTED_DEFAULT_COLOR = -1;
export abstract class BaseRenderLayer implements IRenderLayer {
private _canvas: HTMLCanvasElement;
protected _ctx: CanvasRenderingContext2D;
@@ -102,11 +104,13 @@ export abstract class BaseRenderLayer implements IRenderLayer {
this._ctx.font = `${terminal.options.fontSize * window.devicePixelRatio}px ${terminal.options.fontFamily}`;
this._ctx.textBaseline = 'top';
// 256 color support
if (fg < 256) {
if (fg === INVERTED_DEFAULT_COLOR) {
this._ctx.fillStyle = this.colors.background;
} else if (fg < 256) {
// 256 color support
this._ctx.fillStyle = this.colors.ansi[fg];
} else {
this._ctx.fillStyle = '#ffffff';
this._ctx.fillStyle = this.colors.foreground;
}
// TODO: Do we care about width for rendering wide chars?
+3 -3
View File
@@ -4,7 +4,7 @@ import { CHAR_DATA_ATTR_INDEX, CHAR_DATA_CODE_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_
import { FLAGS } from './Types';
import { GridCache } from './GridCache';
import { CharData } from '../Types';
import { BaseRenderLayer } from './BaseRenderLayer';
import { BaseRenderLayer, INVERTED_DEFAULT_COLOR } from './BaseRenderLayer';
export class ForegroundRenderLayer extends BaseRenderLayer {
private _state: GridCache<CharData>;
@@ -74,8 +74,8 @@ export class ForegroundRenderLayer extends BaseRenderLayer {
if (flags & FLAGS.INVERSE) {
fg = attr & 0x1ff;
// TODO: Is this case still needed
if (fg === 257) {
fg = 0;
if (fg === 256) {
fg = INVERTED_DEFAULT_COLOR;
}
}