Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created August 27, 2016 11:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gfldex/7d716436aa88c8261734bfabd7106c3d to your computer and use it in GitHub Desktop.
use v6;
use Term::termios;
my $keystrokes = Supplier.new;
start {
$*IN = open('/dev/tty');
ENTER my $saved-termios = Term::termios.new(fd => 0).getattr;
LEAVE $saved-termios.setattr(:DRAIN);
CATCH { default { say .Str } }
my $IN = $*IN;
Term::termios.new(fd => 0).getattr.makeraw.setattr(:DRAIN);
my $max = 0;
loop {
$keystrokes.emit($IN.getc);
last if $max++ > 10;
}
};
react {
whenever $keystrokes -> $k {
put $k;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment