Skip to content

Conversation

@thkim1011
Copy link
Contributor

@thkim1011 thkim1011 commented May 7, 2025

When the outputHeight goes from a value >= stdout.rows to a value < stdout.rows in between re-render, it is possible that the old content is not completely removed from the terminal.

This happens for three reasons

  1. We actually want to consider the previous output height when deciding to entirely clear the terminal or only delete several lines. If the current output has a height >= stdout.rows, but we only need to clear the previous render's output, there's no point in writing ansiEscapes.clearTerminal. Similarly, if the current output has a height < stdout.rows but the previous output exceeded stdout.rows, then writing ansiEscapes.eraseLines(previousLineCount) won't clear all of the old output.
  2. this.log.clear() doesn't actually track the height of the output if we rendered via the outputHeight >= this.options.stdout.rows conditional. I've added a helper LogUpdate.sync to keep it in sync.
  3. The outputHeight >= this.options.stdout.rows conditional differs slightly in behavior to this.log in that it does not append a newline at the end.

Addressing all three of these points fixes the bug.

To test, I verified locally using a small example, and I've also added a test (see "erase screen where state changes in small viewport") which fails on master but passes in this branch.

Fixes #585

const customGlobal = global as any;

// These things must exist before importing `react-devtools-core`
// eslint-disable-next-line n/no-unsupported-features/node-builtins
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unclear why this lint error just started to appear, but should be safe to ignore.

@thkim1011
Copy link
Contributor Author

Correct me if I'm wrong but I think my PR fixes #585.

@thkim1011
Copy link
Contributor Author

@sindresorhus can I get a re-run of the ci?

@thkim1011
Copy link
Contributor Author

@sindresorhus just a heads up that this is ready for review.

NTaylorMullen added a commit to google-gemini/gemini-cli that referenced this pull request May 16, 2025
This commit introduces several changes to better manage terminal height and prevent UI tearing, especially when displaying long tool outputs or when the pending history item exceeds the available terminal height.

- Calculate and utilize available terminal height in `App.tsx`, `HistoryItemDisplay.tsx`, `ToolGroupMessage.tsx`, and `ToolMessage.tsx`.
- Refresh the static display area in `App.tsx` when a pending history item is too large, working around an Ink bug (see vadimdemedes/ink#717).
- Truncate long tool output in `ToolMessage.tsx` and indicate the number of hidden lines.
- Refactor `App.tsx` to correctly measure and account for footer height.

Fixes https://b.corp.google.com/issues/414196943
NTaylorMullen added a commit to google-gemini/gemini-cli that referenced this pull request May 16, 2025
This commit introduces several changes to better manage terminal height and prevent UI tearing, especially when displaying long tool outputs or when the pending history item exceeds the available terminal height.

- Calculate and utilize available terminal height in `App.tsx`, `HistoryItemDisplay.tsx`, `ToolGroupMessage.tsx`, and `ToolMessage.tsx`.
- Refresh the static display area in `App.tsx` when a pending history item is too large, working around an Ink bug (see vadimdemedes/ink#717).
- Truncate long tool output in `ToolMessage.tsx` and indicate the number of hidden lines.
- Refactor `App.tsx` to correctly measure and account for footer height.

Fixes https://b.corp.google.com/issues/414196943
@sindresorhus sindresorhus merged commit 8f2ad8f into vadimdemedes:master May 29, 2025
2 checks passed
keithballinger pushed a commit to google-gemini/gemini-cli that referenced this pull request Jun 13, 2025
This commit introduces several changes to better manage terminal height and prevent UI tearing, especially when displaying long tool outputs or when the pending history item exceeds the available terminal height.
- Calculate and utilize available terminal height in `App.tsx`, `HistoryItemDisplay.tsx`, `ToolGroupMessage.tsx`, and `ToolMessage.tsx`.
- Refresh the static display area in `App.tsx` when a pending history item is too large, working around an Ink bug (see vadimdemedes/ink#717).
- Truncate long tool output in `ToolMessage.tsx` and indicate the number of hidden lines.
- Refactor `App.tsx` to correctly measure and account for footer height.
Fixes https://b.corp.google.com/issues/414196943
elminramazanov pushed a commit to elminramazanov/claimfront that referenced this pull request Jun 25, 2025
This commit introduces several changes to better manage terminal height and prevent UI tearing, especially when displaying long tool outputs or when the pending history item exceeds the available terminal height.

- Calculate and utilize available terminal height in `App.tsx`, `HistoryItemDisplay.tsx`, `ToolGroupMessage.tsx`, and `ToolMessage.tsx`.
- Refresh the static display area in `App.tsx` when a pending history item is too large, working around an Ink bug (see vadimdemedes/ink#717).
- Truncate long tool output in `ToolMessage.tsx` and indicate the number of hidden lines.
- Refactor `App.tsx` to correctly measure and account for footer height.

Fixes https://b.corp.google.com/issues/414196943
viridivn pushed a commit to viridivn/gemini-cli that referenced this pull request Jun 29, 2025
This commit introduces several changes to better manage terminal height and prevent UI tearing, especially when displaying long tool outputs or when the pending history item exceeds the available terminal height.

- Calculate and utilize available terminal height in `App.tsx`, `HistoryItemDisplay.tsx`, `ToolGroupMessage.tsx`, and `ToolMessage.tsx`.
- Refresh the static display area in `App.tsx` when a pending history item is too large, working around an Ink bug (see vadimdemedes/ink#717).
- Truncate long tool output in `ToolMessage.tsx` and indicate the number of hidden lines.
- Refactor `App.tsx` to correctly measure and account for footer height.

Fixes https://b.corp.google.com/issues/414196943
happy-dev100 added a commit to happy-dev100/gemini that referenced this pull request Sep 19, 2025
This commit introduces several changes to better manage terminal height and prevent UI tearing, especially when displaying long tool outputs or when the pending history item exceeds the available terminal height.

- Calculate and utilize available terminal height in `App.tsx`, `HistoryItemDisplay.tsx`, `ToolGroupMessage.tsx`, and `ToolMessage.tsx`.
- Refresh the static display area in `App.tsx` when a pending history item is too large, working around an Ink bug (see vadimdemedes/ink#717).
- Truncate long tool output in `ToolMessage.tsx` and indicate the number of hidden lines.
- Refactor `App.tsx` to correctly measure and account for footer height.

Fixes https://b.corp.google.com/issues/414196943
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output terminal isn't cleared when second to last frame is taller than terminal

2 participants