From 000fefdeadc1b3ec9e64c9c26db6e1d7f368abc1 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 18 May 2019 17:49:48 -0700 Subject: [PATCH] Move ColorManager to ui Part of #2005 Part of #1507 --- src/TestUtils.test.ts | 3 ++- src/Types.ts | 3 ++- src/Viewport.ts | 2 +- src/renderer/BaseRenderLayer.ts | 3 ++- src/renderer/CursorRenderLayer.ts | 3 ++- src/renderer/LinkRenderLayer.ts | 3 ++- src/renderer/Renderer.ts | 5 +++-- src/renderer/SelectionRenderLayer.ts | 3 ++- src/renderer/TextRenderLayer.ts | 3 ++- src/renderer/Types.ts | 19 +------------------ src/renderer/atlas/CharAtlasCache.ts | 2 +- src/renderer/atlas/CharAtlasGenerator.ts | 2 +- src/renderer/atlas/CharAtlasUtils.ts | 2 +- src/renderer/atlas/DynamicCharAtlas.ts | 4 ++-- src/renderer/atlas/Types.ts | 2 +- src/renderer/dom/DomRenderer.ts | 5 +++-- src/{renderer => ui}/ColorManager.test.ts | 0 src/{renderer => ui}/ColorManager.ts | 0 src/ui/Types.ts | 22 ++++++++++++++++++++++ 19 files changed, 50 insertions(+), 36 deletions(-) rename src/{renderer => ui}/ColorManager.test.ts (100%) rename src/{renderer => ui}/ColorManager.ts (100%) create mode 100644 src/ui/Types.ts diff --git a/src/TestUtils.test.ts b/src/TestUtils.test.ts index b43f262bd9..fecb3a94fe 100644 --- a/src/TestUtils.test.ts +++ b/src/TestUtils.test.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { IColorSet, IRenderer, IRenderDimensions, IColorManager } from './renderer/Types'; +import { IRenderer, IRenderDimensions } from './renderer/Types'; import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, ILinkifier, IMouseHelper, ILinkMatcherOptions, CharacterJoinerHandler, IBufferStringIterator } from './Types'; import { IBufferLine, ICellData, IAttributeData } from './core/Types'; import { ICircularList, XtermListener } from './common/Types'; @@ -12,6 +12,7 @@ import * as Browser from './common/Platform'; import { ITheme, IDisposable, IMarker, IEvent, ISelectionPosition } from 'xterm'; import { Terminal } from './Terminal'; import { AttributeData } from './core/buffer/BufferLine'; +import { IColorManager, IColorSet } from './ui/Types'; export class TestTerminal extends Terminal { writeSync(data: string): void { diff --git a/src/Types.ts b/src/Types.ts index 716daa5d78..ea80383fa8 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -4,10 +4,11 @@ */ import { ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable, IMarker, ISelectionPosition } from 'xterm'; -import { IColorSet, IRenderer } from './renderer/Types'; +import { IRenderer } from './renderer/Types'; import { ICharset, IAttributeData, ICellData, IBufferLine, CharData } from './core/Types'; import { ICircularList } from './common/Types'; import { IEvent } from './common/EventEmitter2'; +import { IColorSet } from './ui/Types'; export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean; diff --git a/src/Viewport.ts b/src/Viewport.ts index 6bf92531ca..b7e2b5f672 100644 --- a/src/Viewport.ts +++ b/src/Viewport.ts @@ -3,11 +3,11 @@ * @license MIT */ -import { IColorSet } from './renderer/Types'; import { ITerminal, IViewport } from './Types'; import { CharMeasure } from './CharMeasure'; import { Disposable } from './common/Lifecycle'; import { addDisposableDomListener } from './ui/Lifecycle'; +import { IColorSet } from './ui/Types'; const FALLBACK_SCROLL_BAR_WIDTH = 15; diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index 498b24d083..691294196f 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { IRenderLayer, IColorSet, IRenderDimensions } from './Types'; +import { IRenderLayer, IRenderDimensions } from './Types'; import { ITerminal } from '../Types'; import { ICellData } from '../core/Types'; import { DEFAULT_COLOR } from '../common/Types'; @@ -11,6 +11,7 @@ import { DIM_OPACITY, INVERTED_DEFAULT_COLOR, IGlyphIdentifier } from './atlas/T import BaseCharAtlas from './atlas/BaseCharAtlas'; import { acquireCharAtlas } from './atlas/CharAtlasCache'; import { CellData, AttributeData, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_CODE } from '../core/buffer/BufferLine'; +import { IColorSet } from '../ui/Types'; export abstract class BaseRenderLayer implements IRenderLayer { private _canvas: HTMLCanvasElement; diff --git a/src/renderer/CursorRenderLayer.ts b/src/renderer/CursorRenderLayer.ts index 3e8af02de6..7b5747000e 100644 --- a/src/renderer/CursorRenderLayer.ts +++ b/src/renderer/CursorRenderLayer.ts @@ -3,11 +3,12 @@ * @license MIT */ -import { IColorSet, IRenderDimensions } from './Types'; +import { IRenderDimensions } from './Types'; import { BaseRenderLayer } from './BaseRenderLayer'; import { ITerminal } from '../Types'; import { ICellData } from '../core/Types'; import { CellData } from '../core/buffer/BufferLine'; +import { IColorSet } from '../ui/Types'; interface ICursorState { x: number; diff --git a/src/renderer/LinkRenderLayer.ts b/src/renderer/LinkRenderLayer.ts index abb899b0f5..c92b10dc63 100644 --- a/src/renderer/LinkRenderLayer.ts +++ b/src/renderer/LinkRenderLayer.ts @@ -4,10 +4,11 @@ */ import { ILinkifierEvent, ITerminal, ILinkifierAccessor } from '../Types'; -import { IColorSet, IRenderDimensions } from './Types'; +import { IRenderDimensions } from './Types'; import { BaseRenderLayer } from './BaseRenderLayer'; import { INVERTED_DEFAULT_COLOR } from './atlas/Types'; import { is256Color } from './atlas/CharAtlasUtils'; +import { IColorSet } from '../ui/Types'; export class LinkRenderLayer extends BaseRenderLayer { private _state: ILinkifierEvent = null; diff --git a/src/renderer/Renderer.ts b/src/renderer/Renderer.ts index 14ce72b351..f5e022a349 100644 --- a/src/renderer/Renderer.ts +++ b/src/renderer/Renderer.ts @@ -6,8 +6,8 @@ import { TextRenderLayer } from './TextRenderLayer'; import { SelectionRenderLayer } from './SelectionRenderLayer'; import { CursorRenderLayer } from './CursorRenderLayer'; -import { ColorManager } from './ColorManager'; -import { IRenderLayer, IColorSet, IRenderer, IRenderDimensions, ICharacterJoinerRegistry } from './Types'; +import { ColorManager } from '../ui/ColorManager'; +import { IRenderLayer, IRenderer, IRenderDimensions, ICharacterJoinerRegistry } from './Types'; import { ITerminal, CharacterJoinerHandler } from '../Types'; import { LinkRenderLayer } from './LinkRenderLayer'; import { RenderDebouncer } from '../ui/RenderDebouncer'; @@ -16,6 +16,7 @@ import { ITheme } from 'xterm'; import { CharacterJoinerRegistry } from '../renderer/CharacterJoinerRegistry'; import { EventEmitter2, IEvent } from '../common/EventEmitter2'; import { Disposable } from '../common/Lifecycle'; +import { IColorSet } from '../ui/Types'; export class Renderer extends Disposable implements IRenderer { private _renderDebouncer: RenderDebouncer; diff --git a/src/renderer/SelectionRenderLayer.ts b/src/renderer/SelectionRenderLayer.ts index fc16a2fb69..81e6afbb90 100644 --- a/src/renderer/SelectionRenderLayer.ts +++ b/src/renderer/SelectionRenderLayer.ts @@ -4,8 +4,9 @@ */ import { ITerminal } from '../Types'; -import { IColorSet, IRenderDimensions } from './Types'; +import { IRenderDimensions } from './Types'; import { BaseRenderLayer } from './BaseRenderLayer'; +import { IColorSet } from '../ui/Types'; interface ISelectionState { start: [number, number]; diff --git a/src/renderer/TextRenderLayer.ts b/src/renderer/TextRenderLayer.ts index 8be5665c43..b3baad31cd 100644 --- a/src/renderer/TextRenderLayer.ts +++ b/src/renderer/TextRenderLayer.ts @@ -3,13 +3,14 @@ * @license MIT */ -import { IColorSet, IRenderDimensions, ICharacterJoinerRegistry } from './Types'; +import { IRenderDimensions, ICharacterJoinerRegistry } from './Types'; import { ITerminal } from '../Types'; import { CharData, ICellData } from '../core/Types'; import { GridCache } from './GridCache'; import { BaseRenderLayer } from './BaseRenderLayer'; import { CellData, AttributeData, Content, NULL_CELL_CODE } from '../core/buffer/BufferLine'; import { JoinedCellData } from './CharacterJoinerRegistry'; +import { IColorSet } from '../ui/Types'; /** * This CharData looks like a null character, which will forc a clear and render diff --git a/src/renderer/Types.ts b/src/renderer/Types.ts index 9d2ddcc32d..df3de528c7 100644 --- a/src/renderer/Types.ts +++ b/src/renderer/Types.ts @@ -6,6 +6,7 @@ import { ITerminal, CharacterJoinerHandler } from '../Types'; import { ITheme, IDisposable } from 'xterm'; import { IEvent } from '../common/EventEmitter2'; +import { IColorManager, IColorSet } from '../ui/Types'; /** * Flags used to render terminal text properly. @@ -47,10 +48,6 @@ export interface IRenderer extends IDisposable { deregisterCharacterJoiner(joinerId: number): boolean; } -export interface IColorManager { - colors: IColorSet; -} - export interface IRenderDimensions { scaledCharWidth: number; scaledCharHeight: number; @@ -134,17 +131,3 @@ export interface ICharacterJoinerRegistry { deregisterCharacterJoiner(joinerId: number): boolean; getJoinedCharacters(row: number): [number, number][]; } - -export interface IColor { - css: string; - rgba: number; // 32-bit int with rgba in each byte -} - -export interface IColorSet { - foreground: IColor; - background: IColor; - cursor: IColor; - cursorAccent: IColor; - selection: IColor; - ansi: IColor[]; -} diff --git a/src/renderer/atlas/CharAtlasCache.ts b/src/renderer/atlas/CharAtlasCache.ts index 388a181b57..30826d5b5b 100644 --- a/src/renderer/atlas/CharAtlasCache.ts +++ b/src/renderer/atlas/CharAtlasCache.ts @@ -4,13 +4,13 @@ */ import { ITerminal } from '../../Types'; -import { IColorSet } from '../Types'; import { generateConfig, configEquals } from './CharAtlasUtils'; import BaseCharAtlas from './BaseCharAtlas'; import DynamicCharAtlas from './DynamicCharAtlas'; import NoneCharAtlas from './NoneCharAtlas'; import StaticCharAtlas from './StaticCharAtlas'; import { ICharAtlasConfig } from './Types'; +import { IColorSet } from '../../ui/Types'; const charAtlasImplementations = { 'none': NoneCharAtlas, diff --git a/src/renderer/atlas/CharAtlasGenerator.ts b/src/renderer/atlas/CharAtlasGenerator.ts index 389507661e..4452cadb8f 100644 --- a/src/renderer/atlas/CharAtlasGenerator.ts +++ b/src/renderer/atlas/CharAtlasGenerator.ts @@ -5,8 +5,8 @@ import { FontWeight } from 'xterm'; import { isFirefox, isSafari } from '../../common/Platform'; -import { IColor } from '../Types'; import { ICharAtlasConfig, CHAR_ATLAS_CELL_SPACING } from './Types'; +import { IColor } from '../../ui/Types'; /** * Generates a char atlas. diff --git a/src/renderer/atlas/CharAtlasUtils.ts b/src/renderer/atlas/CharAtlasUtils.ts index c2eb2e1ef9..762e81418c 100644 --- a/src/renderer/atlas/CharAtlasUtils.ts +++ b/src/renderer/atlas/CharAtlasUtils.ts @@ -4,9 +4,9 @@ */ import { ITerminal } from '../../Types'; -import { IColorSet } from '../Types'; import { ICharAtlasConfig } from './Types'; import { DEFAULT_COLOR } from '../../common/Types'; +import { IColorSet } from '../../ui/Types'; export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: ITerminal, colors: IColorSet): ICharAtlasConfig { // null out some fields that don't matter diff --git a/src/renderer/atlas/DynamicCharAtlas.ts b/src/renderer/atlas/DynamicCharAtlas.ts index cb03a48f94..3239facc98 100644 --- a/src/renderer/atlas/DynamicCharAtlas.ts +++ b/src/renderer/atlas/DynamicCharAtlas.ts @@ -5,11 +5,11 @@ import { DIM_OPACITY, IGlyphIdentifier, INVERTED_DEFAULT_COLOR, ICharAtlasConfig } from './Types'; import BaseCharAtlas from './BaseCharAtlas'; -import { DEFAULT_ANSI_COLORS } from '../ColorManager'; +import { DEFAULT_ANSI_COLORS } from '../../ui/ColorManager'; import { clearColor } from './CharAtlasGenerator'; import LRUMap from './LRUMap'; import { isFirefox, isSafari } from '../../common/Platform'; -import { IColor } from '../Types'; +import { IColor } from '../../ui/Types'; // In practice we're probably never going to exhaust a texture this large. For debugging purposes, // however, it can be useful to set this to a really tiny value, to verify that LRU eviction works. diff --git a/src/renderer/atlas/Types.ts b/src/renderer/atlas/Types.ts index 2459c72ffc..eabdf14199 100644 --- a/src/renderer/atlas/Types.ts +++ b/src/renderer/atlas/Types.ts @@ -4,7 +4,7 @@ */ import { FontWeight } from 'xterm'; -import { IColorSet } from '../Types'; +import { IColorSet } from '../../ui/Types'; export const INVERTED_DEFAULT_COLOR = 257; export const DIM_OPACITY = 0.5; diff --git a/src/renderer/dom/DomRenderer.ts b/src/renderer/dom/DomRenderer.ts index 862f55c884..8c582ec3f4 100644 --- a/src/renderer/dom/DomRenderer.ts +++ b/src/renderer/dom/DomRenderer.ts @@ -3,15 +3,16 @@ * @license MIT */ -import { IRenderer, IRenderDimensions, IColorSet } from '../Types'; +import { IRenderer, IRenderDimensions } from '../Types'; import { ILinkifierEvent, ITerminal, CharacterJoinerHandler } from '../../Types'; import { ITheme } from 'xterm'; -import { ColorManager } from '../ColorManager'; +import { ColorManager } from '../../ui/ColorManager'; import { RenderDebouncer } from '../../ui/RenderDebouncer'; 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 { EventEmitter2, IEvent } from '../../common/EventEmitter2'; import { Disposable } from '../../common/Lifecycle'; +import { IColorSet } from '../../ui/Types'; const TERMINAL_CLASS_PREFIX = 'xterm-dom-renderer-owner-'; const ROW_CONTAINER_CLASS = 'xterm-rows'; diff --git a/src/renderer/ColorManager.test.ts b/src/ui/ColorManager.test.ts similarity index 100% rename from src/renderer/ColorManager.test.ts rename to src/ui/ColorManager.test.ts diff --git a/src/renderer/ColorManager.ts b/src/ui/ColorManager.ts similarity index 100% rename from src/renderer/ColorManager.ts rename to src/ui/ColorManager.ts diff --git a/src/ui/Types.ts b/src/ui/Types.ts new file mode 100644 index 0000000000..ef725ba6e9 --- /dev/null +++ b/src/ui/Types.ts @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2017 The xterm.js authors. All rights reserved. + * @license MIT + */ + +export interface IColorManager { + colors: IColorSet; +} + +export interface IColor { + css: string; + rgba: number; // 32-bit int with rgba in each byte +} + +export interface IColorSet { + foreground: IColor; + background: IColor; + cursor: IColor; + cursorAccent: IColor; + selection: IColor; + ansi: IColor[]; +}