Skip to content

Instantly share code, notes, and snippets.

@skids
Created November 25, 2015 03:13
Show Gist options
  • Save skids/0b1cfabedddd95a824c8 to your computer and use it in GitHub Desktop.
Save skids/0b1cfabedddd95a824c8 to your computer and use it in GitHub Desktop.
snippet from some terminal code
# We have to use NativeCall here as there is otherwise no way to
# get an fd for Term::termios, as of yet. And, it is buried so
# deep in the IO object it'll require guts work to unearth.
use NativeCall;
my sub open (str $pathname, int $flags) returns int is native {*}
my sub read (int $fd, Buf $buf is rw, int $count) returns int is native {*}
my sub close (int $fd) returns int is native {*}
my sub get-input {
# Keystrokes may not be coming in on stdin. Ensure we have the TTY.
open("/dev/tty",0);
}
my sub make-raw ($fd) {
use Term::termios;
my $saved = Term::termios.new(:$fd).getattr;
my $t = Term::termios.new(:$fd).getattr;
# $t.unset_lflags(<ECHO ICANON ISIG IEXTEN>);
$t.unset_lflags(<ECHO ICANON IEXTEN>);
$t.setattr;
$saved;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment