From 0b2df9d611f9bd2b925f3fab27173d9ce3b25f4d Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 14 Jun 2019 21:30:51 -0700 Subject: [PATCH 1/3] Split common/ Types.ts into .d.ts and Constants.ts --- src/common/EventEmitter.ts | 7 ++- src/common/{Types.ts => Types.d.ts} | 17 ++----- src/common/buffer/BufferLine.ts | 3 +- src/common/buffer/Constants.ts | 6 +++ src/common/buffer/{Types.ts => Types.d.ts} | 0 src/common/parser/Constants.ts | 45 +++++++++++++++++++ .../parser/EscapeSequenceParser.test.ts | 3 +- src/common/parser/EscapeSequenceParser.ts | 3 +- src/common/parser/{Types.ts => Types.d.ts} | 42 +---------------- src/renderer/BaseRenderLayer.ts | 3 +- src/renderer/atlas/CharAtlasUtils.ts | 2 +- 11 files changed, 71 insertions(+), 60 deletions(-) rename src/common/{Types.ts => Types.d.ts} (87%) create mode 100644 src/common/buffer/Constants.ts rename src/common/buffer/{Types.ts => Types.d.ts} (100%) create mode 100644 src/common/parser/Constants.ts rename src/common/parser/{Types.ts => Types.d.ts} (84%) diff --git a/src/common/EventEmitter.ts b/src/common/EventEmitter.ts index efc101ce8c..34ac190f15 100644 --- a/src/common/EventEmitter.ts +++ b/src/common/EventEmitter.ts @@ -13,7 +13,12 @@ export interface IEvent { (listener: (e: T) => any): IDisposable; } -export class EventEmitter { +export interface IEventEmitter { + event: IEvent; + fire(data: T): void; +} + +export class EventEmitter implements IEventEmitter { private _listeners: IListener[] = []; private _event?: IEvent; diff --git a/src/common/Types.ts b/src/common/Types.d.ts similarity index 87% rename from src/common/Types.ts rename to src/common/Types.d.ts index b29515d4e8..97bd602934 100644 --- a/src/common/Types.ts +++ b/src/common/Types.d.ts @@ -3,22 +3,13 @@ * @license MIT */ -import { IEvent, EventEmitter } from 'common/EventEmitter'; +import { IEvent, IEventEmitter } from 'common/EventEmitter'; import { IDeleteEvent, IInsertEvent } from 'common/CircularList'; -export const DEFAULT_COLOR = 256; - export interface IDisposable { dispose(): void; } -export interface IEventEmitter { - on(type: string, listener: (...args: any[]) => void): void; - off(type: string, listener: (...args: any[]) => void): void; - emit(type: string, data?: any): void; - addDisposableListener(type: string, handler: (...args: any[]) => void): IDisposable; -} - export type XtermListener = (...args: any[]) => void; /** @@ -40,11 +31,11 @@ export interface ICircularList { maxLength: number; isFull: boolean; - onDeleteEmitter: EventEmitter; + onDeleteEmitter: IEventEmitter; onDelete: IEvent; - onInsertEmitter: EventEmitter; + onInsertEmitter: IEventEmitter; onInsert: IEvent; - onTrimEmitter: EventEmitter; + onTrimEmitter: IEventEmitter; onTrim: IEvent; get(index: number): T | undefined; diff --git a/src/common/buffer/BufferLine.ts b/src/common/buffer/BufferLine.ts index eb0a5e992f..ffa2c2848c 100644 --- a/src/common/buffer/BufferLine.ts +++ b/src/common/buffer/BufferLine.ts @@ -2,8 +2,9 @@ * Copyright (c) 2018 The xterm.js authors. All rights reserved. * @license MIT */ -import { DEFAULT_COLOR, CharData, IBufferLine, ICellData, IColorRGB, IAttributeData } from 'common/Types'; +import { CharData, IBufferLine, ICellData, IColorRGB, IAttributeData } from 'common/Types'; import { stringFromCodePoint } from 'common/input/TextDecoder'; +import { DEFAULT_COLOR } from 'common/buffer/Constants'; export const DEFAULT_ATTR = (0 << 18) | (DEFAULT_COLOR << 9) | (256 << 0); diff --git a/src/common/buffer/Constants.ts b/src/common/buffer/Constants.ts new file mode 100644 index 0000000000..3ad7e55146 --- /dev/null +++ b/src/common/buffer/Constants.ts @@ -0,0 +1,6 @@ +/** + * Copyright (c) 2019 The xterm.js authors. All rights reserved. + * @license MIT + */ + +export const DEFAULT_COLOR = 256; diff --git a/src/common/buffer/Types.ts b/src/common/buffer/Types.d.ts similarity index 100% rename from src/common/buffer/Types.ts rename to src/common/buffer/Types.d.ts diff --git a/src/common/parser/Constants.ts b/src/common/parser/Constants.ts new file mode 100644 index 0000000000..55e4a005f8 --- /dev/null +++ b/src/common/parser/Constants.ts @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +/** + * Internal states of EscapeSequenceParser. + */ +export const enum ParserState { + GROUND = 0, + ESCAPE = 1, + ESCAPE_INTERMEDIATE = 2, + CSI_ENTRY = 3, + CSI_PARAM = 4, + CSI_INTERMEDIATE = 5, + CSI_IGNORE = 6, + SOS_PM_APC_STRING = 7, + OSC_STRING = 8, + DCS_ENTRY = 9, + DCS_PARAM = 10, + DCS_IGNORE = 11, + DCS_INTERMEDIATE = 12, + DCS_PASSTHROUGH = 13 +} + +/** +* Internal actions of EscapeSequenceParser. +*/ +export const enum ParserAction { + IGNORE = 0, + ERROR = 1, + PRINT = 2, + EXECUTE = 3, + OSC_START = 4, + OSC_PUT = 5, + OSC_END = 6, + CSI_DISPATCH = 7, + PARAM = 8, + COLLECT = 9, + ESC_DISPATCH = 10, + CLEAR = 11, + DCS_HOOK = 12, + DCS_PUT = 13, + DCS_UNHOOK = 14 +} diff --git a/src/common/parser/EscapeSequenceParser.test.ts b/src/common/parser/EscapeSequenceParser.test.ts index 18d5c6cf91..f445efc403 100644 --- a/src/common/parser/EscapeSequenceParser.test.ts +++ b/src/common/parser/EscapeSequenceParser.test.ts @@ -3,10 +3,11 @@ * @license MIT */ -import { ParserState, IDcsHandler, IParsingState } from 'common/parser/Types'; +import { IDcsHandler, IParsingState } from 'common/parser/Types'; import { EscapeSequenceParser, TransitionTable, VT500_TRANSITION_TABLE } from 'common/parser/EscapeSequenceParser'; import * as chai from 'chai'; import { StringToUtf32, stringFromCodePoint } from 'common/input/TextDecoder'; +import { ParserState } from 'common/parser/Constants'; function r(a: number, b: number): string[] { let c = b - a; diff --git a/src/common/parser/EscapeSequenceParser.ts b/src/common/parser/EscapeSequenceParser.ts index c8b631d08b..d8d4e02eda 100644 --- a/src/common/parser/EscapeSequenceParser.ts +++ b/src/common/parser/EscapeSequenceParser.ts @@ -3,7 +3,8 @@ * @license MIT */ -import { ParserState, ParserAction, IParsingState, IDcsHandler, IEscapeSequenceParser } from 'common/parser/Types'; +import { IParsingState, IDcsHandler, IEscapeSequenceParser } from 'common/parser/Types'; +import { ParserState, ParserAction } from 'common/parser/Constants'; import { Disposable } from 'common/Lifecycle'; import { utf32ToString } from 'common/input/TextDecoder'; import { IDisposable } from 'common/Types'; diff --git a/src/common/parser/Types.ts b/src/common/parser/Types.d.ts similarity index 84% rename from src/common/parser/Types.ts rename to src/common/parser/Types.d.ts index 871997029b..47ec98e15d 100644 --- a/src/common/parser/Types.ts +++ b/src/common/parser/Types.d.ts @@ -4,47 +4,7 @@ */ import { IDisposable } from 'common/Types'; - -/** - * Internal states of EscapeSequenceParser. - */ -export const enum ParserState { - GROUND = 0, - ESCAPE = 1, - ESCAPE_INTERMEDIATE = 2, - CSI_ENTRY = 3, - CSI_PARAM = 4, - CSI_INTERMEDIATE = 5, - CSI_IGNORE = 6, - SOS_PM_APC_STRING = 7, - OSC_STRING = 8, - DCS_ENTRY = 9, - DCS_PARAM = 10, - DCS_IGNORE = 11, - DCS_INTERMEDIATE = 12, - DCS_PASSTHROUGH = 13 -} - -/** -* Internal actions of EscapeSequenceParser. -*/ -export const enum ParserAction { - IGNORE = 0, - ERROR = 1, - PRINT = 2, - EXECUTE = 3, - OSC_START = 4, - OSC_PUT = 5, - OSC_END = 6, - CSI_DISPATCH = 7, - PARAM = 8, - COLLECT = 9, - ESC_DISPATCH = 10, - CLEAR = 11, - DCS_HOOK = 12, - DCS_PUT = 13, - DCS_UNHOOK = 14 -} +import { ParserState } from 'common/parser/Constants'; /** * Internal state of EscapeSequenceParser. diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index 8335f76d9e..f4ff6ccba9 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -6,7 +6,8 @@ import { IRenderLayer } from './Types'; import { IRenderDimensions } from 'browser/renderer/Types'; import { ITerminal } from '../Types'; -import { ICellData, DEFAULT_COLOR } from 'common/Types'; +import { ICellData } from 'common/Types'; +import { DEFAULT_COLOR } from 'common/buffer/Constants'; import { DIM_OPACITY, INVERTED_DEFAULT_COLOR, IGlyphIdentifier } from './atlas/Types'; import { BaseCharAtlas } from './atlas/BaseCharAtlas'; import { acquireCharAtlas } from './atlas/CharAtlasCache'; diff --git a/src/renderer/atlas/CharAtlasUtils.ts b/src/renderer/atlas/CharAtlasUtils.ts index b68793f64f..ee787a7ba8 100644 --- a/src/renderer/atlas/CharAtlasUtils.ts +++ b/src/renderer/atlas/CharAtlasUtils.ts @@ -5,7 +5,7 @@ import { ITerminal } from '../../Types'; import { ICharAtlasConfig } from './Types'; -import { DEFAULT_COLOR } from 'common/Types'; +import { DEFAULT_COLOR } from 'common/buffer/Constants'; import { IColorSet } from 'browser/Types'; export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: ITerminal, colors: IColorSet): ICharAtlasConfig { From 913faef3b84b0d2abccf5afa2de9aa6a0fe5566f Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 14 Jun 2019 21:38:19 -0700 Subject: [PATCH 2/3] Split src/ Types.ts into d.ts and Constants --- src/{Types.ts => Types.d.ts} | 6 +++--- src/renderer/BaseRenderLayer.ts | 3 ++- src/renderer/Constants.ts | 17 +++++++++++++++++ src/renderer/LinkRenderLayer.ts | 2 +- src/renderer/{Types.ts => Types.d.ts} | 13 ------------- src/renderer/atlas/Constants.ts | 9 +++++++++ src/renderer/atlas/DynamicCharAtlas.ts | 3 ++- src/renderer/atlas/{Types.ts => Types.d.ts} | 5 ----- src/renderer/dom/DomRenderer.ts | 2 +- src/renderer/dom/DomRendererRowFactory.ts | 2 +- 10 files changed, 36 insertions(+), 26 deletions(-) rename src/{Types.ts => Types.d.ts} (98%) create mode 100644 src/renderer/Constants.ts rename src/renderer/{Types.ts => Types.d.ts} (91%) create mode 100644 src/renderer/atlas/Constants.ts rename src/renderer/atlas/{Types.ts => Types.d.ts} (83%) diff --git a/src/Types.ts b/src/Types.d.ts similarity index 98% rename from src/Types.ts rename to src/Types.d.ts index 721ab063dd..6f587931c8 100644 --- a/src/Types.ts +++ b/src/Types.d.ts @@ -5,7 +5,7 @@ import { ITerminalOptions as IPublicTerminalOptions, IDisposable, IMarker, ISelectionPosition } from 'xterm'; import { ICharset, IAttributeData, CharData } from 'common/Types'; -import { IEvent, EventEmitter } from 'common/EventEmitter'; +import { IEvent, IEventEmitter } from 'common/EventEmitter'; import { IColorSet, IMouseHelper } from 'browser/Types'; import { IOptionsService } from 'common/services/Services'; import { IBuffer, IBufferSet } from 'common/buffer/Types'; @@ -54,8 +54,8 @@ export interface IInputHandlingTerminal { viewport: IViewport; selectionManager: ISelectionManager; - onA11yCharEmitter: EventEmitter; - onA11yTabEmitter: EventEmitter; + onA11yCharEmitter: IEventEmitter; + onA11yTabEmitter: IEventEmitter; bell(): void; focus(): void; diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index f4ff6ccba9..89679d3c3c 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -8,7 +8,8 @@ import { IRenderDimensions } from 'browser/renderer/Types'; import { ITerminal } from '../Types'; import { ICellData } from 'common/Types'; import { DEFAULT_COLOR } from 'common/buffer/Constants'; -import { DIM_OPACITY, INVERTED_DEFAULT_COLOR, IGlyphIdentifier } from './atlas/Types'; +import { IGlyphIdentifier } from './atlas/Types'; +import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from './atlas/Constants'; import { BaseCharAtlas } from './atlas/BaseCharAtlas'; import { acquireCharAtlas } from './atlas/CharAtlasCache'; import { CellData, AttributeData, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_CODE } from 'common/buffer/BufferLine'; diff --git a/src/renderer/Constants.ts b/src/renderer/Constants.ts new file mode 100644 index 0000000000..36ce9b0736 --- /dev/null +++ b/src/renderer/Constants.ts @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +/** + * Flags used to render terminal text properly for the old CharData format + */ +export const enum FLAGS { + BOLD = 1, + UNDERLINE = 2, + BLINK = 4, + INVERSE = 8, + INVISIBLE = 16, + DIM = 32, + ITALIC = 64 +} diff --git a/src/renderer/LinkRenderLayer.ts b/src/renderer/LinkRenderLayer.ts index 32db3db91d..99eff4a2e1 100644 --- a/src/renderer/LinkRenderLayer.ts +++ b/src/renderer/LinkRenderLayer.ts @@ -6,7 +6,7 @@ import { ILinkifierEvent, ITerminal, ILinkifierAccessor } from '../Types'; import { IRenderDimensions } from 'browser/renderer/Types'; import { BaseRenderLayer } from './BaseRenderLayer'; -import { INVERTED_DEFAULT_COLOR } from './atlas/Types'; +import { INVERTED_DEFAULT_COLOR } from './atlas/Constants'; import { is256Color } from './atlas/CharAtlasUtils'; import { IColorSet } from 'browser/Types'; diff --git a/src/renderer/Types.ts b/src/renderer/Types.d.ts similarity index 91% rename from src/renderer/Types.ts rename to src/renderer/Types.d.ts index 153b68e248..5f7d67a8d5 100644 --- a/src/renderer/Types.ts +++ b/src/renderer/Types.d.ts @@ -8,19 +8,6 @@ import { IDisposable } from 'xterm'; import { IColorSet } from 'browser/Types'; import { IRenderDimensions, CharacterJoinerHandler } from 'browser/renderer/Types'; -/** - * Flags used to render terminal text properly. - */ -export const enum FLAGS { - BOLD = 1, - UNDERLINE = 2, - BLINK = 4, - INVERSE = 8, - INVISIBLE = 16, - DIM = 32, - ITALIC = 64 -} - export interface IRenderLayer extends IDisposable { /** * Called when the terminal loses focus. diff --git a/src/renderer/atlas/Constants.ts b/src/renderer/atlas/Constants.ts new file mode 100644 index 0000000000..150aad888f --- /dev/null +++ b/src/renderer/atlas/Constants.ts @@ -0,0 +1,9 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +export const INVERTED_DEFAULT_COLOR = 257; +export const DIM_OPACITY = 0.5; + +export const CHAR_ATLAS_CELL_SPACING = 1; diff --git a/src/renderer/atlas/DynamicCharAtlas.ts b/src/renderer/atlas/DynamicCharAtlas.ts index c8ccefcbda..fdae4e8029 100644 --- a/src/renderer/atlas/DynamicCharAtlas.ts +++ b/src/renderer/atlas/DynamicCharAtlas.ts @@ -3,7 +3,8 @@ * @license MIT */ -import { DIM_OPACITY, IGlyphIdentifier, INVERTED_DEFAULT_COLOR, ICharAtlasConfig } from './Types'; +import { IGlyphIdentifier, ICharAtlasConfig } from './Types'; +import { DIM_OPACITY, INVERTED_DEFAULT_COLOR } from './Constants'; import { BaseCharAtlas } from './BaseCharAtlas'; import { DEFAULT_ANSI_COLORS } from 'browser/ColorManager'; import { LRUMap } from './LRUMap'; diff --git a/src/renderer/atlas/Types.ts b/src/renderer/atlas/Types.d.ts similarity index 83% rename from src/renderer/atlas/Types.ts rename to src/renderer/atlas/Types.d.ts index 2cb1db4097..1de843e08a 100644 --- a/src/renderer/atlas/Types.ts +++ b/src/renderer/atlas/Types.d.ts @@ -6,11 +6,6 @@ import { FontWeight } from 'xterm'; import { IColorSet } from 'browser/Types'; -export const INVERTED_DEFAULT_COLOR = 257; -export const DIM_OPACITY = 0.5; - -export const CHAR_ATLAS_CELL_SPACING = 1; - export interface IGlyphIdentifier { chars: string; code: number; diff --git a/src/renderer/dom/DomRenderer.ts b/src/renderer/dom/DomRenderer.ts index 284905c6ea..fe6ab4d1b9 100644 --- a/src/renderer/dom/DomRenderer.ts +++ b/src/renderer/dom/DomRenderer.ts @@ -6,7 +6,7 @@ import { IRenderer, IRenderDimensions, CharacterJoinerHandler } from 'browser/renderer/Types'; import { ILinkifierEvent, ITerminal } from '../../Types'; import { BOLD_CLASS, ITALIC_CLASS, CURSOR_CLASS, CURSOR_STYLE_BLOCK_CLASS, CURSOR_BLINK_CLASS, CURSOR_STYLE_BAR_CLASS, CURSOR_STYLE_UNDERLINE_CLASS, DomRendererRowFactory } from './DomRendererRowFactory'; -import { INVERTED_DEFAULT_COLOR } from '../atlas/Types'; +import { INVERTED_DEFAULT_COLOR } from '../atlas/Constants'; import { Disposable } from 'common/Lifecycle'; import { IColorSet } from 'browser/Types'; import { ICharSizeService } from 'browser/services/Services'; diff --git a/src/renderer/dom/DomRendererRowFactory.ts b/src/renderer/dom/DomRendererRowFactory.ts index 8c31aa444b..b4de161f7a 100644 --- a/src/renderer/dom/DomRendererRowFactory.ts +++ b/src/renderer/dom/DomRendererRowFactory.ts @@ -5,7 +5,7 @@ import { ITerminalOptions } from '../../Types'; import { IBufferLine } from 'common/Types'; -import { INVERTED_DEFAULT_COLOR } from '../atlas/Types'; +import { INVERTED_DEFAULT_COLOR } from '../atlas/Constants'; import { CellData, AttributeData, NULL_CELL_CODE, WHITESPACE_CELL_CHAR } from 'common/buffer/BufferLine'; export const BOLD_CLASS = 'xterm-bold'; From 7b6dd9fe9d8fa67d6e3a3d6ea5c8ade9a1f1d779 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 14 Jun 2019 21:39:22 -0700 Subject: [PATCH 3/3] Rename browser Types.ts to .d.ts --- src/browser/{Types.ts => Types.d.ts} | 0 src/browser/renderer/{Types.ts => Types.d.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/browser/{Types.ts => Types.d.ts} (100%) rename src/browser/renderer/{Types.ts => Types.d.ts} (100%) diff --git a/src/browser/Types.ts b/src/browser/Types.d.ts similarity index 100% rename from src/browser/Types.ts rename to src/browser/Types.d.ts diff --git a/src/browser/renderer/Types.ts b/src/browser/renderer/Types.d.ts similarity index 100% rename from src/browser/renderer/Types.ts rename to src/browser/renderer/Types.d.ts