Merge pull request #3204 from meganrogge/master

set this._buffer to new buffer
This commit is contained in:
Daniel Imms
2021-01-05 10:20:57 -08:00
committed by GitHub
4 changed files with 22 additions and 19 deletions
+10 -9
View File
@@ -13,6 +13,7 @@ import * as Strings from '../LocalizableStrings';
import { IEvent, EventEmitter } from 'common/EventEmitter'; import { IEvent, EventEmitter } from 'common/EventEmitter';
import { AddonManager } from './AddonManager'; import { AddonManager } from './AddonManager';
import { IParams } from 'common/parser/Types'; import { IParams } from 'common/parser/Types';
import { BufferSet } from 'common/buffer/BufferSet';
export class Terminal implements ITerminalApi { export class Terminal implements ITerminalApi {
private _core: ITerminal; private _core: ITerminal;
@@ -60,7 +61,7 @@ export class Terminal implements ITerminalApi {
public get buffer(): IBufferNamespaceApi { public get buffer(): IBufferNamespaceApi {
this._checkProposedApi(); this._checkProposedApi();
if (!this._buffer) { if (!this._buffer) {
return new BufferNamespaceApi(this._core.buffers); this._buffer = new BufferNamespaceApi(this._core);
} }
return this._buffer; return this._buffer;
} }
@@ -249,21 +250,21 @@ class BufferNamespaceApi implements IBufferNamespaceApi {
private _onBufferChange = new EventEmitter<IBufferApi>(); private _onBufferChange = new EventEmitter<IBufferApi>();
public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; } public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; }
constructor(private _buffers: IBufferSet) { constructor(private _core: ITerminal) {
this._normal = new BufferApiView(this._buffers.normal, 'normal'); this._normal = new BufferApiView(this._core.buffers.normal, 'normal');
this._alternate = new BufferApiView(this._buffers.alt, 'alternate'); this._alternate = new BufferApiView(this._core.buffers.alt, 'alternate');
this._buffers.onBufferActivate(() => this._onBufferChange.fire(this.active)); this._core.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._core.buffers.active === this._core.buffers.normal) { return this.normal; }
if (this._buffers.active === this._buffers.alt) { return this.alternate; } if (this._core.buffers.active === this._core.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 { public get normal(): IBufferApi {
return this._normal.init(this._buffers.normal); return this._normal.init(this._core.buffers.normal);
} }
public get alternate(): IBufferApi { public get alternate(): IBufferApi {
return this._alternate.init(this._buffers.alt); return this._alternate.init(this._core.buffers.alt);
} }
} }
+10 -8
View File
@@ -15,10 +15,9 @@ import { Disposable } from 'common/Lifecycle';
* provides also utilities for working with them. * provides also utilities for working with them.
*/ */
export class BufferSet extends Disposable implements IBufferSet { export class BufferSet extends Disposable implements IBufferSet {
private _normal: Buffer; private _normal!: Buffer;
private _alt: Buffer; private _alt!: Buffer;
private _activeBuffer: Buffer; private _activeBuffer!: Buffer;
private _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>()); private _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>());
public get onBufferActivate(): IEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}> { return this._onBufferActivate.event; } public get onBufferActivate(): IEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}> { return this._onBufferActivate.event; }
@@ -28,17 +27,20 @@ export class BufferSet extends Disposable implements IBufferSet {
* @param _terminal - The terminal the BufferSet will belong to * @param _terminal - The terminal the BufferSet will belong to
*/ */
constructor( constructor(
optionsService: IOptionsService, private readonly _optionsService: IOptionsService,
bufferService: IBufferService private readonly _bufferService: IBufferService
) { ) {
super(); super();
this.reset();
}
this._normal = new Buffer(true, optionsService, bufferService); public reset(): void {
this._normal = new Buffer(true, this._optionsService, this._bufferService);
this._normal.fillViewportRows(); this._normal.fillViewportRows();
// The alt buffer should never have scrollback. // The alt buffer should never have scrollback.
// See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer // See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
this._alt = new Buffer(false, optionsService, bufferService); this._alt = new Buffer(false, this._optionsService, this._bufferService);
this._activeBuffer = this._normal; this._activeBuffer = this._normal;
this.setupTabStops(); this.setupTabStops();
+1
View File
@@ -56,6 +56,7 @@ export interface IBufferSet extends IDisposable {
activateNormalBuffer(): void; activateNormalBuffer(): void;
activateAltBuffer(fillAttr?: IAttributeData): void; activateAltBuffer(fillAttr?: IAttributeData): void;
reset(): void;
resize(newCols: number, newRows: number): void; resize(newCols: number, newRows: number): void;
setupTabStops(i?: number): void; setupTabStops(i?: number): void;
} }
+1 -2
View File
@@ -49,8 +49,7 @@ export class BufferService extends Disposable implements IBufferService {
} }
public reset(): void { public reset(): void {
this.buffers.dispose(); this.buffers.reset();
this.buffers = new BufferSet(this._optionsService, this);
this.isUserScrolling = false; this.isUserScrolling = false;
} }
} }