aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/xterm/src/browser/RenderDebouncer.ts
diff options
context:
space:
mode:
authorAnthony Schneider <tonyschneider3@gmail.com>2022-02-11 19:40:35 -0600
committerAnthony Schneider <tonyschneider3@gmail.com>2022-02-11 19:40:35 -0600
commitb52feccdcc58c1f4583c8542632d6c026335dea7 (patch)
tree5e242dd13ed4bbfff85a07109ef826f80874e2a6 /node_modules/xterm/src/browser/RenderDebouncer.ts
parent94862321e2e4a58e3209c037e8061f0435b3aa82 (diff)
Changed javascript to be in its own file. Began (messy) setup for terminal.
Diffstat (limited to 'node_modules/xterm/src/browser/RenderDebouncer.ts')
-rw-r--r--node_modules/xterm/src/browser/RenderDebouncer.ts63
1 files changed, 63 insertions, 0 deletions
diff --git a/node_modules/xterm/src/browser/RenderDebouncer.ts b/node_modules/xterm/src/browser/RenderDebouncer.ts
new file mode 100644
index 0000000..0252107
--- /dev/null
+++ b/node_modules/xterm/src/browser/RenderDebouncer.ts
@@ -0,0 +1,63 @@
+/**
+ * Copyright (c) 2018 The xterm.js authors. All rights reserved.
+ * @license MIT
+ */
+
+import { IRenderDebouncer } from 'browser/Types';
+
+/**
+ * Debounces calls to render terminal rows using animation frames.
+ */
+export class RenderDebouncer implements IRenderDebouncer {
+ private _rowStart: number | undefined;
+ private _rowEnd: number | undefined;
+ private _rowCount: number | undefined;
+ private _animationFrame: number | undefined;
+
+ constructor(
+ private _renderCallback: (start: number, end: number) => void
+ ) {
+ }
+
+ public dispose(): void {
+ if (this._animationFrame) {
+ window.cancelAnimationFrame(this._animationFrame);
+ this._animationFrame = undefined;
+ }
+ }
+
+ public refresh(rowStart: number | undefined, rowEnd: number | undefined, rowCount: number): void {
+ this._rowCount = rowCount;
+ // Get the min/max row start/end for the arg values
+ rowStart = rowStart !== undefined ? rowStart : 0;
+ rowEnd = rowEnd !== undefined ? rowEnd : this._rowCount - 1;
+ // Set the properties to the updated values
+ this._rowStart = this._rowStart !== undefined ? Math.min(this._rowStart, rowStart) : rowStart;
+ this._rowEnd = this._rowEnd !== undefined ? Math.max(this._rowEnd, rowEnd) : rowEnd;
+
+ if (this._animationFrame) {
+ return;
+ }
+
+ this._animationFrame = window.requestAnimationFrame(() => this._innerRefresh());
+ }
+
+ private _innerRefresh(): void {
+ // Make sure values are set
+ if (this._rowStart === undefined || this._rowEnd === undefined || this._rowCount === undefined) {
+ return;
+ }
+
+ // Clamp values
+ const start = Math.max(this._rowStart, 0);
+ const end = Math.min(this._rowEnd, this._rowCount - 1);
+
+ // Reset debouncer (this happens before render callback as the render could trigger it again)
+ this._rowStart = undefined;
+ this._rowEnd = undefined;
+ this._animationFrame = undefined;
+
+ // Run render callback
+ this._renderCallback(start, end);
+ }
+}