fix(ui): Correct footer measurement and prevent negative terminal height (#8362)

This commit is contained in:
Gal Zahavi
2025-09-12 22:42:17 -07:00
committed by GitHub
parent 5a05fb0dd0
commit 087c192e51
2 changed files with 74 additions and 15 deletions
+25 -15
View File
@@ -4,7 +4,14 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { useMemo, useState, useCallback, useEffect, useRef } from 'react';
import {
useMemo,
useState,
useCallback,
useEffect,
useRef,
useLayoutEffect,
} from 'react';
import { type DOMElement, measureElement } from 'ink';
import { App } from './App.js';
import { AppContext } from './contexts/AppContext.js';
@@ -622,18 +629,27 @@ Logging in with Google... Please restart Gemini CLI to continue.
streamingState === StreamingState.Responding) &&
!proQuotaRequest;
// Compute available terminal height based on controls measurement
const availableTerminalHeight = useMemo(() => {
const [controlsHeight, setControlsHeight] = useState(0);
useLayoutEffect(() => {
if (mainControlsRef.current) {
const fullFooterMeasurement = measureElement(mainControlsRef.current);
return terminalHeight - fullFooterMeasurement.height - staticExtraHeight;
if (fullFooterMeasurement.height > 0) {
setControlsHeight(fullFooterMeasurement.height);
}
}
return terminalHeight - staticExtraHeight;
}, [terminalHeight]);
}, [buffer, terminalWidth, terminalHeight]);
// Compute available terminal height based on controls measurement
const availableTerminalHeight =
terminalHeight - controlsHeight - staticExtraHeight;
config.setShellExecutionConfig({
terminalWidth: Math.floor(terminalWidth * SHELL_WIDTH_FRACTION),
terminalHeight: Math.floor(availableTerminalHeight - SHELL_HEIGHT_PADDING),
terminalHeight: Math.max(
Math.floor(availableTerminalHeight - SHELL_HEIGHT_PADDING),
1,
),
pager: settings.merged.tools?.shell?.pager,
showColor: settings.merged.tools?.shell?.showColor,
});
@@ -660,16 +676,10 @@ Logging in with Google... Please restart Gemini CLI to continue.
ShellExecutionService.resizePty(
activePtyId,
Math.floor(terminalWidth * SHELL_WIDTH_FRACTION),
Math.floor(availableTerminalHeight - SHELL_HEIGHT_PADDING),
Math.max(Math.floor(availableTerminalHeight - SHELL_HEIGHT_PADDING), 1),
);
}
}, [
terminalHeight,
terminalWidth,
availableTerminalHeight,
activePtyId,
geminiClient,
]);
}, [terminalWidth, availableTerminalHeight, activePtyId]);
useEffect(() => {
if (