"be consistent" | |
PerlMonks |
Handling curses window resizes with Curses.pmby Llew_Llaw_Gyffes (Scribe) |
on Sep 08, 2016 at 16:44 UTC ( [id://1171416]=perlquestion: print w/replies, xml ) | Need Help?? |
Llew_Llaw_Gyffes has asked for the wisdom of the Perl Monks concerning the following question: O wise brethren, I have a threaded multi-window curses application. (Yes, I know many of you are already scratching your heads and asking "Why?" Suffice it to say that the design decision was made to further my knowledge of Perl, and because it was a challenge, and because a multithreaded Perl ICB client was a cool thing to create.) Now, one of my long-documented bugs that I have been unable to solve is that the application failed to handle SIGWINCH gracefully. Or at all, in fact. When the terminal size was changed, the usual result was that it would crash. I and several other people investigated as deeply as we could, and eventually concluded that it appeared something was breaking deep within Curses.pm, and I abandoned my attempts to handle SIGWINCH and documented it as a known bug. However, Curses.pm just updated, for the first time in quite some time. And now at least SOME SIGWINCH handling works. Column resizes of the controlling xterm are now handled correctly with no intervention required on my part, but lines resizing does not work correctly. My application creates three curses windows, as follows:
As should be evident, resizing the terminal vertically should cause only the size of $output_window to change. In practice, the curses window heights do not seem to change when the terminal is resized, and if this causes the status line to be "pushed off the bottom" of the terminal by a terminal height reduction, it is broken and does not work when brought back onscreen again by a terminal height increase. Since the terminal itself does not know how my window sizes are to be managed, I clearly need to handle SIGWINCH myself to correctly resize the output window and move the status line and input window up or down accordingly. My first step should presumably be to call resizeterm(newlines, newcols). resizeterm( ) will call resize_term( ), which will do things like update LINES and COLS, after which I can recalculate my window sizes and make appropriate calls to wresize( ). To know when I need to do this, my reading leads me to understand I should be looking for a KEY_RESIZE event. I'm doing so like this in the thread that handles input:
The resize flag should then trigger each thread to update its own window. There are two problems here. First, I don't appear to be receiving KEY_RESIZE events. Secondly, I don't know what newlines/newcols to pass to resizeterm( ), and I can't even check whether the terminal really WAS resized because is_term_resized( ) is not supported in Curses.pm. Can anyone offer guidance on how I should be accomplishing what I'm trying to do here?
Back to
Seekers of Perl Wisdom
|
|