Convert cursormove to EventEmitter2

This commit is contained in:
Daniel Imms
2019-04-09 19:31:59 -07:00
parent a86c2943b8
commit 8e5d372b81
3 changed files with 19 additions and 3 deletions
+5 -1
View File
@@ -15,6 +15,7 @@ import { Disposable } from './common/Lifecycle';
import { concat } from './common/TypedArrayUtils';
import { StringToUtf32, stringFromCodePoint, utf32ToString } from './core/input/TextDecoder';
import { CellData, Attributes, FgFlags, BgFlags, AttributeData } from './BufferLine';
import { EventEmitter2, IEvent } from './common/EventEmitter2';
/**
* Map collect to glevel. Used in `selectCharset`.
@@ -106,6 +107,9 @@ export class InputHandler extends Disposable implements IInputHandler {
private _stringDecoder: StringToUtf32 = new StringToUtf32();
private _workCell: CellData = new CellData();
private _onCursorMove = new EventEmitter2<void>();
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
constructor(
protected _terminal: IInputHandlingTerminal,
private _parser: IEscapeSequenceParser = new EscapeSequenceParser())
@@ -305,7 +309,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();
}
}
+10
View File
@@ -85,6 +85,16 @@ describe('term.js addons', () => {
});
});
describe('cursormove', () => {
it('should emit a cursormove event', (done) => {
term.on('cursormove', () => {
done();
});
term.write('foo');
});
});
describe(`keypress (including 'key' event)`, () => {
it('should receive a string and event object', (done) => {
let steps = 0;
+4 -2
View File
@@ -261,7 +261,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this._setup();
// TODO: Replace EventEmitter with EventEmitter2 internally
this.on('cursormove', () => this._onCursorMove.fire());
this.on('linefeed', () => this._onLineFeed.fire());
this.on('selection', () => this._onSelectionChange.fire());
this.on('data', e => this._onInput.fire(e));
@@ -270,6 +269,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
// TODO: Remove these in v4
// Fire old style events from new emitters
this.onCursorMove(() => this.emit('cursormove'));
this.onKey(e => this.emit('key', e.key, e.domEvent));
this.onResize(e => this.emit('resize', e));
this.onTitleChange(e => this.emit('title', e));
@@ -350,7 +350,9 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this._userScrolling = false;
this._inputHandler = new InputHandler(this);
this._inputHandler.onCursorMove(() => this._onCursorMove.fire());
this.register(this._inputHandler);
// Reuse renderer if the Terminal is being recreated via a reset call.
this.renderer = this.renderer || null;
this.selectionManager = this.selectionManager || null;
@@ -769,7 +771,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this.viewport.onThemeChanged(this.renderer.colorManager.colors);
this.register(this.viewport);
this.register(this.addDisposableListener('cursormove', () => this.renderer.onCursorMove()));
this.register(this.onCursorMove(() => this.renderer.onCursorMove()));
this.register(this.onResize(() => this.renderer.onResize(this.cols, this.rows)));
this.register(this.addDisposableListener('blur', () => this.renderer.onBlur()));
this.register(this.addDisposableListener('focus', () => this.renderer.onFocus()));