Skip to content

Instantly share code, notes, and snippets.

@gfldex
Last active August 16, 2016 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfldex/60ec413cc652bbbc6e08d5b413338237 to your computer and use it in GitHub Desktop.
Save gfldex/60ec413cc652bbbc6e08d5b413338237 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