Skip to content

feat(ui): add dynamic toggle for alternate buffer mode - #29262

Closed
bhalsodnikunjhiteshbhai wants to merge 1 commit into
google-gemini:mainfrom
bhalsodnikunjhiteshbhai:14414-alt-buffer-toggle
Closed

bhalsodnikunjhiteshbhai wants to merge 1 commit into
google-gemini:mainfrom
bhalsodnikunjhiteshbhai:14414-alt-buffer-toggle

Conversation

@bhalsodnikunjhiteshbhai

Copy link
Copy Markdown
  • Prevents memory access out of bounds crash in yoga-wasm by avoiding synchronous unmounts of history items
  • Eliminates duplicated footer artifacts when exiting alternate buffer by ensuring Ink has time to issue erasure codes before swapping terminal buffers
  • Fully restores normal buffer scrollback without clipping or duplicating history
  • Resolves startup layout rendering bug when alternate buffer is set in config by manually handling terminal transitions instead of letting Ink's alternateBuffer renderer take over

Summary

Details

Related Issues

How to Validate

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

- Prevents memory access out of bounds crash in yoga-wasm by avoiding synchronous unmounts of history items
- Eliminates duplicated footer artifacts when exiting alternate buffer by ensuring Ink has time to issue erasure codes before swapping terminal buffers
- Fully restores normal buffer scrollback without clipping or duplicating history
- Resolves startup layout rendering bug when alternate buffer is set in config by manually handling terminal transitions instead of letting Ink's alternateBuffer renderer take over
@github-actions github-actions Bot added the size/xl An extra large PR label Sep 9, 2026
@google-cla

google-cla Bot commented Sep 9, 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 commented Sep 9, 2026

Copy link
Copy Markdown

📊 PR Size: size/XL

  • Lines changed: 1054
  • Additions: +598
  • Deletions: -456
  • Files changed: 44

@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 implements a dynamic toggle for the alternate buffer mode, allowing users to switch between standard and alternate screen buffers using Alt+A. The changes focus on improving the stability of terminal transitions, ensuring that scrollback history is preserved, and fixing layout rendering bugs during startup. By centralizing the alternate buffer state and improving cleanup logic, the PR provides a more robust and responsive terminal UI experience.

Highlights

  • Dynamic Alternate Buffer Toggle: Introduced a new keyboard shortcut (Alt+A) to dynamically toggle the alternate screen buffer mode.
  • Improved Terminal State Management: Enhanced terminal cleanup procedures and added transition state handling to prevent rendering artifacts and memory access issues.
  • Refactored Sizing Logic: Updated width calculation logic to rely on the alternate buffer state directly rather than the configuration object.
  • Enhanced Testing: Updated numerous unit and snapshot tests to accommodate the new alternate buffer state and improved cleanup routines.
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 the ability to toggle the alternate screen buffer dynamically using the Alt+A shortcut, along with a smooth transition mechanism (isTransitioningAltBuffer) to prevent scrollback erasure when exiting the alternate buffer. It refactors useAlternateBuffer to read from the UI state instead of the static configuration, simplifies MouseProvider by keeping its stdin listener active for robust sequence detection, and improves terminal cleanup on exit. The review feedback correctly points out that the fallback cleanup functions in cleanupTerminalOnExit should be wrapped in a try-catch block to prevent unhandled exceptions if process.stdout is closed or in an invalid state during process termination.

Comment on lines +43 to +49
// Fallback cleanup using explicit helper functions.
disableKittyKeyboardProtocol();
disableModifyOtherKeys();
disableBracketedPasteMode();
exitAlternateScreen();
disableMouseEvents();
enableLineWrapping();

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.

high

The fallback cleanup functions are executed outside of any try-catch block. If process.stdout is closed, destroyed, or in an invalid state when the process exits, calling these functions (which write to stdout) can throw unhandled exceptions (such as ERR_STREAM_WRITE_AFTER_END). Since this is an exit/cleanup handler, any unhandled exception can crash the exit process or clutter the console with stack traces.

We should wrap the fallback cleanup in a single try-catch block to ensure that all exit cleanups are safe and do not crash the process, while avoiding wrapping each individual call in its own block.

  try {
    // Fallback cleanup using explicit helper functions.
    disableKittyKeyboardProtocol();
    disableModifyOtherKeys();
    disableBracketedPasteMode();
    exitAlternateScreen();
    disableMouseEvents();
    enableLineWrapping();
  } catch (e) {
    debugLogger.warn('Failed to execute fallback terminal cleanup:', e);
  }
References
  1. When performing sequential cleanup operations writing to the same output stream (e.g., process.stdout), avoid wrapping each call in a separate try...catch block. If one write fails, subsequent writes to the same stream are also highly likely to fail.

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

Labels

priority/p1 Important and should be addressed in the near term. size/xl An extra large PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants