From b0bc7c3d996d25c9fefdfbcba3ca19fa46ad199f Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Thu, 19 Jun 2025 20:17:23 +0000 Subject: Fix flicker issues by ensuring all actively changing content fits in the viewport (#1217) --- packages/cli/src/ui/App.tsx | 47 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'packages/cli/src/ui/App.tsx') diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx index a5317b30..a9c5f0e7 100644 --- a/packages/cli/src/ui/App.tsx +++ b/packages/cli/src/ui/App.tsx @@ -115,6 +115,7 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { const ctrlCTimerRef = useRef(null); const [ctrlDPressedOnce, setCtrlDPressedOnce] = useState(false); const ctrlDTimerRef = useRef(null); + const [constrainHeight, setConstrainHeight] = useState(true); const errorCount = useMemo( () => consoleMessages.filter((msg) => msg.type === 'error').length, @@ -217,7 +218,7 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { const widthFraction = 0.9; const inputWidth = Math.max( 20, - Math.round(terminalWidth * widthFraction) - 3, + Math.floor(terminalWidth * widthFraction) - 3, ); const suggestionsWidth = Math.max(60, Math.floor(terminalWidth * 0.8)); @@ -279,6 +280,8 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { return; } handleExit(ctrlDPressedOnce, setCtrlDPressedOnce, ctrlDTimerRef); + } else if (key.ctrl && input === 's') { + setConstrainHeight((prev) => !prev); } }); @@ -393,10 +396,11 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { } }, [terminalHeight, consoleMessages, showErrorDetails]); - const availableTerminalHeight = useMemo(() => { - const staticExtraHeight = /* margins and padding */ 3; - return terminalHeight - footerHeight - staticExtraHeight; - }, [terminalHeight, footerHeight]); + const staticExtraHeight = /* margins and padding */ 3; + const availableTerminalHeight = useMemo( + () => terminalHeight - footerHeight - staticExtraHeight, + [terminalHeight, footerHeight], + ); useEffect(() => { if (!pendingHistoryItems.length) { @@ -445,7 +449,10 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { {quittingMessages.map((item) => ( { ); } - + const mainAreaWidth = Math.floor(terminalWidth * 0.9); + const debugConsoleMaxHeight = Math.max(terminalHeight * 0.2, 5); + // Arbitrary threshold to ensure that items in the static area are large + // enough but not too large to make the terminal hard to use. + const staticAreaMaxItemHeight = Math.max(terminalHeight * 4, 100); return ( @@ -479,7 +490,8 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { , ...history.map((h) => ( { {pendingHistoryItems.map((item, i) => ( { onSelect={handleThemeSelect} onHighlight={handleThemeHighlight} settings={settings} + availableTerminalHeight={ + constrainHeight + ? terminalHeight - staticExtraHeight + : undefined + } + terminalWidth={mainAreaWidth} /> ) : isEditorDialogOpen ? ( @@ -604,7 +625,13 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { {showErrorDetails && ( - + )} {isInputActive && ( -- cgit v1.2.3