From 45682f0e7659e7cb59e7c1094868f81c517c84cc Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 14 Jun 2019 22:55:06 -0700 Subject: [PATCH] Move Content to Constants --- src/common/buffer/BufferLine.test.ts | 4 +-- src/common/buffer/BufferLine.ts | 46 +------------------------ src/common/buffer/CellData.ts | 10 ++++-- src/common/buffer/Constants.ts | 43 +++++++++++++++++++++++ src/renderer/CharacterJoinerRegistry.ts | 4 +-- src/renderer/TextRenderLayer.ts | 4 +-- 6 files changed, 58 insertions(+), 53 deletions(-) diff --git a/src/common/buffer/BufferLine.test.ts b/src/common/buffer/BufferLine.test.ts index 4ee604b5..ae80aa16 100644 --- a/src/common/buffer/BufferLine.test.ts +++ b/src/common/buffer/BufferLine.test.ts @@ -3,8 +3,8 @@ * @license MIT */ import * as chai from 'chai'; -import { NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR } from 'common/buffer/Constants'; -import { BufferLine, Content } from 'common/buffer//BufferLine'; +import { NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR, Content } from 'common/buffer/Constants'; +import { BufferLine } from 'common/buffer//BufferLine'; import { CellData } from 'common/buffer/CellData'; import { CharData, IBufferLine } from '../Types'; diff --git a/src/common/buffer/BufferLine.ts b/src/common/buffer/BufferLine.ts index b171649c..95ddb91a 100644 --- a/src/common/buffer/BufferLine.ts +++ b/src/common/buffer/BufferLine.ts @@ -5,7 +5,7 @@ import { CharData, IBufferLine, ICellData, IColorRGB, IAttributeData } from 'common/Types'; import { stringFromCodePoint } from 'common/input/TextDecoder'; -import { DEFAULT_COLOR, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_ATTR_INDEX, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, WHITESPACE_CELL_CHAR } from 'common/buffer/Constants'; +import { DEFAULT_COLOR, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_ATTR_INDEX, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, WHITESPACE_CELL_CHAR, Content } from 'common/buffer/Constants'; import { CellData } from './CellData'; /** @@ -34,50 +34,6 @@ const enum Cell { BG = 2 // currently unused } -/** - * Bitmasks for accessing data in `content`. - */ -export const enum Content { - /** - * bit 1..21 codepoint, max allowed in UTF32 is 0x10FFFF (21 bits taken) - * read: `codepoint = content & Content.codepointMask;` - * write: `content |= codepoint & Content.codepointMask;` - * shortcut if precondition `codepoint <= 0x10FFFF` is met: - * `content |= codepoint;` - */ - CODEPOINT_MASK = 0x1FFFFF, - - /** - * bit 22 flag indication whether a cell contains combined content - * read: `isCombined = content & Content.isCombined;` - * set: `content |= Content.isCombined;` - * clear: `content &= ~Content.isCombined;` - */ - IS_COMBINED_MASK = 0x200000, // 1 << 21 - - /** - * bit 1..22 mask to check whether a cell contains any string data - * we need to check for codepoint and isCombined bits to see - * whether a cell contains anything - * read: `isEmpty = !(content & Content.hasContent)` - */ - HAS_CONTENT_MASK = 0x3FFFFF, - - /** - * bit 23..24 wcwidth value of cell, takes 2 bits (ranges from 0..2) - * read: `width = (content & Content.widthMask) >> Content.widthShift;` - * `hasWidth = content & Content.widthMask;` - * as long as wcwidth is highest value in `content`: - * `width = content >> Content.widthShift;` - * write: `content |= (width << Content.widthShift) & Content.widthMask;` - * shortcut if precondition `0 <= width <= 3` is met: - * `content |= width << Content.widthShift;` - */ - WIDTH_MASK = 0xC00000, // 3 << 22 - WIDTH_SHIFT = 22 -} - - export const enum Attributes { /** * bit 1..8 blue in RGB, color in P256 and P16 diff --git a/src/common/buffer/CellData.ts b/src/common/buffer/CellData.ts index 11fa607b..39fe0d50 100644 --- a/src/common/buffer/CellData.ts +++ b/src/common/buffer/CellData.ts @@ -1,7 +1,13 @@ +/** + * Copyright (c) 2018 The xterm.js authors. All rights reserved. + * @license MIT + */ + import { CharData, ICellData } from 'common/Types'; import { stringFromCodePoint } from 'common/input/TextDecoder'; -import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_ATTR_INDEX } from 'common/buffer/Constants'; -import { AttributeData, Content } from './BufferLine'; +import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_ATTR_INDEX, Content } from 'common/buffer/Constants'; +import { AttributeData } from './BufferLine'; + /** * CellData - represents a single Cell in the terminal buffer. */ diff --git a/src/common/buffer/Constants.ts b/src/common/buffer/Constants.ts index eee530ee..35c9096f 100644 --- a/src/common/buffer/Constants.ts +++ b/src/common/buffer/Constants.ts @@ -28,3 +28,46 @@ export const NULL_CELL_CODE = 0; export const WHITESPACE_CELL_CHAR = ' '; export const WHITESPACE_CELL_WIDTH = 1; export const WHITESPACE_CELL_CODE = 32; + +/** + * Bitmasks for accessing data in `content`. + */ +export const enum Content { + /** + * bit 1..21 codepoint, max allowed in UTF32 is 0x10FFFF (21 bits taken) + * read: `codepoint = content & Content.codepointMask;` + * write: `content |= codepoint & Content.codepointMask;` + * shortcut if precondition `codepoint <= 0x10FFFF` is met: + * `content |= codepoint;` + */ + CODEPOINT_MASK = 0x1FFFFF, + + /** + * bit 22 flag indication whether a cell contains combined content + * read: `isCombined = content & Content.isCombined;` + * set: `content |= Content.isCombined;` + * clear: `content &= ~Content.isCombined;` + */ + IS_COMBINED_MASK = 0x200000, // 1 << 21 + + /** + * bit 1..22 mask to check whether a cell contains any string data + * we need to check for codepoint and isCombined bits to see + * whether a cell contains anything + * read: `isEmpty = !(content & Content.hasContent)` + */ + HAS_CONTENT_MASK = 0x3FFFFF, + + /** + * bit 23..24 wcwidth value of cell, takes 2 bits (ranges from 0..2) + * read: `width = (content & Content.widthMask) >> Content.widthShift;` + * `hasWidth = content & Content.widthMask;` + * as long as wcwidth is highest value in `content`: + * `width = content >> Content.widthShift;` + * write: `content |= (width << Content.widthShift) & Content.widthMask;` + * shortcut if precondition `0 <= width <= 3` is met: + * `content |= width << Content.widthShift;` + */ + WIDTH_MASK = 0xC00000, // 3 << 22 + WIDTH_SHIFT = 22 +} diff --git a/src/renderer/CharacterJoinerRegistry.ts b/src/renderer/CharacterJoinerRegistry.ts index b82d419b..475def00 100644 --- a/src/renderer/CharacterJoinerRegistry.ts +++ b/src/renderer/CharacterJoinerRegistry.ts @@ -6,8 +6,8 @@ import { ITerminal } from '../Types'; import { IBufferLine, ICellData, CharData } from 'common/Types'; import { ICharacterJoinerRegistry, ICharacterJoiner } from './Types'; -import { Content, AttributeData } from 'common/buffer/BufferLine'; -import { WHITESPACE_CELL_CHAR } from 'common/buffer/Constants'; +import { AttributeData } from 'common/buffer/BufferLine'; +import { WHITESPACE_CELL_CHAR, Content } from 'common/buffer/Constants'; import { CellData } from 'common/buffer/CellData'; export class JoinedCellData extends AttributeData implements ICellData { diff --git a/src/renderer/TextRenderLayer.ts b/src/renderer/TextRenderLayer.ts index 0d462a2c..a0aac5ad 100644 --- a/src/renderer/TextRenderLayer.ts +++ b/src/renderer/TextRenderLayer.ts @@ -9,8 +9,8 @@ import { ITerminal } from '../Types'; import { CharData, ICellData } from 'common/Types'; import { GridCache } from './GridCache'; import { BaseRenderLayer } from './BaseRenderLayer'; -import { AttributeData, Content } from 'common/buffer/BufferLine'; -import { NULL_CELL_CODE } from 'common/buffer/Constants'; +import { AttributeData } from 'common/buffer/BufferLine'; +import { NULL_CELL_CODE, Content } from 'common/buffer/Constants'; import { JoinedCellData } from './CharacterJoinerRegistry'; import { IColorSet } from 'browser/Types'; import { CellData } from 'common/buffer/CellData';