На справочной странице 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();