Skip to content

fix(ui): fix flickering on small terminal heights#21416

Merged
devr0306 merged 15 commits intomainfrom
file-path-flickering
Mar 18, 2026
Merged

fix(ui): fix flickering on small terminal heights#21416
devr0306 merged 15 commits intomainfrom
file-path-flickering

Conversation

@devr0306
Copy link
Copy Markdown
Contributor

@devr0306 devr0306 commented Mar 6, 2026

Summary

This pull request enhances the UI's ability to adapt to varying terminal heights by implementing a more precise and dynamic height calculation mechanism for displayed content, particularly for history items and shell outputs. The changes ensure that UI elements are appropriately constrained or allowed to expand based on the available vertical space and specific UI modes, leading to a more stable and responsive user experience. This includes refactoring the underlying utility functions and adding comprehensive tests to validate the new logic.

Details

  • Dynamic Height Calculation for UI Components: Introduced availableTerminalHeight to MainContent.tsx to dynamically adjust the maximum height of HistoryItemDisplay and MemoizedHistoryItemDisplay components based on the available terminal space and UI constraints.
  • Improved Tool Layout Utilities: Updated calculateToolContentMaxLines and calculateShellMaxLines in toolLayoutUtils.ts to ensure more accurate and robust height calculations, preventing negative height values and correctly accounting for reserved lines in both standard and alternate buffer modes.
  • Comprehensive Unit Testing: Added a new test file, toolLayoutUtils.test.ts, with extensive unit tests for the height calculation utility functions, covering various scenarios including constrained heights, alternate buffer modes, and edge cases.
  • Snapshot Test Updates: Modified existing snapshot tests in MainContent.test.tsx.snap to reflect the visual changes resulting from the refined height calculation logic, ensuring UI consistency.

Related Issues

Fixes #20217

How to Validate

Ask Gemini "Run npm test -w @google/gemini-cli" and change the height of the terminal as the command is running to verify if it doesn't flicker on different terminal heights. The VS Code terminal might be best for testing this.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@devr0306 devr0306 requested a review from a team as a code owner March 6, 2026 17:00
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Mar 6, 2026

Hi @devr0306, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

Thank you for your understanding and for being a part of our community!

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the UI's ability to adapt to varying terminal heights by implementing a more precise and dynamic height calculation mechanism for displayed content, particularly for history items and shell outputs. The changes ensure that UI elements are appropriately constrained or allowed to expand based on the available vertical space and specific UI modes, leading to a more stable and responsive user experience. This includes refactoring the underlying utility functions and adding comprehensive tests to validate the new logic.

Highlights

  • Dynamic Height Calculation for UI Components: Introduced availableTerminalHeight to MainContent.tsx to dynamically adjust the maximum height of HistoryItemDisplay and MemoizedHistoryItemDisplay components based on the available terminal space and UI constraints.
  • Improved Tool Layout Utilities: Updated calculateToolContentMaxLines and calculateShellMaxLines in toolLayoutUtils.ts to ensure more accurate and robust height calculations, preventing negative height values and correctly accounting for reserved lines in both standard and alternate buffer modes.
  • Comprehensive Unit Testing: Added a new test file, toolLayoutUtils.test.ts, with extensive unit tests for the height calculation utility functions, covering various scenarios including constrained heights, alternate buffer modes, and edge cases.
  • Snapshot Test Updates: Modified existing snapshot tests in MainContent.test.tsx.snap to reflect the visual changes resulting from the refined height calculation logic, ensuring UI consistency.
Changelog
  • packages/cli/src/ui/components/MainContent.tsx
    • Updated component to utilize availableTerminalHeight for dynamic height management of history items and adjusted rendering logic based on UI state.
  • packages/cli/src/ui/components/snapshots/MainContent.test.tsx.snap
    • Updated UI snapshots to reflect the visual changes introduced by the new height calculation logic.
  • packages/cli/src/ui/utils/toolLayoutUtils.test.ts
    • Added new unit tests to thoroughly validate the calculateToolContentMaxLines and calculateShellMaxLines utility functions across various scenarios.
  • packages/cli/src/ui/utils/toolLayoutUtils.ts
    • Refactored height calculation functions to improve accuracy, prevent negative height values, and correctly apply reserved line counts for different UI modes.
Activity
  • The pull request description provides a template, but no specific activity or comments have been recorded yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors and fixes bugs in the height calculation logic for UI components, particularly for tool and shell outputs. The changes replace hardcoded values with shared constants and introduce more accurate calculations that account for available terminal height, preventing UI overflow on smaller terminal sizes. A comprehensive suite of unit tests has been added to validate the new logic. The changes are well-implemented and significantly improve the robustness and correctness of the UI rendering. I have reviewed the changes and found no issues.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 6, 2026

Size Change: +139 B (0%)

Total Size: 26.2 MB

