| 1 | package Term::Completion::_POSIX; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use POSIX qw(:termios_h); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use base qw(Term::Completion::_termsize); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | # we use POSIX termios to set the 'raw' tty properties | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | sub set_raw_tty | ||||||||||||||||||||
| 10 | { | ||||||||||||||||||||
| 11 | 1 | ▶ | my __PACKAGE__ $this = shift; | ||||||||||||||||||
|
Subroutine
set_raw_tty: called CC=3 SCAR=22.7
Pod
documented
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | # check if is a TTY | ||||||||||||||||||||
| 14 | 1 | ▶ | return unless -t $this->{in}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | my $fd = fileno($this->{in}); | |||||||||||||||||||
| 17 | 0 | ▶ | my $termios = ($this->{_termios} ||= POSIX::Termios->new($fd)); | ||||||||||||||||||
|
Condition0%0/3
$this->{"_termios"} ||= "POSIX::Termios"->new($fd)
MC/DC0%0/2
$this->{"_termios"} ||= "POSIX::Termios"->new($fd)
$this->{"_termios"}
"POSIX::Termios"->new($fd)
Truth table0%0/3
A ||= B
A= $this->{"_termios"}B= "POSIX::Termios"->new($fd)
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | # now we want 'raw' mode with echo off | ||||||||||||||||||||
| 20 | # according to IO::Stty this is in detail: | ||||||||||||||||||||
| 21 | # -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr | ||||||||||||||||||||
| 22 | # -icrnl -ixon -ixoff -opost -isig -icanon min 1 time 0 -echo | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | # according to Solaris' stty: | ||||||||||||||||||||
| 25 | # cs8 -icanon min 1 time 0 -isig -xcase -inpck -opost -echo | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | # Linux? | ||||||||||||||||||||
| 28 | 0 | my $set_ccflags = CS8; | |||||||||||||||||||
| 29 | 0 | my $unset_ciflags = IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF; | |||||||||||||||||||
| 30 | 0 | my $unset_clflags = ISIG | ICANON | ECHO; | |||||||||||||||||||
| 31 | 0 | my $unset_coflags = OPOST; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | # get & save the original values: | ||||||||||||||||||||
| 34 | 0 | $termios->getattr(); | |||||||||||||||||||
| 35 | 0 | my $c_cflag = $this->{_tty_cflag} = $termios->getcflag; | |||||||||||||||||||
| 36 | 0 | my $c_iflag = $this->{_tty_iflag} = $termios->getiflag; | |||||||||||||||||||
| 37 | 0 | my $c_lflag = $this->{_tty_lflag} = $termios->getlflag; | |||||||||||||||||||
| 38 | 0 | my $c_oflag = $this->{_tty_oflag} = $termios->getoflag; | |||||||||||||||||||
| 39 | 0 | $this->{_tty_vmin} = $termios->getcc(VMIN); | |||||||||||||||||||
| 40 | 0 | $this->{_tty_vtime} = $termios->getcc(VTIME); | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | # now set the values | ||||||||||||||||||||
| 43 | 0 | $c_cflag |= $set_ccflags; | |||||||||||||||||||
| 44 | 0 | $c_iflag &= ~$unset_ciflags; | |||||||||||||||||||
| 45 | 0 | $c_lflag &= ~$unset_clflags; | |||||||||||||||||||
| 46 | 0 | $c_oflag &= ~$unset_coflags; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | $termios->setcflag($c_cflag); | |||||||||||||||||||
| 49 | 0 | $termios->setiflag($c_iflag); | |||||||||||||||||||
| 50 | 0 | $termios->setlflag($c_lflag); | |||||||||||||||||||
| 51 | 0 | $termios->setoflag($c_oflag); | |||||||||||||||||||
| 52 | 0 | $termios->setcc(VMIN,1); # 1 | |||||||||||||||||||
| 53 | 0 | $termios->setcc(VTIME,0); # 0 | |||||||||||||||||||
| 54 | 0 | $termios->setattr($fd, TCSANOW); | |||||||||||||||||||
| 55 | 0 | 1; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | sub reset_tty | ||||||||||||||||||||
| 59 | { | ||||||||||||||||||||
| 60 | 1 | ▶ | my __PACKAGE__ $this = shift; | ||||||||||||||||||
|
Subroutine
reset_tty: called CC=2 SCAR=14.0
Pod
documented
| |||||||||||||||||||||
| 61 | 1 | ▶ | return unless -t $this->{in}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | my $fd = fileno($this->{in}); | |||||||||||||||||||
| 63 | 0 | my $termios = delete $this->{_termios}; | |||||||||||||||||||
| 64 | 0 | $termios->setcflag($this->{_tty_cflag}); | |||||||||||||||||||
| 65 | 0 | $termios->setiflag($this->{_tty_iflag}); | |||||||||||||||||||
| 66 | 0 | $termios->setlflag($this->{_tty_lflag}); | |||||||||||||||||||
| 67 | 0 | $termios->setoflag($this->{_tty_oflag}); | |||||||||||||||||||
| 68 | 0 | $termios->setcc(VMIN, $this->{_tty_vmin}); | |||||||||||||||||||
| 69 | 0 | $termios->setcc(VTIME, $this->{_tty_vtime}); | |||||||||||||||||||
| 70 | 0 | $termios->setattr($fd, TCSANOW); | |||||||||||||||||||
| 71 | 0 | delete $this->{grep(/^_tty_/, keys %$this)}; | |||||||||||||||||||
| 72 | 0 | 1; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | sub get_key | ||||||||||||||||||||
| 76 | { | ||||||||||||||||||||
| 77 | 0 | ▶ | my __PACKAGE__ $this = shift; | ||||||||||||||||||
|
Subroutine
get_key: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 78 | 0 | getc($this->{in}); | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 1 | 1; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||