How to get with Curses the window-size from a resized window?

安稳与你 提交于 2019-12-02 11:11:03

问题


I tried it this way, but it doesn't work - the returned values from getmaxyx remain always the same.

#!/usr/bin/env perl
use warnings;
use 5.012;
use Curses;

my $size_changed = 0;
$SIG{'WINCH'} = sub { $size_changed= 1; };

initscr(); 

my ( $row, $col );
getmaxyx( $row, $col );
addstr( "begin: $row - $col\n" );
refresh();

for ( 0 .. 19 ) {
    addstr( "-------------\n" );
    if ( $size_changed ) {
        getmaxyx( $row, $col );
        addstr( "new: $row - $col\n" );
        $size_changed = 0;
    }
    refresh();
    sleep 1;

}

sleep 3;
endwin();

回答1:


#!/usr/bin/env perl
use warnings;
use 5.012;
use Curses;

my $size_changed = 0;
$SIG{'WINCH'} = sub { $size_changed= 1; };

initscr(); 

my ( $row, $col );
getmaxyx( $row, $col );
addstr( "begin: $row - $col\n" );
refresh();

for ( 0 .. 19 ) {
    sleep 2;
    if ( $size_changed ) {
        endwin();
        refresh(); 
        getmaxyx( $row, $col );
        addstr( "new: $row - $col\n" );
        $size_changed = 0;
    }
}

sleep 3;
endwin();

^^^ this worked for me. according to Writing Programs with NCURSES / Using NCURSES under XTERM you are suppose to do "endwin() followed by an refresh()"




回答2:


Knowing almost nothing about Curses, at a first guess I'd say your problem is that you broke $SIG{WINCH}, because libcurses is going to want to use that to detect when the window may have changed size.



来源:https://stackoverflow.com/questions/9769723/how-to-get-with-curses-the-window-size-from-a-resized-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!