Skip to content

fix(cli): cap pending plain text height to reduce streaming flicker - #29629

Open
shamanshetty07 wants to merge 2 commits into
google-gemini:mainfrom
shamanshetty07:fix/pending-text-height-flicker
Open

shamanshetty07 wants to merge 2 commits into
google-gemini:mainfrom
shamanshetty07:fix/pending-text-height-flicker

Conversation

@shamanshetty07

@shamanshetty07 shamanshetty07 commented Oct 4, 2026 •

Copy link
Copy Markdown

Summary

Cap the height of pending (streaming) plain text in MarkdownDisplay so the frame stays shorter than the terminal in the default rendering mode. This removes the full-screen clear-and-redraw that happens on every streamed update when a response grows taller than the terminal.

Details

  • In the default mode (alternate buffer and terminal buffer off), availableTerminalHeight was applied only to code blocks. Paragraphs and list items were not limited, so a long streamed list could make the frame taller than the terminal.
  • When Ink's last frame height is >= the terminal rows, it takes renderFullTerminal (clearTerminal + full static history + frame) instead of the incremental path. During streaming that repeats on every token update.
  • The fix wraps pending, non-alternate-buffer markdown in the existing MaxSizedBox (overflowDirection="top"), so the latest lines stay visible with a "lines hidden" note. Completed messages and alternate-buffer mode are unchanged.
  • useFlickerDetector is intentionally left as is. In alternate-buffer mode the root box height is fixed at the terminal height, so changing its > check to >= would report on every render.

Measured with the CLI run from source in a pseudo-terminal (macOS), prompt "Write a long numbered list of 60 programming tips, one line each", counting frames where Ink took the full-clear path (temporary logging in Ink, not included in this PR):

Rows Before (full-clear frames / renders) After (full-clear frames / renders)
20 164 / 669 (run 1), 38 / 746 (run 2, model stopped at item 29) 0 / 766, 0 / 603
60 63 / 645 (run 1) 0 / 749, 0 / 433

One additional "before" run at 60 rows never produced the list, so it is excluded. Render counts depend on model speed and are not directly comparable; the full-clear frame count is the relevant number. Total bytes written were not meaningfully reduced (spinner redraws remain), so the benefit is no full-screen clears, not less output.

Related Issues

Related to #29628

How to Validate

  1. npm run build, then run the CLI with default settings in a short terminal (for example 20 or 60 rows).
  2. Ask: "Write a long numbered list of 60 programming tips, one line each".
  3. Before: the screen visibly flashes while the list streams. After: no full-screen clears; the newest lines are shown with a "... first N lines hidden ..." line until the response is committed.
  4. npm test -w @google/gemini-cli -- src/ui/utils/MarkdownDisplay.test.tsx

npm run preflight: lint, typecheck and all other tests pass. One test in packages/core (ShellExecutionService > Orphan PTY slave FD cleanup ... darwin) fails on a clean upstream/main as well and is unrelated to this change.

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

While a response streams in the default (non-alternate-buffer) mode, plain text such as long lists or paragraphs was not height-limited; only code blocks were. The frame could grow taller than the terminal, which makes Ink clear the screen and rewrite the full history on every update.

Wrap pending markdown in MaxSizedBox so only the most recent lines that fit in availableTerminalHeight are shown. Completed messages and alternate-buffer mode are unchanged.
@google-cla

google-cla Bot commented Oct 4, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added the size/m A medium sized PR label Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 59
  • Additions: +59
  • Deletions: -0
  • Files changed: 2

@shamanshetty07
shamanshetty07 marked this pull request as ready for review October 4, 2026 20:38
@shamanshetty07
shamanshetty07 requested a review from a team as a code owner October 4, 2026 20:38
@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 addresses a visual flickering issue in the CLI during streaming responses. By capping the height of pending markdown content when not in alternate buffer mode, the application avoids triggering Ink's full-screen clear-and-redraw logic, significantly improving the stability of the terminal display during long streaming outputs.

Highlights

  • Streaming Flicker Reduction: Implemented a height cap for pending (streaming) plain text in MarkdownDisplay to prevent the terminal from performing full-screen clear-and-redraw operations when content exceeds the terminal height.
  • MaxSizedBox Integration: Wrapped pending, non-alternate-buffer markdown content in a MaxSizedBox component, ensuring the latest lines remain visible while hiding overflowed content.
  • Test Coverage: Added new unit tests to verify that pending text is correctly capped at the available terminal height, while completed text remains unaffected.
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 the 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 counterproductive. 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.

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. ↩

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

Copy link
Copy Markdown
Contributor

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 introduces height capping for pending markdown plain text when not in alternate buffer mode. By wrapping the content blocks in a MaxSizedBox component constrained to the available terminal height, it prevents Ink from clearing and redrawing the entire screen during streaming updates. Corresponding unit tests have been added to verify this behavior for both pending and completed text. I have no additional feedback to provide as the implementation is clean and well-tested.

@shamanshetty07

Copy link
Copy Markdown
Author

@googlebot I signed it!

@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Oct 4, 2026
@gemini-cli gemini-cli Bot added the priority/p2 Important but can be addressed in a future release. label Oct 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality priority/p2 Important but can be addressed in a future release. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant