]> git.proxmox.com Git - mirror_xterm.js.git/blob - src/BufferSet.ts
4a65dbfe16e984aa3da41e29da225dea681aa8c4
[mirror_xterm.js.git] / src / BufferSet.ts
1 /**
2 * @license MIT
3 */
4
5 import { ITerminal, IBufferSet } from './Interfaces';
6 import { Buffer } from './Buffer';
7 import { EventEmitter } from './EventEmitter';
8
9 /**
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.
12 */
13 export class BufferSet extends EventEmitter implements IBufferSet {
14 private _normal: Buffer;
15 private _alt: Buffer;
16 private _activeBuffer: Buffer;
17
18 /**
19 * Create a new BufferSet for the given terminal.
20 * @param {Terminal} terminal - The terminal the BufferSet will belong to
21 */
22 constructor(private _terminal: ITerminal) {
23 super();
24 this._normal = new Buffer(this._terminal);
25 this._alt = new Buffer(this._terminal);
26 this._activeBuffer = this._normal;
27 }
28
29 /**
30 * Returns the alt Buffer of the BufferSet
31 * @returns {Buffer}
32 */
33 public get alt(): Buffer {
34 return this._alt;
35 }
36
37 /**
38 * Returns the normal Buffer of the BufferSet
39 * @returns {Buffer}
40 */
41 public get active(): Buffer {
42 return this._activeBuffer;
43 }
44
45 /**
46 * Returns the currently active Buffer of the BufferSet
47 * @returns {Buffer}
48 */
49 public get normal(): Buffer {
50 return this._normal;
51 }
52
53 /**
54 * Sets the normal Buffer of the BufferSet as its currently active Buffer
55 */
56 public activateNormalBuffer(): void {
57 this._activeBuffer = this._normal;
58 this.emit('activate', this._normal);
59 }
60
61 /**
62 * Sets the alt Buffer of the BufferSet as its currently active Buffer
63 */
64 public activateAltBuffer(): void {
65 this._activeBuffer = this._alt;
66 this.emit('activate', this._alt);
67 }
68
69 public resize(newCols: number, newRows: number): void {
70 this._normal.resize(newCols, newRows);
71 this._alt.resize(newCols, newRows);
72 }
73 }