Skip to content

Commit

Permalink
Merge pull request #1652 from Tyriar/1337_project_refs_prep
Browse files Browse the repository at this point in the history
Preparation for project references
  • Loading branch information
Tyriar committed Sep 8, 2018
2 parents 0d89fcd + 8b334b0 commit bdb6647
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -40,7 +40,7 @@
"ts-loader": "^4.5.0",
"tslint": "^5.9.1",
"tslint-consistent-codestyle": "^1.13.0",
"typescript": "2.8.3",
"typescript": "3.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"webpack": "^4.17.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Buffer.ts
Expand Up @@ -5,7 +5,7 @@

import { CircularList } from './common/CircularList';
import { CharData, ITerminal, IBuffer, IBufferLine } from './Types';
import { EventEmitter } from './EventEmitter';
import { EventEmitter } from './common/EventEmitter';
import { IMarker } from 'xterm';
import { BufferLine } from './BufferLine';

Expand Down
2 changes: 1 addition & 1 deletion src/BufferSet.ts
Expand Up @@ -5,7 +5,7 @@

import { ITerminal, IBufferSet } from './Types';
import { Buffer } from './Buffer';
import { EventEmitter } from './EventEmitter';
import { EventEmitter } from './common/EventEmitter';

/**
* The BufferSet represents the set of two buffers used by xterm terminals (normal and alt) and
Expand Down
2 changes: 1 addition & 1 deletion src/Linkifier.ts
Expand Up @@ -6,7 +6,7 @@
import { IMouseZoneManager } from './ui/Types';
import { ILinkHoverEvent, ILinkMatcher, LinkMatcherHandler, LinkHoverEventTypes, ILinkMatcherOptions, ILinkifier, ITerminal, IBufferLine } from './Types';
import { MouseZone } from './ui/MouseZoneManager';
import { EventEmitter } from './EventEmitter';
import { EventEmitter } from './common/EventEmitter';
import { CHAR_DATA_ATTR_INDEX } from './Buffer';

/**
Expand Down
5 changes: 3 additions & 2 deletions src/SelectionManager.ts
Expand Up @@ -3,11 +3,12 @@
* @license MIT
*/

import { ITerminal, ISelectionManager, IBuffer, CharData, XtermListener, IBufferLine } from './Types';
import { ITerminal, ISelectionManager, IBuffer, CharData, IBufferLine } from './Types';
import { XtermListener } from './common/Types';
import { MouseHelper } from './utils/MouseHelper';
import * as Browser from './shared/utils/Browser';
import { CharMeasure } from './ui/CharMeasure';
import { EventEmitter } from './EventEmitter';
import { EventEmitter } from './common/EventEmitter';
import { SelectionModel } from './SelectionModel';
import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_CODE_INDEX } from './Buffer';
import { AltClickHandler } from './handlers/AltClickHandler';
Expand Down
2 changes: 1 addition & 1 deletion src/Terminal.ts
Expand Up @@ -27,7 +27,7 @@ import { IRenderer } from './renderer/Types';
import { BufferSet } from './BufferSet';
import { Buffer, MAX_BUFFER_SIZE, DEFAULT_ATTR, NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer';
import { CompositionHelper } from './CompositionHelper';
import { EventEmitter } from './EventEmitter';
import { EventEmitter } from './common/EventEmitter';
import { Viewport } from './Viewport';
import { rightClickHandler, moveTextAreaUnderMouseCursor, pasteHandler, copyHandler } from './handlers/Clipboard';
import { C0 } from './common/data/EscapeSequences';
Expand Down
16 changes: 1 addition & 15 deletions src/Types.ts
Expand Up @@ -7,11 +7,10 @@ import { Terminal as PublicTerminal, ITerminalOptions as IPublicTerminalOptions,
import { IColorSet, IRenderer } from './renderer/Types';
import { IMouseZoneManager } from './ui/Types';
import { ICharset } from './core/Types';
import { ICircularList } from './common/Types';

export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean;

export type XtermListener = (...args: any[]) => void;

export type CharData = [number, string, number, number];
export type LineData = CharData[];

Expand Down Expand Up @@ -294,19 +293,6 @@ export interface IBufferSet extends IEventEmitter {
activateAltBuffer(): void;
}

export interface ICircularList<T> extends IEventEmitter {
length: number;
maxLength: number;

get(index: number): T;
set(index: number, value: T): void;
push(value: T): void;
pop(): T;
splice(start: number, deleteCount: number, ...items: T[]): void;
trimStart(count: number): void;
shiftElements(start: number, count: number, offset: number): void;
}

export interface ISelectionManager {
selectionText: string;
selectionStart: [number, number];
Expand Down
14 changes: 7 additions & 7 deletions src/common/CircularList.ts
Expand Up @@ -3,15 +3,15 @@
* @license MIT
*/

import { EventEmitter } from '../EventEmitter';
import { ICircularList } from '../Types';
import { EventEmitter } from './EventEmitter';
import { ICircularList } from './Types';

/**
* Represents a circular list; a list with a maximum size that wraps around when push is called,
* overriding values at the start of the list.
*/
export class CircularList<T> extends EventEmitter implements ICircularList<T> {
protected _array: T[];
protected _array: (T | undefined)[];
private _startIndex: number;
private _length: number;

Expand All @@ -36,7 +36,7 @@ export class CircularList<T> extends EventEmitter implements ICircularList<T> {

// Reconstruct array, starting at index 0. Only transfer values from the
// indexes 0 to length.
const newArray = new Array<T>(newMaxLength);
const newArray = new Array<T | undefined>(newMaxLength);
for (let i = 0; i < Math.min(newMaxLength, this.length); i++) {
newArray[i] = this._array[this._getCyclicIndex(i)];
}
Expand Down Expand Up @@ -66,7 +66,7 @@ export class CircularList<T> extends EventEmitter implements ICircularList<T> {
* @param index The index of the value to get.
* @return The value corresponding to the index.
*/
public get(index: number): T {
public get(index: number): T | undefined {
return this._array[this._getCyclicIndex(index)];
}

Expand All @@ -78,7 +78,7 @@ export class CircularList<T> extends EventEmitter implements ICircularList<T> {
* @param index The index to set.
* @param value The value to set.
*/
public set(index: number, value: T): void {
public set(index: number, value: T | undefined): void {
this._array[this._getCyclicIndex(index)] = value;
}

Expand All @@ -104,7 +104,7 @@ export class CircularList<T> extends EventEmitter implements ICircularList<T> {
* Removes and returns the last value on the list.
* @return The popped value.
*/
public pop(): T {
public pop(): T | undefined {
return this._array[this._getCyclicIndex(this._length-- - 1)];
}

Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions src/EventEmitter.ts → src/common/EventEmitter.ts
Expand Up @@ -5,7 +5,7 @@

import { XtermListener } from './Types';
import { IEventEmitter, IDisposable } from 'xterm';
import { Disposable } from './common/Lifecycle';
import { Disposable } from './Lifecycle';

export class EventEmitter extends Disposable implements IEventEmitter, IDisposable {
private _events: {[type: string]: XtermListener[]};
Expand All @@ -30,14 +30,15 @@ export class EventEmitter extends Disposable implements IEventEmitter, IDisposab
public addDisposableListener(type: string, handler: XtermListener): IDisposable {
// TODO: Rename addDisposableEventListener to more easily disambiguate from Dom listener
this.on(type, handler);
let disposed = false;
return {
dispose: () => {
if (!handler) {
if (disposed) {
// Already disposed
return;
}
this.off(type, handler);
handler = null;
disposed = true;
}
};
}
Expand Down
17 changes: 17 additions & 0 deletions src/common/Types.ts
Expand Up @@ -3,6 +3,10 @@
* @license MIT
*/

import { IEventEmitter } from 'xterm';

export type XtermListener = (...args: any[]) => void;

/**
* A keyboard event interface which does not depend on the DOM, KeyboardEvent implicitly extends
* this event.
Expand All @@ -16,3 +20,16 @@ export interface IKeyboardEvent {
key: string;
type: string;
}

export interface ICircularList<T> extends IEventEmitter {
length: number;
maxLength: number;

get(index: number): T | undefined;
set(index: number, value: T): void;
push(value: T): void;
pop(): T | undefined;
splice(start: number, deleteCount: number, ...items: T[]): void;
trimStart(count: number): void;
shiftElements(start: number, count: number, offset: number): void;
}
3 changes: 2 additions & 1 deletion src/handlers/AltClickHandler.ts
Expand Up @@ -3,7 +3,8 @@
* @license MIT
*/

import { ITerminal, ICircularList, IBufferLine } from '../Types';
import { ITerminal, IBufferLine } from '../Types';
import { ICircularList } from '../common/Types';
import { C0 } from '../common/data/EscapeSequences';

const enum Direction {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/Renderer.ts
Expand Up @@ -10,7 +10,7 @@ import { ColorManager } from './ColorManager';
import { IRenderLayer, IColorSet, IRenderer, IRenderDimensions, ICharacterJoinerRegistry } from './Types';
import { ITerminal, CharacterJoinerHandler } from '../Types';
import { LinkRenderLayer } from './LinkRenderLayer';
import { EventEmitter } from '../EventEmitter';
import { EventEmitter } from '../common/EventEmitter';
import { RenderDebouncer } from '../ui/RenderDebouncer';
import { ScreenDprMonitor } from '../ui/ScreenDprMonitor';
import { ITheme } from 'xterm';
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/dom/DomRenderer.ts
Expand Up @@ -6,7 +6,7 @@
import { IRenderer, IRenderDimensions, IColorSet } from '../Types';
import { ITerminal, CharacterJoinerHandler } from '../../Types';
import { ITheme } from 'xterm';
import { EventEmitter } from '../../EventEmitter';
import { EventEmitter } from '../../common/EventEmitter';
import { ColorManager } from '../ColorManager';
import { RenderDebouncer } from '../../ui/RenderDebouncer';
import { BOLD_CLASS, ITALIC_CLASS, CURSOR_CLASS, CURSOR_STYLE_BLOCK_CLASS, CURSOR_STYLE_BAR_CLASS, CURSOR_STYLE_UNDERLINE_CLASS, DomRendererRowFactory } from './DomRendererRowFactory';
Expand Down
2 changes: 1 addition & 1 deletion src/ui/CharMeasure.ts
Expand Up @@ -4,7 +4,7 @@
*/

import { ICharMeasure, ITerminalOptions } from '../Types';
import { EventEmitter } from '../EventEmitter';
import { EventEmitter } from '../common/EventEmitter';

/**
* Utility class that measures the size of a character. Measurements are done in
Expand Down
3 changes: 2 additions & 1 deletion src/utils/TestUtils.test.ts
Expand Up @@ -4,7 +4,8 @@
*/

import { IColorSet, IRenderer, IRenderDimensions, IColorManager } from '../renderer/Types';
import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, ICircularList, ILinkifier, IMouseHelper, ILinkMatcherOptions, XtermListener, CharacterJoinerHandler, IBufferLine } from '../Types';
import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, ILinkifier, IMouseHelper, ILinkMatcherOptions, CharacterJoinerHandler, IBufferLine } from '../Types';
import { ICircularList, XtermListener } from '../common/Types';
import { Buffer } from '../Buffer';
import * as Browser from '../shared/utils/Browser';
import { ITheme, IDisposable, IMarker } from 'xterm';
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -5868,9 +5868,9 @@ typedarray@^0.0.6, typedarray@~0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@2.8.3:
version "2.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170"
typescript@3.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.3.tgz#4853b3e275ecdaa27f78fda46dc273a7eb7fc1c8"

uglify-es@^3.3.4:
version "3.3.9"
Expand Down

0 comments on commit bdb6647

Please sign in to comment.