xterm
[VSoRC/.git] / node_modules / xterm / src / browser / renderer / GridCache.ts
1 /**
2  * Copyright (c) 2017 The xterm.js authors. All rights reserved.
3  * @license MIT
4  */
5
6 export class GridCache<T> {
7   public cache: (T | undefined)[][];
8
9   public constructor() {
10     this.cache = [];
11   }
12
13   public resize(width: number, height: number): void {
14     for (let x = 0; x < width; x++) {
15       if (this.cache.length <= x) {
16         this.cache.push([]);
17       }
18       for (let y = this.cache[x].length; y < height; y++) {
19         this.cache[x].push(undefined);
20       }
21       this.cache[x].length = height;
22     }
23     this.cache.length = width;
24   }
25
26   public clear(): void {
27     for (let x = 0; x < this.cache.length; x++) {
28       for (let y = 0; y < this.cache[x].length; y++) {
29         this.cache[x][y] = undefined;
30       }
31     }
32   }
33 }