Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set this._buffer to new buffer #3204

Merged
merged 3 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/browser/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as Strings from '../LocalizableStrings';
import { IEvent, EventEmitter } from 'common/EventEmitter';
import { AddonManager } from './AddonManager';
import { IParams } from 'common/parser/Types';
import { BufferSet } from 'common/buffer/BufferSet';

export class Terminal implements ITerminalApi {
private _core: ITerminal;
Expand Down Expand Up @@ -60,7 +61,7 @@ export class Terminal implements ITerminalApi {
public get buffer(): IBufferNamespaceApi {
this._checkProposedApi();
if (!this._buffer) {
return new BufferNamespaceApi(this._core.buffers);
this._buffer = new BufferNamespaceApi(this._core);
}
return this._buffer;
}
Expand Down Expand Up @@ -249,21 +250,21 @@ class BufferNamespaceApi implements IBufferNamespaceApi {
private _onBufferChange = new EventEmitter<IBufferApi>();
public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; }

constructor(private _buffers: IBufferSet) {
this._normal = new BufferApiView(this._buffers.normal, 'normal');
this._alternate = new BufferApiView(this._buffers.alt, 'alternate');
this._buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
constructor(private _core: ITerminal) {
this._normal = new BufferApiView(this._core.buffers.normal, 'normal');
this._alternate = new BufferApiView(this._core.buffers.alt, 'alternate');
this._core.buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
}
public get active(): IBufferApi {
if (this._buffers.active === this._buffers.normal) { return this.normal; }
if (this._buffers.active === this._buffers.alt) { return this.alternate; }
if (this._core.buffers.active === this._core.buffers.normal) { return this.normal; }
if (this._core.buffers.active === this._core.buffers.alt) { return this.alternate; }
throw new Error('Active buffer is neither normal nor alternate');
}
public get normal(): IBufferApi {
return this._normal.init(this._buffers.normal);
return this._normal.init(this._core.buffers.normal);
}
public get alternate(): IBufferApi {
return this._alternate.init(this._buffers.alt);
return this._alternate.init(this._core.buffers.alt);
}
}

Expand Down
18 changes: 10 additions & 8 deletions src/common/buffer/BufferSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import { Disposable } from 'common/Lifecycle';
* provides also utilities for working with them.
*/
export class BufferSet extends Disposable implements IBufferSet {
private _normal: Buffer;
private _alt: Buffer;
private _activeBuffer: Buffer;

private _normal!: Buffer;
private _alt!: Buffer;
private _activeBuffer!: Buffer;

private _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>());
public get onBufferActivate(): IEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}> { return this._onBufferActivate.event; }
Expand All @@ -28,17 +27,20 @@ export class BufferSet extends Disposable implements IBufferSet {
* @param _terminal - The terminal the BufferSet will belong to
*/
constructor(
optionsService: IOptionsService,
bufferService: IBufferService
private readonly _optionsService: IOptionsService,
private readonly _bufferService: IBufferService
) {
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();

// The alt buffer should never have scrollback.
// 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.setupTabStops();
Expand Down
1 change: 1 addition & 0 deletions src/common/buffer/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface IBufferSet extends IDisposable {

activateNormalBuffer(): void;
activateAltBuffer(fillAttr?: IAttributeData): void;
reset(): void;
resize(newCols: number, newRows: number): void;
setupTabStops(i?: number): void;
}
3 changes: 1 addition & 2 deletions src/common/services/BufferService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export class BufferService extends Disposable implements IBufferService {
}

public reset(): void {
this.buffers.dispose();
this.buffers = new BufferSet(this._optionsService, this);
this.buffers.reset();
this.isUserScrolling = false;
}
}