Skip to content

Instantly share code, notes, and snippets.

@jonathanstowe
Created April 19, 2016 22:02
Show Gist options
  • Save jonathanstowe/6561a7ab0b7213eb6b5733cf6f9f47fa to your computer and use it in GitHub Desktop.
Save jonathanstowe/6561a7ab0b7213eb6b5733cf6f9f47fa to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
use v6;
use Term::termios;
use NativeCall;
class FILE is repr('CPointer') {
sub fdopen(Int, Str) returns FILE is native { * }
method new(Int $fd) {
fdopen($fd, "r");
}
sub getc(FILE) returns uint8 is native { * }
method getc() returns uint8 {
getc(self);
}
}
my $saved_termios := Term::termios.new(fd => $*IN.native-descriptor).getattr;
my $termios := Term::termios.new(fd => $*IN.native-descriptor).getattr;
$termios.makeraw;
$termios.setattr(:DRAIN);
loop {
my $c = $*IN.getc();
print "got: " ~ $c.ord ~ "\r\n";
last if $c eq 'q';
}
$saved_termios.setattr(:DRAIN);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment