From fd4e9d8a1bcf2fa4e6b4f275d48725e7670c534e Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 2 Sep 2017 23:13:22 -0700 Subject: [PATCH] Fix graphical glitch wide chars would leave behind Wide chars now 'own' the character next to them and are entirely responsible for drawing and clean up --- src/renderer/BaseRenderLayer.ts | 5 +++++ src/renderer/ForegroundRenderLayer.ts | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index 912d351f..686a1d25 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -128,6 +128,11 @@ export abstract class BaseRenderLayer implements IRenderLayer { } protected drawChar(terminal: ITerminal, char: string, code: number, width: number, x: number, y: number, fg: number, underline: boolean = false): void { + // Clear the cell next to this character if it's wide + if (width === 2) { + this.clearCells(x + 1, y, 1, 1); + } + let colorIndex = 0; if (fg < 256) { colorIndex = fg + 1; diff --git a/src/renderer/ForegroundRenderLayer.ts b/src/renderer/ForegroundRenderLayer.ts index e8835dea..8ee81f02 100644 --- a/src/renderer/ForegroundRenderLayer.ts +++ b/src/renderer/ForegroundRenderLayer.ts @@ -48,6 +48,14 @@ export class ForegroundRenderLayer extends BaseRenderLayer { const code: number = charData[CHAR_DATA_CODE_INDEX]; const char: string = charData[CHAR_DATA_CHAR_INDEX]; const attr: number = charData[CHAR_DATA_ATTR_INDEX]; + const width: number = charData[CHAR_DATA_WIDTH_INDEX]; + + // The character to the left is a wide character, drawing is owned by + // the char at x-1 + if (width === 0) { + this._state.cache[x][y] = null; + continue; + } // Skip rendering if the character is identical const state = this._state.cache[x][y]; @@ -59,7 +67,7 @@ export class ForegroundRenderLayer extends BaseRenderLayer { // Clear the old character if present if (state && state[CHAR_DATA_CODE_INDEX] !== 32 /*' '*/) { - this.clearCells(x, y, 1, 1); + this.clearChar(x, y); } this._state.cache[x][y] = charData; @@ -102,11 +110,20 @@ export class ForegroundRenderLayer extends BaseRenderLayer { this.drawBottomLineAtCell(x, y); } - const width: number = charData[CHAR_DATA_WIDTH_INDEX]; this.drawChar(terminal, char, code, width, x, y, fg); this._ctx.restore(); } } } + + private clearChar(x: number, y: number): void { + let colsToClear = 1; + // Clear the adjacent character if it was wide + const state = this._state.cache[x][y]; + if (state && state[CHAR_DATA_WIDTH_INDEX] === 2) { + colsToClear = 2; + } + this.clearCells(x, y, colsToClear, 1); + } }