Don't pass buffers to BufferApiView

This commit is contained in:
Daniel Imms
2020-04-10 09:56:26 -07:00
parent 886af692e2
commit 4c36ef9d24
+13 -13
View File
@@ -193,19 +193,16 @@ export class Terminal implements ITerminalApi {
} }
class BufferApiView implements IBufferApi { class BufferApiView implements IBufferApi {
constructor(private _buffer: IBuffer, private _buffers: IBufferSet) { } constructor(
private _buffer: IBuffer,
public readonly type: 'normal' | 'alternate'
) { }
init(buffer: IBuffer, buffers: IBufferSet): BufferApiView { public init(buffer: IBuffer): BufferApiView {
this._buffer = buffer; this._buffer = buffer;
this._buffers = buffers;
return this; return this;
} }
public get type(): 'normal' | 'alternate' {
if (this._buffers.normal === this._buffer) { return 'normal'; }
if (this._buffers.alt === this._buffer) { return 'alternate'; }
throw new Error('Unknown buffer type');
}
public get cursorY(): number { return this._buffer.y; } public get cursorY(): number { return this._buffer.y; }
public get cursorX(): number { return this._buffer.x; } public get cursorX(): number { return this._buffer.x; }
public get viewportY(): number { return this._buffer.ydisp; } public get viewportY(): number { return this._buffer.ydisp; }
@@ -228,18 +225,21 @@ class BufferNamespaceApi implements IBufferNamespaceApi {
public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; } public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; }
constructor(private _buffers: IBufferSet) { constructor(private _buffers: IBufferSet) {
this._normal = new BufferApiView(this._buffers.normal, this._buffers); this._normal = new BufferApiView(this._buffers.normal, 'normal');
this._alternate = new BufferApiView(this._buffers.alt, this._buffers); this._alternate = new BufferApiView(this._buffers.alt, 'alternate');
this._buffers.onBufferActivate(() => this._onBufferChange.fire(this.active)); this._buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
} }
public get active(): IBufferApi { public get active(): IBufferApi {
if (this._buffers.active === this._buffers.normal) { return this.normal; } if (this._buffers.active === this._buffers.normal) { return this.normal; }
if (this._buffers.active === this._buffers.alt) { return this.alternate; } if (this._buffers.active === this._buffers.alt) { return this.alternate; }
throw new Error('Active buffer is neither normal nor alternate'); throw new Error('Active buffer is neither normal nor alternate');
} }
public get normal(): IBufferApi { return this._normal.init(this._buffers.normal, this._buffers); } public get normal(): IBufferApi {
public get alternate(): IBufferApi { return this._alternate.init(this._buffers.alt, this._buffers); } return this._normal.init(this._buffers.normal);
}
public get alternate(): IBufferApi {
return this._alternate.init(this._buffers.alt);
}
} }
class BufferLineApiView implements IBufferLineApi { class BufferLineApiView implements IBufferLineApi {