5 import { ITerminal, IBufferSet } from './Interfaces';
6 import { Buffer } from './Buffer';
7 import { EventEmitter } from './EventEmitter';
10 * The BufferSet represents the set of two buffers used by xterm terminals (normal and alt) and
11 * provides also utilities for working with them.
13 export class BufferSet extends EventEmitter implements IBufferSet {
14 private _normal: Buffer;
16 private _activeBuffer: Buffer;
19 * Create a new BufferSet for the given terminal.
20 * @param {Terminal} terminal - The terminal the BufferSet will belong to
22 constructor(private _terminal: ITerminal) {
24 this._normal = new Buffer(this._terminal);
25 this._normal.fillViewportRows();
26 this._alt = new Buffer(this._terminal);
27 this._activeBuffer = this._normal;
31 * Returns the alt Buffer of the BufferSet
34 public get alt(): Buffer {
39 * Returns the normal Buffer of the BufferSet
42 public get active(): Buffer {
43 return this._activeBuffer;
47 * Returns the currently active Buffer of the BufferSet
50 public get normal(): Buffer {
55 * Sets the normal Buffer of the BufferSet as its currently active Buffer
57 public activateNormalBuffer(): void {
58 // The alt buffer should always be cleared when we switch to the normal
59 // buffer. This frees up memory since the alt buffer should always be new
63 this._activeBuffer = this._normal;
64 this.emit('activate', this._normal);
68 * Sets the alt Buffer of the BufferSet as its currently active Buffer
70 public activateAltBuffer(): void {
71 // Since the alt buffer is always cleared when the normal buffer is
72 // activated, we want to fill it when switching to it.
73 this._alt.fillViewportRows();
75 this._activeBuffer = this._alt;
76 this.emit('activate', this._alt);
80 * Resizes both normal and alt buffers, adjusting their data accordingly.
81 * @param newCols The new number of columns.
82 * @param newRows The new number of rows.
84 public resize(newCols: number, newRows: number): void {
85 this._normal.resize(newCols, newRows);
86 this._alt.resize(newCols, newRows);