Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redraw flashing #123

Closed
wants to merge 1 commit into from
Closed

Conversation

Tired-Fox
Copy link
Contributor

All instances of redrawing will now call \x1b[H to go to home position and then draw over all characters on the screen. This removed screen flickering for many if not most of terminal emulators. When a full redraw is needed, when the terminal resizes, the redraw is set to full and will fully clear the screen instead of going to home.

@bczsalba
Copy link
Owner

bczsalba commented Jul 6, 2023

Hey! Sorry about the delay.

Unfortunately it seems this is gonna be a bit more complicated. When windows are drawn we only draw their current state, and as a result not doing a full clear is causing a whole lot of ghosting to happen.

I remember dealing with this a long time ago; there are ways to get around it. We could, for example keep track of windows that changed sizes and draw a "blank" that fills up their previous space, or we could also make the whole "home clear" an optional feature of the WindowManager, so people who rely on windows getting resized/moved around don't run into this problem.

I'll try to think of things we could do to get around it, but it's probably gonna involve having a new look at the compositor. As I mentioned in the Discord I do have a solution to this, but unfortunately it isn't compatible with practically any of PTG's underbelly.

Thank you!

@taraskuzyk
Copy link

Hey @bczsalba, do you mind posting the solution / workarounds to this issue? Would be great to have this in the FAQ, similar to how you describe avoiding multithreading issues here

1 similar comment
@taraskuzyk
Copy link

Hey @bczsalba, do you mind posting the solution / workarounds to this issue? Would be great to have this in the FAQ, similar to how you describe avoiding multithreading issues here

@bczsalba
Copy link
Owner

@taraskuzyk Hey!

Unfortunately the fix to this must happen at an architectural level, as the problem is just a fundamental flaw of how drawing is implemented here. Essentially we just gather a whole frame in one string and dump it onto the screen, which can cause flashing and long scrollbacks to be created on terminals that don't optimize for it.

The way I got around it in the successor to this project (and part of the reason that successor even exists) was to draw individual updates on the screen as opposed to the whole buffer, which pretty much eliminates the problem. I'm sure there are performant ways to do this here as well, but in that project I maintain a matrix of screen cells that each contain their current character's data which I can compare against whenever there's a new write call. If any change happens it's added to a sort of queue that's later merged and printed out as a single string with positional ANSI sequences for each changed cell coordinate.

To do all this every styled string is handled as a special class which contains all of its styling information alongside the plain text which lets me easily look for any changes. Without that one cog in place I'm not sure this is possible with any reasonable performance, especially in Python. I'm sure you could make it work though, I got halfway down implementing an ANSI parser at one point before abandoning ship because I couldn't make it anywhere near usable in speed. Unfortunately that code is now long gone, but it wasn't all that good anyway (rather it was so bad at what it tried to do it inspired me to rewrite the entire library instead of finishing it, lmao).

This ended up being a bit of a ramble but I think it gets the idea across - if you are interested in trying to fix this I'm happy to chat about any issues you run into. Feel free to also check out the fixes the aforementioned rewrite has:

@bczsalba
Copy link
Owner

Closing for lack of activity - we've discussed the concept anyways, so if there is a way to do it I'm always open for another attempt :)

@bczsalba bczsalba closed this Aug 31, 2024
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.

3 participants