Created
November 25, 2015 03:13
-
-
Save skids/0b1cfabedddd95a824c8 to your computer and use it in GitHub Desktop.
snippet from some terminal code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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