Prevent flickering due to scrolling when terminal is resized and cursor is off-screen #8514

Open
opened 2026-01-31 01:31:24 +00:00 by claunia · 7 comments
Owner

Originally created by @joaobzrr on GitHub (May 22, 2020).

I've opened an issue about this before, but I still don't understand how to solve this problem (if it's solvable at all). It seems to me that, if a resize happens and the cursor gets pushed off-screen, then that will always trigger a scroll, which the application can detect and scroll the viewport back up and redraw the screen. The problem is this will introduce flickering as the application states before and after the resize will be separated by a third intermediary state in which the viewport was scrolled down. So far I see no way to have smooth, non-layout-breaking resizing if resizing can cause the viewport to scroll. So I have a couple questions:

  1. Is there a way to prevent this flickering from happening?
  2. If it is impossible to prevent auto scrolling when cursor is pushed off-screen, would always having the cursor at the next to last line and maybe polling frequently enough mitigate this issue?
  3. Couldn't an application just opt-out of this behavior. Maybe there could be a console mode that you could set to always have the cursor within the screen if the window is resized that would work only when an application switches to the alternate screen buffer.
Originally created by @joaobzrr on GitHub (May 22, 2020). I've opened an issue about this before, but I still don't understand how to solve this problem (if it's solvable at all). It seems to me that, if a resize happens and the cursor gets pushed off-screen, then that will always trigger a scroll, which the application can detect and scroll the viewport back up and redraw the screen. The problem is this will introduce flickering as the application states before and after the resize will be separated by a third intermediary state in which the viewport was scrolled down. So far I see no way to have smooth, non-layout-breaking resizing if resizing can cause the viewport to scroll. So I have a couple questions: 1. Is there a way to prevent this flickering from happening? 2. If it is impossible to prevent auto scrolling when cursor is pushed off-screen, would always having the cursor at the next to last line and maybe polling frequently enough mitigate this issue? 3. Couldn't an application just opt-out of this behavior. Maybe there could be a console mode that you could set to always have the cursor within the screen if the window is resized that would work only when an application switches to the alternate screen buffer.
claunia added the Issue-QuestionNeeds-Tag-FixProduct-Meta labels 2026-01-31 01:31:24 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Jun 9, 2020):

Could you link the previous discussion? I'm having a hard time finding it in the backlog.

IMO, if you're creating a commandline application that's drawing to the entire viewport (like vim, emacs, etc), then the right way to do this is with the alternate screen buffer. This will create a second virtual buffer that you can use to draw to the entire screen, which doesn't have any sort of scrollback to deal with.

See The Alternate Screen Buffer for more details

@zadjii-msft commented on GitHub (Jun 9, 2020): Could you link the previous discussion? I'm having a hard time finding it in the backlog. IMO, if you're creating a commandline application that's drawing to the entire viewport (like `vim`, `emacs`, etc), then the _right_ way to do this is with the alternate screen buffer. This will create a second virtual buffer that you can use to draw to the entire screen, which doesn't have any sort of scrollback to deal with. See [The Alternate Screen Buffer](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer) for more details
Author
Owner

@joaobzrr commented on GitHub (Jun 11, 2020):

Previous issue was #4181. By the way, I am using the alternate screen buffer and I still get this problem.

@joaobzrr commented on GitHub (Jun 11, 2020): Previous issue was #4181. By the way, I *am* using the alternate screen buffer and I still get this problem.
Author
Owner

@zadjii-msft commented on GitHub (Jun 11, 2020):

Wait lemme just clarify something, are you using the alt buffer in conhost or in the Windows Terminal? The Terminal unfortunately doesn't support the alt buffer quite yet (#381), so that'll definitely cause problems, but I'd think that the alt buffer in conhost would be fine...

@zadjii-msft commented on GitHub (Jun 11, 2020): Wait lemme just clarify something, are you using the alt buffer in _conhost_ or in the Windows Terminal? The Terminal unfortunately doesn't support the alt buffer quite yet (#381), so that'll _definitely_ cause problems, but I'd think that the alt buffer in conhost would be fine...
Author
Owner

@ghost commented on GitHub (Jun 15, 2020):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost commented on GitHub (Jun 15, 2020): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@joaobzrr commented on GitHub (Jun 17, 2020):

I'll test using conhost and get back to you.

@joaobzrr commented on GitHub (Jun 17, 2020): I'll test using conhost and get back to you.
Author
Owner

@joaobzrr commented on GitHub (Jun 17, 2020):

Okay, I can confirm the same problem occurs while using the alt buffer in conhost.

@joaobzrr commented on GitHub (Jun 17, 2020): Okay, I can confirm the same problem occurs while using the alt buffer in conhost.
Author
Owner

@DHowett commented on GitHub (Jun 26, 2020):

Thanks for the confirmation 😄

@DHowett commented on GitHub (Jun 26, 2020): Thanks for the confirmation :smile:
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8514