Debian Codegraph @

node/@xterm/xterm/src/common/public/BufferNamespaceApi.ts

raw
1 /**
2 * Copyright (c) 2021 The xterm.js authors. All rights reserved.
3 * @license MIT
4 */
5
6 import { IBuffer as IBufferApi, IBufferNamespace as IBufferNamespaceApi } from '@xterm/xterm';
7 import { BufferApiView } from 'common/public/BufferApiView';
8 import { ICoreTerminal } from 'common/Types';
9 import { Disposable } from 'vs/base/common/lifecycle';
10 import { Emitter } from 'vs/base/common/event';
11
12 export class BufferNamespaceApi extends Disposable implements IBufferNamespaceApi {
13 private _normal: BufferApiView;
14 private _alternate: BufferApiView;
15
16 private readonly _onBufferChange = this._register(new Emitter<IBufferApi>());
17 public readonly onBufferChange = this._onBufferChange.event;
18
19 constructor(private _core: ICoreTerminal) {
20 super();
21 this._normal = new BufferApiView(this._core.buffers.normal, 'normal');
22 this._alternate = new BufferApiView(this._core.buffers.alt, 'alternate');
23 this._core.buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
24 }
25 public get active(): IBufferApi {
26 if (this._core.buffers.active === this._core.buffers.normal) { return this.normal; }
27 if (this._core.buffers.active === this._core.buffers.alt) { return this.alternate; }
28 throw new Error('Active buffer is neither normal nor alternate');
29 }
30 public get normal(): IBufferApi {
31 return this._normal.init(this._core.buffers.normal);
32 }
33 public get alternate(): IBufferApi {
34 return this._alternate.init(this._core.buffers.alt);
35 }
36 }