Skip to content

Commit

Permalink
Merge pull request #2211 from Tyriar/remove_ee
Browse files Browse the repository at this point in the history
Remove old event emitter, rename new one to EventEmitter
  • Loading branch information
Tyriar committed Jun 9, 2019
2 parents 58ec3f9 + 07cef1e commit 1621700
Show file tree
Hide file tree
Showing 28 changed files with 161 additions and 604 deletions.
4 changes: 2 additions & 2 deletions addons/xterm-addon-attach/src/AttachAddon.api.ts
Expand Up @@ -17,7 +17,7 @@ const height = 600;

describe('AttachAddon', () => {
before(async function(): Promise<any> {
this.timeout(10000);
this.timeout(20000);
browser = await puppeteer.launch({
headless: process.argv.indexOf('--headless') !== -1,
slowMo: 80,
Expand All @@ -32,7 +32,7 @@ describe('AttachAddon', () => {
});

beforeEach(async function(): Promise<any> {
this.timeout(5000);
this.timeout(20000);
await page.goto(APP);
});

Expand Down
6 changes: 3 additions & 3 deletions src/AccessibilityManager.ts
Expand Up @@ -85,11 +85,11 @@ export class AccessibilityManager extends Disposable {
this.register(this._terminal.onRender(e => this._refreshRows(e.start, e.end)));
this.register(this._terminal.onScroll(() => this._refreshRows()));
// Line feed is an issue as the prompt won't be read out after a command is run
this.register(this._terminal.addDisposableListener('a11y.char', (char) => this._onChar(char)));
this.register(this._terminal.onA11yChar(char => this._onChar(char)));
this.register(this._terminal.onLineFeed(() => this._onChar('\n')));
this.register(this._terminal.addDisposableListener('a11y.tab', spaceCount => this._onTab(spaceCount)));
this.register(this._terminal.onA11yTab(spaceCount => this._onTab(spaceCount)));
this.register(this._terminal.onKey(e => this._onKey(e.key)));
this.register(this._terminal.addDisposableListener('blur', () => this._clearLiveRegion()));
this.register(this._terminal.onBlur(() => this._clearLiveRegion()));

this._screenDprMonitor = new ScreenDprMonitor();
this.register(this._screenDprMonitor);
Expand Down
1 change: 0 additions & 1 deletion src/Clipboard.ts
Expand Up @@ -63,7 +63,6 @@ export function pasteHandler(ev: ClipboardEvent, term: ITerminal): void {
text = bracketTextForPaste(text, term.bracketedPasteMode);
term.handler(text);
term.textarea.value = '';
term.emit('paste', text);
term.cancel(ev);
};

Expand Down
16 changes: 8 additions & 8 deletions src/InputHandler.ts
Expand Up @@ -14,7 +14,7 @@ import { Disposable } from 'common/Lifecycle';
import { concat } from 'common/TypedArrayUtils';
import { StringToUtf32, stringFromCodePoint, utf32ToString, Utf8ToUtf32 } from 'common/input/TextDecoder';
import { CellData, Attributes, FgFlags, BgFlags, AttributeData, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
import { EventEmitter2, IEvent } from 'common/EventEmitter2';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { IParsingState, IDcsHandler, IEscapeSequenceParser } from 'common/parser/Types';

/**
Expand Down Expand Up @@ -108,13 +108,13 @@ export class InputHandler extends Disposable implements IInputHandler {
private _utf8Decoder: Utf8ToUtf32 = new Utf8ToUtf32();
private _workCell: CellData = new CellData();

private _onCursorMove = new EventEmitter2<void>();
private _onCursorMove = new EventEmitter<void>();
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
private _onData = new EventEmitter2<string>();
private _onData = new EventEmitter<string>();
public get onData(): IEvent<string> { return this._onData.event; }
private _onLineFeed = new EventEmitter2<void>();
private _onLineFeed = new EventEmitter<void>();
public get onLineFeed(): IEvent<void> { return this._onLineFeed.event; }
private _onScroll = new EventEmitter2<number>();
private _onScroll = new EventEmitter<number>();
public get onScroll(): IEvent<number> { return this._onScroll.event; }

constructor(
Expand Down Expand Up @@ -342,7 +342,7 @@ export class InputHandler extends Disposable implements IInputHandler {

buffer = this._terminal.buffer;
if (buffer.x !== cursorStartX || buffer.y !== cursorStartY) {
this._terminal.emit('cursormove');
this._onCursorMove.fire();
}
}

Expand Down Expand Up @@ -377,7 +377,7 @@ export class InputHandler extends Disposable implements IInputHandler {
}

if (screenReaderMode) {
this._terminal.emit('a11y.char', stringFromCodePoint(code));
this._terminal.onA11yCharEmitter.fire(stringFromCodePoint(code));
}

// insert combining char at last cursor position
Expand Down Expand Up @@ -542,7 +542,7 @@ export class InputHandler extends Disposable implements IInputHandler {
const originalX = this._terminal.buffer.x;
this._terminal.buffer.x = this._terminal.buffer.nextStop();
if (this._terminal.options.screenReaderMode) {
this._terminal.emit('a11y.tab', this._terminal.buffer.x - originalX);
this._terminal.onA11yTabEmitter.fire(this._terminal.buffer.x - originalX);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Linkifier.ts
Expand Up @@ -7,7 +7,7 @@ import { ILinkifierEvent, ILinkMatcher, LinkMatcherHandler, ILinkMatcherOptions,
import { IBufferStringIteratorResult } from 'common/buffer/Types';
import { MouseZone } from './MouseZoneManager';
import { getStringCellWidth } from 'common/CharWidth';
import { EventEmitter2, IEvent } from 'common/EventEmitter2';
import { EventEmitter, IEvent } from 'common/EventEmitter';

/**
* The Linkifier applies links to rows shortly after they have been refreshed.
Expand All @@ -34,11 +34,11 @@ export class Linkifier implements ILinkifier {
private _nextLinkMatcherId = 0;
private _rowsToLinkify: { start: number, end: number };

private _onLinkHover = new EventEmitter2<ILinkifierEvent>();
private _onLinkHover = new EventEmitter<ILinkifierEvent>();
public get onLinkHover(): IEvent<ILinkifierEvent> { return this._onLinkHover.event; }
private _onLinkLeave = new EventEmitter2<ILinkifierEvent>();
private _onLinkLeave = new EventEmitter<ILinkifierEvent>();
public get onLinkLeave(): IEvent<ILinkifierEvent> { return this._onLinkLeave.event; }
private _onLinkTooltip = new EventEmitter2<ILinkifierEvent>();
private _onLinkTooltip = new EventEmitter<ILinkifierEvent>();
public get onLinkTooltip(): IEvent<ILinkifierEvent> { return this._onLinkTooltip.event; }

constructor(
Expand Down
8 changes: 4 additions & 4 deletions src/SelectionManager.ts
Expand Up @@ -12,7 +12,7 @@ import { SelectionModel } from './SelectionModel';
import { AltClickHandler } from './handlers/AltClickHandler';
import { CellData } from 'common/buffer/BufferLine';
import { IDisposable } from 'xterm';
import { EventEmitter2, IEvent } from 'common/EventEmitter2';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { ICharSizeService } from 'browser/services/Services';
import { IBufferService } from 'common/services/Services';

Expand Down Expand Up @@ -110,11 +110,11 @@ export class SelectionManager implements ISelectionManager {

private _mouseDownTimeStamp: number;

private _onLinuxMouseSelection = new EventEmitter2<string>();
private _onLinuxMouseSelection = new EventEmitter<string>();
public get onLinuxMouseSelection(): IEvent<string> { return this._onLinuxMouseSelection.event; }
private _onRedrawRequest = new EventEmitter2<ISelectionRedrawRequestEvent>();
private _onRedrawRequest = new EventEmitter<ISelectionRedrawRequestEvent>();
public get onRedrawRequest(): IEvent<ISelectionRedrawRequestEvent> { return this._onRedrawRequest.event; }
private _onSelectionChange = new EventEmitter2<void>();
private _onSelectionChange = new EventEmitter<void>();
public get onSelectionChange(): IEvent<void> { return this._onSelectionChange.event; }

constructor(
Expand Down
176 changes: 12 additions & 164 deletions src/Terminal.test.ts
Expand Up @@ -57,20 +57,20 @@ describe('Terminal', () => {
term.handler('fake');
});
it('should fire the onCursorMove event', (done) => {
term.on('cursormove', () => done());
term.onCursorMove(() => done());
term.write('foo');
});
it('should fire the onLineFeed event', (done) => {
term.on('linefeed', () => done());
term.onLineFeed(() => done());
term.write('\n');
});
it('should fire a scroll event when scrollback is created', (done) => {
term.on('scroll', () => done());
term.onScroll(() => done());
term.write('\n'.repeat(INIT_ROWS));
});
it('should fire a scroll event when scrollback is cleared', (done) => {
term.write('\n'.repeat(INIT_ROWS));
term.on('scroll', () => done());
term.onScroll(() => done());
term.clear();
});
it('should fire a key event after a keypress DOM event', (done) => {
Expand Down Expand Up @@ -126,158 +126,6 @@ describe('Terminal', () => {
});
});

describe('on', () => {
beforeEach(() => {
term.on('key', () => { });
term.on('keypress', () => { });
term.on('keydown', () => { });
});

describe('data', () => {
it('should emit a data event', (done) => {
term.on('data', () => {
done();
});

term.handler('fake');
});
});

describe('cursormove', () => {
it('should emit a cursormove event', (done) => {
term.on('cursormove', () => {
done();
});
term.write('foo');
});
});

describe('linefeed', () => {
it('should emit a linefeed event', (done) => {
term.on('linefeed', () => {
done();
});
term.write('\n');
});
});

describe('scroll', () => {
it('should emit a scroll event when scrollback is created', (done) => {
term.on('scroll', () => {
done();
});
term.write('\n'.repeat(INIT_ROWS));
});
it('should emit a scroll event when scrollback is cleared', (done) => {
term.write('\n'.repeat(INIT_ROWS));
term.on('scroll', () => {
done();
});
term.clear();
});
});

describe(`keypress (including 'key' event)`, () => {
it('should receive a string and event object', (done) => {
let steps = 0;

const finish = () => {
if ((++steps) === 2) {
done();
}
};

const evKeyPress = <KeyboardEvent>{
preventDefault: () => { },
stopPropagation: () => { },
type: 'keypress',
keyCode: 13
};

term.on('keypress', (key, event) => {
assert.equal(typeof key, 'string');
expect(event).to.be.an.instanceof(Object);
finish();
});

term.on('key', (key, event) => {
assert.equal(typeof key, 'string');
expect(event).to.be.an.instanceof(Object);
finish();
});

term.keyPress(evKeyPress);
});
});

describe(`keydown (including 'key' event)`, () => {
it(`should receive an event object for 'keydown' and a string and event object for 'key'`, (done) => {
let steps = 0;

const finish = () => {
if ((++steps) === 2) {
done();
}
};

const evKeyDown = <KeyboardEvent>{
preventDefault: () => { },
stopPropagation: () => { },
type: 'keydown',
keyCode: 13
};

term.on('keydown', (event) => {
expect(event).to.be.an.instanceof(Object);
finish();
});

term.on('key', (key, event) => {
assert.equal(typeof key, 'string');
expect(event).to.be.an.instanceof(Object);
finish();
});

term.keyDown(evKeyDown);
});
});

describe('resize', () => {
it('should receive an object: {cols: number, rows: number}', (done) => {
term.on('resize', (data) => {
expect(data).to.have.keys(['cols', 'rows']);
assert.equal(typeof data.cols, 'number');
assert.equal(typeof data.rows, 'number');
done();
});

term.resize(1, 1);
});
});

describe('scroll', () => {
it('should receive a number', (done) => {
term.on('scroll', (ydisp) => {
assert.equal(typeof ydisp, 'number');
done();
});

term.scroll();
});
});

describe('title', () => {
it('should receive a string', (done) => {
term.on('title', (title) => {
assert.equal(typeof title, 'string');
done();
});

term.handleTitle('title');
});
});
});

describe('attachCustomKeyEventHandler', () => {
const evKeyDown = <KeyboardEvent>{
preventDefault: () => { },
Expand Down Expand Up @@ -741,10 +589,10 @@ describe('Terminal', () => {
it('should emit key with alt + key on keyPress', (done) => {
const keys = ['@', '@', '\\', '\\', '|', '|'];

term.on('keypress', (key) => {
if (key) {
const index = keys.indexOf(key);
assert(index !== -1, 'Emitted wrong key: ' + key);
term.onKey(e => {
if (e.key) {
const index = keys.indexOf(e.key);
assert(index !== -1, 'Emitted wrong key: ' + e.key);
keys.splice(index, 1);
}
if (keys.length === 0) done();
Expand Down Expand Up @@ -807,10 +655,10 @@ describe('Terminal', () => {
it('should emit key with alt + ctrl + key on keyPress', (done) => {
const keys = ['@', '@', '\\', '\\', '|', '|'];

term.on('keypress', (key) => {
if (key) {
const index = keys.indexOf(key);
assert(index !== -1, 'Emitted wrong key: ' + key);
term.onKey(e => {
if (e.key) {
const index = keys.indexOf(e.key);
assert(index !== -1, 'Emitted wrong key: ' + e.key);
keys.splice(index, 1);
}
if (keys.length === 0) done();
Expand Down

0 comments on commit 1621700

Please sign in to comment.