From 9d4beb024a506552328741392fc280b4d9c1ba90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Thu, 29 Nov 2018 22:11:38 +0100 Subject: [PATCH] keep whitespace chars --- src/Buffer.ts | 8 ++++---- src/BufferLine.ts | 14 +++++++------- src/Terminal.integration.ts | 4 ++-- src/renderer/TextRenderLayer.ts | 6 +++--- src/renderer/dom/DomRendererRowFactory.ts | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Buffer.ts b/src/Buffer.ts index f9eed90f..07a5442c 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -17,14 +17,14 @@ export const CHAR_DATA_WIDTH_INDEX = 2; export const CHAR_DATA_CODE_INDEX = 3; export const MAX_BUFFER_SIZE = 4294967295; // 2^32 - 1 -// export const NULL_CELL_CHAR = ' '; -// export const NULL_CELL_WIDTH = 1; -// export const NULL_CELL_CODE = 32; - export const NULL_CELL_CHAR = ''; export const NULL_CELL_WIDTH = 1; export const NULL_CELL_CODE = 0; +export const WHITESPACE_CELL_CHAR = ' '; +export const WHITESPACE_CELL_WIDTH = 1; +export const WHITESPACE_CELL_CODE = 32; + /** * This class represents a terminal buffer (an internal state of the terminal), where the * following information is stored (in high-level): diff --git a/src/BufferLine.ts b/src/BufferLine.ts index 53a194c5..5a462d27 100644 --- a/src/BufferLine.ts +++ b/src/BufferLine.ts @@ -3,7 +3,7 @@ * @license MIT */ import { CharData, IBufferLine } from './Types'; -import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX } from './Buffer'; +import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, WHITESPACE_CELL_CHAR } from './Buffer'; /** * Class representing a terminal line. @@ -123,7 +123,7 @@ export class BufferLine implements IBufferLine { } let result = ''; while (startCol < length) { - result += this.get(startCol)[CHAR_DATA_CHAR_INDEX] || ' '; + result += this.get(startCol)[CHAR_DATA_CHAR_INDEX] || WHITESPACE_CELL_CHAR; startCol += this.get(startCol)[CHAR_DATA_WIDTH_INDEX] || 1; } return result; @@ -141,7 +141,7 @@ const enum Cell { } /** single vs. combined char distinction */ -const COMBINED = 0x80000000; +const IS_COMBINED_BIT_MASK = 0x80000000; /** * Typed array based bufferline implementation. @@ -177,11 +177,11 @@ export class BufferLineTypedArray implements IBufferLine { const stringData = this._data[index * CELL_SIZE + Cell.STRING]; return [ this._data[index * CELL_SIZE + Cell.FLAGS], - (stringData & COMBINED) + (stringData & IS_COMBINED_BIT_MASK) ? this._combined[index] : (stringData) ? String.fromCharCode(stringData) : '', this._data[index * CELL_SIZE + Cell.WIDTH], - (stringData & COMBINED) + (stringData & IS_COMBINED_BIT_MASK) ? this._combined[index].charCodeAt(this._combined[index].length - 1) : stringData ]; @@ -191,7 +191,7 @@ export class BufferLineTypedArray implements IBufferLine { this._data[index * CELL_SIZE + Cell.FLAGS] = value[0]; if (value[1].length > 1) { this._combined[index] = value[1]; - this._data[index * CELL_SIZE + Cell.STRING] = index | COMBINED; + this._data[index * CELL_SIZE + Cell.STRING] = index | IS_COMBINED_BIT_MASK; } else { this._data[index * CELL_SIZE + Cell.STRING] = value[1].charCodeAt(0); } @@ -320,7 +320,7 @@ export class BufferLineTypedArray implements IBufferLine { let result = ''; while (startCol < length) { const stringData = this._data[startCol * CELL_SIZE + Cell.STRING]; - result += (stringData & COMBINED) ? this._combined[startCol] : (stringData) ? String.fromCharCode(stringData) : ' '; + result += (stringData & IS_COMBINED_BIT_MASK) ? this._combined[startCol] : (stringData) ? String.fromCharCode(stringData) : WHITESPACE_CELL_CHAR; startCol += this._data[startCol * CELL_SIZE + Cell.WIDTH] || 1; } return result; diff --git a/src/Terminal.integration.ts b/src/Terminal.integration.ts index 21c4a2d0..d2a5cd7c 100644 --- a/src/Terminal.integration.ts +++ b/src/Terminal.integration.ts @@ -13,7 +13,7 @@ import * as path from 'path'; import * as pty from 'node-pty'; import { assert } from 'chai'; import { Terminal } from './Terminal'; -import { CHAR_DATA_CHAR_INDEX } from './Buffer'; +import { CHAR_DATA_CHAR_INDEX, WHITESPACE_CELL_CHAR } from './Buffer'; import { IViewport } from './Types'; class TestTerminal extends Terminal { @@ -67,7 +67,7 @@ function terminalToString(term: Terminal): string { for (let line = term.buffer.ybase; line < term.buffer.ybase + term.rows; line++) { lineText = ''; for (let cell = 0; cell < term.cols; ++cell) { - lineText += term.buffer.lines.get(line).get(cell)[CHAR_DATA_CHAR_INDEX] || ' '; + lineText += term.buffer.lines.get(line).get(cell)[CHAR_DATA_CHAR_INDEX] || WHITESPACE_CELL_CHAR; } // rtrim empty cells as xterm does lineText = lineText.replace(/\s+$/, ''); diff --git a/src/renderer/TextRenderLayer.ts b/src/renderer/TextRenderLayer.ts index 7ab2d238..ade2dd4c 100644 --- a/src/renderer/TextRenderLayer.ts +++ b/src/renderer/TextRenderLayer.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { CHAR_DATA_ATTR_INDEX, CHAR_DATA_CODE_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, NULL_CELL_CODE } from '../Buffer'; +import { CHAR_DATA_ATTR_INDEX, CHAR_DATA_CODE_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, NULL_CELL_CODE, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_CODE } from '../Buffer'; import { FLAGS, IColorSet, IRenderDimensions, ICharacterJoinerRegistry } from './Types'; import { CharData, ITerminal } from '../Types'; import { INVERTED_DEFAULT_COLOR, DEFAULT_COLOR } from './atlas/Types'; @@ -73,11 +73,11 @@ export class TextRenderLayer extends BaseRenderLayer { const joinedRanges = joinerRegistry ? joinerRegistry.getJoinedCharacters(row) : []; for (let x = 0; x < terminal.cols; x++) { const charData = line.get(x); - let code: number = charData[CHAR_DATA_CODE_INDEX] || 32; + let code: number = charData[CHAR_DATA_CODE_INDEX] || WHITESPACE_CELL_CODE; // Can either represent character(s) for a single cell or multiple cells // if indicated by a character joiner. - let chars: string = charData[CHAR_DATA_CHAR_INDEX] || ' '; + let chars: string = charData[CHAR_DATA_CHAR_INDEX] || WHITESPACE_CELL_CHAR; const attr: number = charData[CHAR_DATA_ATTR_INDEX]; let width: number = charData[CHAR_DATA_WIDTH_INDEX]; diff --git a/src/renderer/dom/DomRendererRowFactory.ts b/src/renderer/dom/DomRendererRowFactory.ts index 4a3715c5..8db1dcf8 100644 --- a/src/renderer/dom/DomRendererRowFactory.ts +++ b/src/renderer/dom/DomRendererRowFactory.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_ATTR_INDEX, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CODE_INDEX, NULL_CELL_CODE } from '../../Buffer'; +import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_ATTR_INDEX, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CODE_INDEX, NULL_CELL_CODE, WHITESPACE_CELL_CHAR } from '../../Buffer'; import { FLAGS } from '../Types'; import { IBufferLine } from '../../Types'; import { DEFAULT_COLOR, INVERTED_DEFAULT_COLOR } from '../atlas/Types'; @@ -41,7 +41,7 @@ export class DomRendererRowFactory { for (let x = 0; x < lineLength; x++) { const charData = lineData.get(x); - const char: string = charData[CHAR_DATA_CHAR_INDEX] || ' '; + const char: string = charData[CHAR_DATA_CHAR_INDEX] || WHITESPACE_CELL_CHAR; const attr: number = charData[CHAR_DATA_ATTR_INDEX]; const width: number = charData[CHAR_DATA_WIDTH_INDEX];