* Fit the terminal to its container * * Calculates optimal dimensions and resizes the terminal. * Does nothing if dimensions cannot be calculated or haven't changed.
()
| 82 | * Does nothing if dimensions cannot be calculated or haven't changed. |
| 83 | */ |
| 84 | public fit(): void { |
| 85 | // Prevent re-entrant calls during resize |
| 86 | if (this._isResizing) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | const dims = this.proposeDimensions(); |
| 91 | if (!dims || !this._terminal) { |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | // Access terminal to check current dimensions |
| 96 | const terminal = this._terminal as any; |
| 97 | const currentCols = terminal.cols; |
| 98 | const currentRows = terminal.rows; |
| 99 | |
| 100 | // Check if dimensions actually changed (prevent feedback loops) |
| 101 | // Compare against BOTH proposed dimensions AND current terminal dimensions |
| 102 | if ( |
| 103 | (dims.cols === this._lastCols && dims.rows === this._lastRows) || |
| 104 | (dims.cols === currentCols && dims.rows === currentRows) |
| 105 | ) { |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | // Store dimensions before resize |
| 110 | this._lastCols = dims.cols; |
| 111 | this._lastRows = dims.rows; |
| 112 | |
| 113 | // Set flag to prevent re-entrant calls |
| 114 | this._isResizing = true; |
| 115 | |
| 116 | try { |
| 117 | // Resize terminal |
| 118 | if (terminal.resize && typeof terminal.resize === 'function') { |
| 119 | terminal.resize(dims.cols, dims.rows); |
| 120 | } |
| 121 | } finally { |
| 122 | // Clear flag after a short delay to allow DOM to settle |
| 123 | setTimeout(() => { |
| 124 | this._isResizing = false; |
| 125 | }, 50); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Propose dimensions to fit the terminal to its container |
no test coverage detected