-
Notifications
You must be signed in to change notification settings - Fork 34
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
React to terminal size changes on JVM #152
Comments
I think this would require some JNA code. In the meantime, you could potentially poll |
updateTerminalSize correctly detects the size change, but doesn't address the garbling of the output when the screen shrinks. |
Oh, good point. That's a tougher problem. It seems like the solution would be to keep track of the terminal size between frames and calculate where we think the cursor is after wrapping so that we can move back to the original position. |
Should be something like previousHeight * ceil(previousWitdh/newWidth), for the case where the animation width covers the entire terminal width, and the newWidth is smaller than the previous. |
Would printing the right number of backspace characters be an alternate way to clear the animation? |
Backspace is a good idea, but unfortunately terminals handle it very differently. Some will ignore it entirely, some will only delete back to the start of the line etc. |
Ok, so I implemented this in #151.
If you're able to try out that branch and let me know what you think, I'd be appreciate it. |
Thanks! I'll try and make time for it in the next few weeks. We have our own multi-task progress bar implementation that uses Mordants rendering alongside its own, but it uses the animation APIs so it should work. Do you have any pictures of what the new multi-task tracker looks like? Perhaps we can migrate, although I do like our current look. The JNA bug could be worked around by using Panama on modern JVMs. JNA isn't necessary anymore on those versions. |
It's stable in JDK 22 releasing in two months. A multi-release jar would allow its use only when running on 22+. |
Currently, changing the size of the terminal window whilst a progress tracker runs will cause corrupt display, as the new size isn't taken into account. There's a sun.misc.Signal API I think, that would allow for reacting to the SIGWINCH on UNIX. On Windows it's harder, I don't think the JVM exposes anything for that, not even in private APIs. Perhaps jline has some code for it.
The text was updated successfully, but these errors were encountered: