line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::Completion::_POSIX;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict;
|
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
6
|
use POSIX qw(:termios_h);
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
2754
|
use base qw(Term::Completion::_termsize);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
716
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# we use POSIX termios to set the 'raw' tty properties
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub set_raw_tty
|
10
|
|
|
|
|
|
|
{
|
11
|
1
|
|
|
1
|
1
|
15
|
my __PACKAGE__ $this = shift;
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# check if is a TTY
|
14
|
1
|
50
|
|
|
|
24
|
return unless -t $this->{in};
|
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
0
|
my $fd = fileno($this->{in});
|
17
|
0
|
|
0
|
|
|
0
|
my $termios = ($this->{_termios} ||= 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
|
|
|
|
|
0
|
my $set_ccflags = CS8;
|
29
|
0
|
|
|
|
|
0
|
my $unset_ciflags = IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF;
|
30
|
0
|
|
|
|
|
0
|
my $unset_clflags = ISIG | ICANON | ECHO;
|
31
|
0
|
|
|
|
|
0
|
my $unset_coflags = OPOST;
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# get & save the original values:
|
34
|
0
|
|
|
|
|
0
|
$termios->getattr();
|
35
|
0
|
|
|
|
|
0
|
my $c_cflag = $this->{_tty_cflag} = $termios->getcflag;
|
36
|
0
|
|
|
|
|
0
|
my $c_iflag = $this->{_tty_iflag} = $termios->getiflag;
|
37
|
0
|
|
|
|
|
0
|
my $c_lflag = $this->{_tty_lflag} = $termios->getlflag;
|
38
|
0
|
|
|
|
|
0
|
my $c_oflag = $this->{_tty_oflag} = $termios->getoflag;
|
39
|
0
|
|
|
|
|
0
|
$this->{_tty_vmin} = $termios->getcc(VMIN);
|
40
|
0
|
|
|
|
|
0
|
$this->{_tty_vtime} = $termios->getcc(VTIME);
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# now set the values
|
43
|
0
|
|
|
|
|
0
|
$c_cflag |= $set_ccflags;
|
44
|
0
|
|
|
|
|
0
|
$c_iflag &= ~$unset_ciflags;
|
45
|
0
|
|
|
|
|
0
|
$c_lflag &= ~$unset_clflags;
|
46
|
0
|
|
|
|
|
0
|
$c_oflag &= ~$unset_coflags;
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
$termios->setcflag($c_cflag);
|
49
|
0
|
|
|
|
|
0
|
$termios->setiflag($c_iflag);
|
50
|
0
|
|
|
|
|
0
|
$termios->setlflag($c_lflag);
|
51
|
0
|
|
|
|
|
0
|
$termios->setoflag($c_oflag);
|
52
|
0
|
|
|
|
|
0
|
$termios->setcc(VMIN,1); # 1
|
53
|
0
|
|
|
|
|
0
|
$termios->setcc(VTIME,0); # 0
|
54
|
0
|
|
|
|
|
0
|
$termios->setattr($fd, TCSANOW);
|
55
|
0
|
|
|
|
|
0
|
1;
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub reset_tty
|
59
|
|
|
|
|
|
|
{
|
60
|
1
|
|
|
1
|
1
|
10
|
my __PACKAGE__ $this = shift;
|
61
|
1
|
50
|
|
|
|
7
|
return unless -t $this->{in};
|
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
|
|
|
0
|
1
|
|
my __PACKAGE__ $this = shift;
|
78
|
0
|
|
|
|
|
|
getc($this->{in});
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1;
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__
|