Help language development. Donate to The Perl Foundation

Term::termios cpan:TITSUKI last updated on 2018-01-27


Build Status




Class to interface to libc termios functions


use Term::termios;

# Save the previous attrs
my $saved_termios := => 1).getattr;

# Get the existing attrs in order to modify them
my $termios := => 1).getattr;

# Set the tty to raw mode

# You could also do the same in the old-fashioned way
$termios.unset_iflags(<BRKINT ICRNL ISTRIP IXON>);
$termios.unset_lflags(<ECHO ICANON IEXTEN ISIG>);

# Set the modified atributes, delayed until the buffer is emptied

# Loop on characters from STDIN
loop {
   my $c = $*IN.getc;
   print "got: " ~ $c.ord ~ "\r\n";
   last if $c eq 'q';

# Restore the saved, previous attributes before exit

See the manpage man:termios(3) for information about the flags.