Filename Size Change
./bundle/chunk-6RBYLCXE.js 0 B -13.5 MB (removed) 🏆
./bundle/chunk-N5HU6JDH.js 0 B -3.63 MB (removed) 🏆
./bundle/core-473GCFLR.js 0 B -41.4 kB (removed) 🏆
./bundle/devtoolsService-LD6SLX6K.js 0 B -27.7 kB (removed) 🏆
./bundle/interactiveCli-KTBM4KO3.js 0 B -1.61 MB (removed) 🏆
./bundle/oauth2-provider-RRDB4BIX.js 0 B -9.19 kB (removed) 🏆
./bundle/chunk-TN5ZXVU3.js 3.63 MB +3.63 MB (new file) 🆕
./bundle/chunk-ZFTGVL5T.js 13.5 MB +13.5 MB (new file) 🆕
./bundle/core-KNQ5FZYH.js 41.4 kB +41.4 kB (new file) 🆕
./bundle/devtoolsService-JVTFZECX.js 27.7 kB +27.7 kB (new file) 🆕
./bundle/interactiveCli-K6K2TH3L.js 1.61 MB +1.61 MB (new file) 🆕
./bundle/oauth2-provider-5N4QRX4L.js 9.19 kB +9.19 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
./bundle/chunk-34MYV7JD.js 2.45 kB
./bundle/chunk-37ZTTFQF.js 966 kB
./bundle/chunk-5AUYMPVF.js 858 B
./bundle/chunk-664ZODQF.js 124 kB
./bundle/chunk-DAHVX5MI.js 206 kB
./bundle/chunk-G4TMH6EN.js 1.95 MB
./bundle/chunk-IUUIT4SU.js 56.5 kB
./bundle/chunk-RJTRUG2J.js 39.8 kB
./bundle/devtools-36NN55EP.js 696 kB
./bundle/dist-T73EYRDX.js 356 B
./bundle/gemini.js 696 kB
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB
./bundle/memoryDiscovery-KKSSU3SI.js 922 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB
./bundle/src-QVCVGIUX.js 47 kB
./bundle/tree-sitter-7U6MW5PS.js 274 kB
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB
./bundle/undici-4X2YZID5.js 360 B

compressed-size-action

@gemini-cli gemini-cli bot added the priority/p1 Important and should be addressed in the near term. label Mar 6, 2026
@devr0306 devr0306 changed the title Changed max height fix(ui): fix flickering on small terminal heights Mar 6, 2026
@gemini-cli gemini-cli bot added the 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. label Mar 6, 2026
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Automated Review from /review-frontend

Hi there! Thanks for putting this PR together.

Overall, this is a great improvement! The fix for the core layout flickering issue—specifically where an expandable shell was wrongly constrained to 40% of the screen height when constrainHeight was true—looks solid. Additionally, the logic to safely clamp contentHeight to 0 instead of 3 in the layout utils is correct and well-tested.

However, correctly fixing the minimum height uncovers a couple of critical bugs in the codebase when maxLines evaluates to 0. I'd like to request a few changes to address these edge cases before we merge, as they can cause severe performance issues or hangs on small terminal heights.

1. Critical Performance Bug in AnsiOutput.tsx

In packages/cli/src/ui/components/AnsiOutput.tsx, when maxLines is 0, numLinesRetained also becomes 0.

Because -0 === 0 in JavaScript, data.slice(-numLinesRetained) evaluates to data.slice(-0). Since slice(-0) is equivalent to slice(0), it returns the entire array instead of an empty array. This causes AnsiOutputText to render the full output (e.g., 10,000 lines) into Ink's layout engine when the terminal is very small, leading to severe performance issues or hanging.

Suggested Fix in packages/cli/src/ui/components/AnsiOutput.tsx:

-  const lastLines = disableTruncation ? data : data.slice(-numLinesRetained);
+  const lastLines = disableTruncation
+    ? data
+    : numLinesRetained === 0
+      ? []
+      : data.slice(-numLinesRetained);

2. Missing Truncation Label in ToolResultDisplay.tsx

In packages/cli/src/ui/components/messages/ToolResultDisplay.tsx, the truncation checks currently use if (maxLines). Since 0 is falsy, these conditions evaluate to false when maxLines is 0. This prevents hiddenLinesCount from being calculated, meaning MaxSizedBox will not display the "... X lines hidden (Ctrl+O to show) ..." label, even though the content is fully truncated.

Suggested Fix (in two places in packages/cli/src/ui/components/messages/ToolResultDisplay.tsx):

-        if (maxLines) {
+        if (maxLines !== undefined) {

and

-      if (Array.isArray(resultDisplay) && !isAlternateBuffer && maxLines) {
+      if (Array.isArray(resultDisplay) && !isAlternateBuffer && maxLines !== undefined) {

Conclusion

Status: Request Changes

Could you please apply these fixes? They are crucial to ensure the application doesn't hang or swallow truncation warnings when the terminal height forces a 0-line constraint.

Thanks again for the excellent work on the core layout fixes! Let me know if you have any questions.

? staticAreaMaxItemHeight
: undefined
: uiState.constrainHeight
? availableTerminalHeight
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we make this change? this is truncating items more than they should be. With this change we are now strangely truncating items that have isExpandable == true more than ones where it is false.

Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtmlgtm

@devr0306 devr0306 added this pull request to the merge queue Mar 18, 2026
Merged via the queue into main with commit 34f2715 Mar 18, 2026
27 checks passed
@devr0306 devr0306 deleted the file-path-flickering branch March 18, 2026 21:39
ProthamD pushed a commit to ProthamD/gemini-cli that referenced this pull request Mar 29, 2026
Co-authored-by: Jacob Richman <jacob314@gmail.com>
warrenzhu25 pushed a commit to warrenzhu25/gemini-cli that referenced this pull request Apr 9, 2026
Co-authored-by: Jacob Richman <jacob314@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flickering when typing file paths

2 participants