perl - 如何使用 Curses 从调整大小的窗口中获取窗口大小?

标签 perl size curses window-resize

我尝试了这种方法,但它不起作用 - getmaxyx 返回的值始终保持不变。

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

最佳答案

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

^^^ 这对我有用。根据Writing Programs with NCURSES / Using NCURSES under XTERM你应该执行“endwin() 后跟刷新()”

关于perl - 如何使用 Curses 从调整大小的窗口中获取窗口大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9769723/

相关文章:

perl - 在 CPAN 上部署 xs 模块

perl - 禁止 Ctrl-C Perl

c++ - 在 C++ 中确定数字大小

c - 使用 `*inchstr()`保存的数据恢复屏幕内容

c - 我在这里做错了什么(尝试用 C 编写 *.srt 解析器)?

Linux:使用行号作为变量将变量附加到行尾

perl - 使用 FCGI 接受 POST 参数

Python - scapy 数据包大小差异

java - int 类型的意外输出

python - 在 pythoncurses 中获取更新的屏幕尺寸