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