Skip to content

Commit

Permalink
Move ColorManager to ui
Browse files Browse the repository at this point in the history
Part of xtermjs#2005
Part of xtermjs#1507
  • Loading branch information
Tyriar committed May 19, 2019
1 parent 3395539 commit 000fefd
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/renderer/BaseRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
* @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';
import { DIM_OPACITY, INVERTED_DEFAULT_COLOR, IGlyphIdentifier } from './atlas/Types';
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;
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/CursorRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/LinkRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/SelectionRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/TextRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 1 addition & 18 deletions src/renderer/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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[];
}
2 changes: 1 addition & 1 deletion src/renderer/atlas/CharAtlasCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/atlas/CharAtlasGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/atlas/CharAtlasUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/atlas/DynamicCharAtlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/atlas/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/dom/DomRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions src/ui/Types.ts
Original file line number Diff line number Diff line change
@@ -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[];
}

0 comments on commit 000fefd

Please sign in to comment.