xterm
[VSoRC/.git] / node_modules / xterm / src / common / services / DirtyRowService.ts
1 /**
2  * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3  * @license MIT
4  */
5
6 import { IBufferService, IDirtyRowService } from 'common/services/Services';
7
8 export class DirtyRowService implements IDirtyRowService {
9   serviceBrand: any;
10
11   private _start!: number;
12   private _end!: number;
13
14   public get start(): number { return this._start; }
15   public get end(): number { return this._end; }
16
17   constructor(
18     @IBufferService private readonly _bufferService: IBufferService
19   ) {
20     this.clearRange();
21   }
22
23   public clearRange(): void {
24     this._start = this._bufferService.buffer.y;
25     this._end = this._bufferService.buffer.y;
26   }
27
28   public markDirty(y: number): void {
29     if (y < this._start) {
30       this._start = y;
31     } else if (y > this._end) {
32       this._end = y;
33     }
34   }
35
36   public markRangeDirty(y1: number, y2: number): void {
37     if (y1 > y2) {
38       const temp = y1;
39       y1 = y2;
40       y2 = temp;
41     }
42     if (y1 < this._start) {
43       this._start = y1;
44     }
45     if (y2 > this._end) {
46       this._end = y2;
47     }
48   }
49
50   public markAllDirty(): void {
51     this.markRangeDirty(0, this._bufferService.rows - 1);
52   }
53 }