【发布时间】:2016-03-20 17:02:44
【问题描述】:
来自 ncurses(3) linux 手册页:
nodelay 选项使 getch 成为非阻塞调用。如果没有输入准备好,getch 返回 ERR。如果禁用(bf 为 FALSE),getch 将等待直到按下某个键。
为什么在我的示例中 getch 不等到我按下一个键?
#!/usr/bin/env perl6
use v6;
use NativeCall;
constant LIB = 'libncursesw.so.5';
constant ERR = -1;
class WINDOW is repr('CPointer') { }
sub initscr() returns WINDOW is native(LIB) {*};
sub cbreak() returns int32 is native(LIB) {*};
sub nodelay(WINDOW, bool) returns int32 is native(LIB) {*};
sub getch() returns int32 is native(LIB) {*};
sub mvaddstr(int32,int32,str) returns int32 is native(LIB) {*};
sub nc_refresh() is symbol('refresh') returns int32 is native(LIB) {*};
sub endwin() returns int32 is native(LIB) {*};
my $win = initscr(); # added "()"
cbreak();
nodelay( $win, False );
my $c = 0;
loop {
my $key = getch(); # getch() doesn't wait
$c++;
mvaddstr( 2, 0, "$c" );
nc_refresh();
next if $key == ERR;
last if $key.chr eq 'q';
}
endwin();
【问题讨论】:
-
这对我来说似乎适用于 ncurses 6 和 perl6 --version 的“这是基于 MoarVM 版本 2016.02 实现 Perl 6.c 的 Rakudo 版本 2016.02”。你运行的是哪个版本的 Perl 6?
-
Coke: perl6 -v: "这是 Rakudo 版本 2016.02-151-gb243a96,基于 MoarVM 版本 2016.02-33-g1e3d2ac 实现 Perl 6.c。"和 ncurses 5.
标签: blocking ncurses raku getch nativecall