AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.07k stars 350 forks source link

Terminal consistently flickers when scrolling through paginated list of options #436

Open aq17 opened 1 year ago

aq17 commented 1 year ago

What operating system and terminal are you using? MacOS+default terminal, also saw same issue on Windows+PowerShell

An example that showcases the bug. (short clip to fit 10mb limit, but continues as you scroll down the list and paginate) https://user-images.githubusercontent.com/54565933/179568187-b4d8e098-a23b-4484-b988-ca143dda607a.mov

What did you expect to see? No flickering when scrolling through paginated list

What did you see instead? Flickering when scrolling through paginated list

jquick commented 1 year ago

I have this issue also, using Alacrity terminal

ekini commented 1 year ago

Same behaviour on Linux (Wayland) in "foot" terminal.

mislav commented 1 year ago

I also experience this and wanted to find ways to mitigate. This is the redrawing logic: https://github.com/AlecAivazis/survey/blob/e47352f914346a910cc7e1ca9f65a7ac0674449a/renderer.go#L135-L145

Perhaps there is a way to redraw the last N lines in a terminal in a way that doesn't cause flickering. Ideas welcome!

dnkl commented 1 year ago

Perhaps there is a way to redraw the last N lines in a terminal in a way that doesn't cause flickering. Ideas welcome!

There are application synchronized updates: https://gitlab.freedesktop.org/terminal-wg/specifications/-/merge_requests/2

TL;DR application emits one escape at the beginning of a "frame" (update) and another one when done.

Note that there are two variants; the DCS initially suggested in the MR, which was the first one implemented by terminals. Later, it was generally agreed that a "private mode" was better, and the 2026 private mode was added.

Another option is writing the erase commands into a buffer, and doing a single actual terminal write.