Wait before drawing the frame when receiving ESC[2J #21264

Closed
opened 2026-01-31 07:38:06 +00:00 by claunia · 4 comments
Owner

Originally created by @a-usr on GitHub (Feb 16, 2024).

Description of the new feature/enhancement

Wait before drawing ( or creating ) a frame when ESC[2J (Clear Screen) is received until either a set time (e.g. 2 ms) has passed or additional data is received from stdout or stderr. This is to prevent flickering caused by applications (that do frame-based rendering, e.g TUI applications) that clear the screen before writing the next frame to it. If such a feature already exists, I propose making the timeout higher.

Worth noting is that the Flickering seems to be more intense on windows 11 vs on windows 10. Do the two platforms have different max framerates or is the framerate not capped at all and its caused by a hardware difference?

Proposed technical implementation details (optional)

Originally created by @a-usr on GitHub (Feb 16, 2024). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement Wait before drawing ( or creating ) a frame when ESC[2J (Clear Screen) is received until either a set time (e.g. 2 ms) has passed or additional data is received from stdout or stderr. This is to prevent flickering caused by applications (that do frame-based rendering, e.g TUI applications) that clear the screen before writing the next frame to it. If such a feature already exists, I propose making the timeout higher. Worth noting is that the Flickering seems to be more intense on windows 11 vs on windows 10. Do the two platforms have different max framerates or is the framerate not capped at all and its caused by a hardware difference? <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> # Proposed technical implementation details (optional) <!-- A clear and concise description of what you want to happen. -->
claunia added the Issue-FeatureNeeds-TriageNeeds-Tag-Fix labels 2026-01-31 07:38:06 +00:00
Author
Owner

@a-usr commented on GitHub (Feb 16, 2024):

For additional context, apparently the Flickering doesnt seem to be an issue with other terminals like WezTerm, but I havent tested this myself.

@a-usr commented on GitHub (Feb 16, 2024): For additional context, apparently the Flickering doesnt seem to be an issue with other terminals like WezTerm, but I havent tested this myself.
Author
Owner

@lhecker commented on GitHub (Feb 17, 2024):

In the current architecture it would be slightly difficult to implement this right now, but it would be generally possible long term. Your suggestion wouldn't work well over SSH though. Other terminals have since adopted iTerm2's synchronized update sequence (BSU = 2026) which does what you'd like but in a more robust manner. You can read about it here: https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec
Support for BSU is tracked in #8331. If that matches what you want, then I believe we should continue tracking this in #8331.

That said, and unrelated to the above, if you use the very latest Windows Terminal version and if you ensure to write your sequences in a single "packet" using the Windows APIs (= WriteFile on stdout) then it should not flicker.
C's printf for instance has an internal buffer size of 4KiB and any printf larger than that will chunk it up which causes flickering. WSL also does some buffering internally which causes the same thing. But if you use a native Windows function to write your output and buffer it properly then it should already work.

@lhecker commented on GitHub (Feb 17, 2024): In the current architecture it would be slightly difficult to implement this right now, but it would be generally possible long term. Your suggestion wouldn't work well over SSH though. Other terminals have since adopted iTerm2's synchronized update sequence (BSU = 2026) which does what you'd like but in a more robust manner. You can read about it here: https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec Support for BSU is tracked in #8331. If that matches what you want, then I believe we should continue tracking this in #8331. That said, and unrelated to the above, if you use the very latest Windows Terminal version and if you ensure to write your sequences in a single "packet" using the Windows APIs (= `WriteFile` on stdout) then it should not flicker. C's `printf` for instance has an internal buffer size of 4KiB and any `printf` larger than that will chunk it up which causes flickering. WSL also does some buffering internally which causes the same thing. But if you use a native Windows function to write your output and buffer it properly then it should already work.
Author
Owner

@a-usr commented on GitHub (Feb 18, 2024):

Thanks for the explanation and the references! Also huge thanks to you for taking your time and taking a look at almost every single issue👍

@a-usr commented on GitHub (Feb 18, 2024): Thanks for the explanation and the references! Also huge thanks to you for taking your time and taking a look at almost every single issue👍
Author
Owner

@a-usr commented on GitHub (Feb 19, 2024):

Also I was wondering, is there any functionality to see when Windows Terminal receives a packet and what its contents are?

@a-usr commented on GitHub (Feb 19, 2024): Also I was wondering, is there any functionality to see when Windows Terminal receives a packet and what its contents are?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21264