Replace EventEmitter usage in BufferSet
This commit is contained in:
+9
-6
@@ -3,25 +3,28 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ITerminal, IBufferSet } from './Types';
|
import { ITerminal, IBufferSet, IBuffer } from './Types';
|
||||||
import { Buffer } from './Buffer';
|
import { Buffer } from './Buffer';
|
||||||
import { EventEmitter } from './common/EventEmitter';
|
import { EventEmitter2, IEvent } from '../lib/common/EventEmitter2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The BufferSet represents the set of two buffers used by xterm terminals (normal and alt) and
|
* The BufferSet represents the set of two buffers used by xterm terminals (normal and alt) and
|
||||||
* provides also utilities for working with them.
|
* provides also utilities for working with them.
|
||||||
*/
|
*/
|
||||||
export class BufferSet extends EventEmitter implements IBufferSet {
|
export class BufferSet implements IBufferSet {
|
||||||
private _normal: Buffer;
|
private _normal: Buffer;
|
||||||
private _alt: Buffer;
|
private _alt: Buffer;
|
||||||
private _activeBuffer: Buffer;
|
private _activeBuffer: Buffer;
|
||||||
|
|
||||||
|
|
||||||
|
private _onBufferActivate = new EventEmitter2<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>();
|
||||||
|
public get onBufferActivate(): IEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}> { return this._onBufferActivate.event; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new BufferSet for the given terminal.
|
* Create a new BufferSet for the given terminal.
|
||||||
* @param _terminal - The terminal the BufferSet will belong to
|
* @param _terminal - The terminal the BufferSet will belong to
|
||||||
*/
|
*/
|
||||||
constructor(private _terminal: ITerminal) {
|
constructor(private _terminal: ITerminal) {
|
||||||
super();
|
|
||||||
this._normal = new Buffer(this._terminal, true);
|
this._normal = new Buffer(this._terminal, true);
|
||||||
this._normal.fillViewportRows();
|
this._normal.fillViewportRows();
|
||||||
|
|
||||||
@@ -68,7 +71,7 @@ export class BufferSet extends EventEmitter implements IBufferSet {
|
|||||||
// when activated.
|
// when activated.
|
||||||
this._alt.clear();
|
this._alt.clear();
|
||||||
this._activeBuffer = this._normal;
|
this._activeBuffer = this._normal;
|
||||||
this.emit('activate', {
|
this._onBufferActivate.fire({
|
||||||
activeBuffer: this._normal,
|
activeBuffer: this._normal,
|
||||||
inactiveBuffer: this._alt
|
inactiveBuffer: this._alt
|
||||||
});
|
});
|
||||||
@@ -87,7 +90,7 @@ export class BufferSet extends EventEmitter implements IBufferSet {
|
|||||||
this._alt.x = this._normal.x;
|
this._alt.x = this._normal.x;
|
||||||
this._alt.y = this._normal.y;
|
this._alt.y = this._normal.y;
|
||||||
this._activeBuffer = this._alt;
|
this._activeBuffer = this._alt;
|
||||||
this.emit('activate', {
|
this._onBufferActivate.fire({
|
||||||
activeBuffer: this._alt,
|
activeBuffer: this._alt,
|
||||||
inactiveBuffer: this._normal
|
inactiveBuffer: this._normal
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
|
|||||||
|
|
||||||
public initBuffersListeners(): void {
|
public initBuffersListeners(): void {
|
||||||
this._trimListener = this._terminal.buffer.lines.onTrim(amount => this._onTrim(amount));
|
this._trimListener = this._terminal.buffer.lines.onTrim(amount => this._onTrim(amount));
|
||||||
this._terminal.buffers.on('activate', e => this._onBufferActivate(e));
|
this._terminal.buffers.onBufferActivate(e => this._onBufferActivate(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -336,7 +336,6 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
|
|||||||
* @param amount The amount the buffer is being trimmed.
|
* @param amount The amount the buffer is being trimmed.
|
||||||
*/
|
*/
|
||||||
private _onTrim(amount: number): void {
|
private _onTrim(amount: number): void {
|
||||||
console.log('onTrim', amount);
|
|
||||||
const needsRefresh = this._model.onTrim(amount);
|
const needsRefresh = this._model.onTrim(amount);
|
||||||
if (needsRefresh) {
|
if (needsRefresh) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
|
|||||||
+4
-1
@@ -8,6 +8,7 @@ import { IColorSet, IRenderer } from './renderer/Types';
|
|||||||
import { IMouseZoneManager } from './ui/Types';
|
import { IMouseZoneManager } from './ui/Types';
|
||||||
import { ICharset } from './core/Types';
|
import { ICharset } from './core/Types';
|
||||||
import { ICircularList } from './common/Types';
|
import { ICircularList } from './common/Types';
|
||||||
|
import { IEvent } from '../lib/common/EventEmitter2';
|
||||||
|
|
||||||
export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean;
|
export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean;
|
||||||
|
|
||||||
@@ -302,11 +303,13 @@ export interface IBuffer {
|
|||||||
getWhitespaceCell(fg?: number, bg?: number): ICellData;
|
getWhitespaceCell(fg?: number, bg?: number): ICellData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBufferSet extends IEventEmitter {
|
export interface IBufferSet {
|
||||||
alt: IBuffer;
|
alt: IBuffer;
|
||||||
normal: IBuffer;
|
normal: IBuffer;
|
||||||
active: IBuffer;
|
active: IBuffer;
|
||||||
|
|
||||||
|
onBufferActivate: IEvent<{ activeBuffer: IBuffer, inactiveBuffer: IBuffer }>;
|
||||||
|
|
||||||
activateNormalBuffer(): void;
|
activateNormalBuffer(): void;
|
||||||
activateAltBuffer(fillAttr?: number): void;
|
activateAltBuffer(fillAttr?: number): void;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user