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

前端 未结 2 337
北恋
北恋 2021-01-25 05:02

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;
u         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-25 05:53

    #!/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()"

提交回复
热议问题