-
Notifications
You must be signed in to change notification settings - Fork 91
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
Immediately redraw the display when terminal window is resized #2
Comments
Hm, I tested this in an EC2 Ubuntu instance and it did work as intended, with a small delay, so maybe it's just a macOS thing. (I've tried both Terminal and iTerm2, inside of tmux and not, and it never works.) |
The bottom bar is not redrawn properly after resizing, even when a key was pressed. |
I just spent a bit of time looking into this. tl;dr, On macOS, redirecting tty to stdin closes the normal stdin fd (0). Before that, The upshot of this is that regardless of actual input, the loop in The comment in
👆 I wasn't able to reproduce this, at least on the latest version. |
Hm, actually that doesn't help at all; the fundamental problem remains, which is that I'm a bit of a rust newbie, but what would you say to not polling on stdin/tty at all, and instead using a channel to combine tty and the SIGWINCH? Specifically, I'm thinking that there could be a channel with two transmitters, each in a separate thread: one reads tty just as fast as it can, and puts parsed TuiEvents into the channel; the other polls the SIGWINCH socket, and puts WinChEvent events into the channel. Then, |
Yes, redrawing works with 0.9.0, so this can be closed imo (I don't use macOS). |
I still need to do a keypress (or mouse action) before the refresh happens. I'm on macos 11.7.8. |
By using a channel, we can remove the need for calling libc::poll on the stdin pipe. This doesn't work on the Mac: when we redirect tty to stdin, it breaks the original stdin pipe (fd 0), such that libc::poll on it returns instantly, with an revents of POLLNVAL (invalid pipe). macOS also doesn't support libc::poll on devices, so we can't poll tty directly. Instead, we spawn two threads: one just reads stdin forever, and the other uses the socket to listen for SIGWINCH events as before (using libc::poll). These both write to a channel, and the TuiInput simply reads from this channel. This fixes PaulJuliusMartinez#2.
jless does not immediately redraw the screen when the terminal window is resized; you have to press to key first.
The relevant code is in
src/input.rs
, which is quite convoluted.When I originally wrote this code, I had two goals: 1) immediately respond to both keypresses and SIGWINCH (clearly a failure), and 2) do so without busy-looping.
To accomplish this, I tried to setup a pipe to receive the signals and then use
poll
on that pipe and stdin to respond to the first change from either input.Along the way there's added complexity because
termion
'sparse_event
doesn't detect pure escapes.I think this is possible, because vim does it, but I'm not totally sure. vim might be doing some busy looping in the background.
The text was updated successfully, but these errors were encountered: