line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Documentation at the __END__ |
2
|
|
|
|
|
|
|
# -*-cperl-*- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package IO::Tty; |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
29
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
113
|
|
7
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
99
|
|
8
|
4
|
|
|
4
|
|
2143
|
use IO::Handle; |
|
4
|
|
|
|
|
25181
|
|
|
4
|
|
|
|
|
176
|
|
9
|
4
|
|
|
4
|
|
1965
|
use IO::File; |
|
4
|
|
|
|
|
7786
|
|
|
4
|
|
|
|
|
418
|
|
10
|
4
|
|
|
4
|
|
1770
|
use IO::Tty::Constant; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
178
|
|
11
|
4
|
|
|
4
|
|
28
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
275
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require POSIX; |
14
|
|
|
|
|
|
|
require DynaLoader; |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
21
|
use vars qw(@ISA $VERSION $XS_VERSION $CONFIG $DEBUG); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
3280
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$VERSION = '1.17'; |
19
|
|
|
|
|
|
|
$XS_VERSION = "1.17"; |
20
|
|
|
|
|
|
|
@ISA = qw(IO::Handle); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
eval { local $^W = 0; undef local $SIG{__DIE__}; require IO::Stty }; |
23
|
|
|
|
|
|
|
push @ISA, "IO::Stty" if ( not $@ ); # if IO::Stty is installed |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
BOOT_XS: { |
26
|
|
|
|
|
|
|
# If I inherit DynaLoader then I inherit AutoLoader and I DON'T WANT TO |
27
|
|
|
|
|
|
|
require DynaLoader; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# DynaLoader calls dl_load_flags as a static method. |
30
|
|
|
|
|
|
|
*dl_load_flags = DynaLoader->can('dl_load_flags'); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
do { |
33
|
|
|
|
|
|
|
defined(&bootstrap) |
34
|
|
|
|
|
|
|
? \&bootstrap |
35
|
|
|
|
|
|
|
: \&DynaLoader::bootstrap; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
->(__PACKAGE__); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub import { |
41
|
7
|
|
|
7
|
|
10762
|
IO::Tty::Constant->export_to_level( 1, @_ ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub open { |
45
|
0
|
|
|
0
|
0
|
0
|
my ( $tty, $dev, $mode ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
0
|
IO::File::open( $tty, $dev, $mode ) |
48
|
|
|
|
|
|
|
or return undef; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
$tty->autoflush; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub clone_winsize_from { |
56
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $fh ) = @_; |
57
|
0
|
0
|
|
|
|
0
|
croak "Given filehandle is not a tty in clone_winsize_from, called" |
58
|
|
|
|
|
|
|
if not POSIX::isatty($fh); |
59
|
0
|
0
|
|
|
|
0
|
return 1 if not POSIX::isatty($self); # ignored for master ptys |
60
|
0
|
|
|
|
|
0
|
my $winsize = " " x 1024; # preallocate memory for older perl versions |
61
|
0
|
|
|
|
|
0
|
$winsize = ''; # But leave the SV as empty |
62
|
0
|
0
|
0
|
|
|
0
|
ioctl( $fh, &IO::Tty::Constant::TIOCGWINSZ, $winsize ) |
63
|
|
|
|
|
|
|
and ioctl( $self, &IO::Tty::Constant::TIOCSWINSZ, $winsize ) |
64
|
|
|
|
|
|
|
and return 1; |
65
|
0
|
0
|
|
|
|
0
|
warn "clone_winsize_from: error: $!" if $^W; |
66
|
0
|
|
|
|
|
0
|
return undef; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# ioctl() doesn't tell us how long the structure is, so we'll have to trim it |
70
|
|
|
|
|
|
|
# after TIOCGWINSZ |
71
|
|
|
|
|
|
|
my $SIZEOF_WINSIZE = length IO::Tty::pack_winsize( 0, 0, 0, 0 ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub get_winsize { |
74
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
75
|
1
|
|
|
|
|
24
|
my $winsize = " " x 1024; # preallocate memory |
76
|
1
|
50
|
|
|
|
32
|
ioctl( $self, IO::Tty::Constant::TIOCGWINSZ(), $winsize ) |
77
|
|
|
|
|
|
|
or croak "Cannot TIOCGWINSZ - $!"; |
78
|
1
|
|
|
|
|
4
|
substr( $winsize, $SIZEOF_WINSIZE ) = ""; |
79
|
1
|
|
|
|
|
91
|
return IO::Tty::unpack_winsize($winsize); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub set_winsize { |
83
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
84
|
0
|
|
|
|
|
0
|
my $winsize = IO::Tty::pack_winsize(@_); |
85
|
0
|
0
|
|
|
|
0
|
ioctl( $self, IO::Tty::Constant::TIOCSWINSZ(), $winsize ) |
86
|
|
|
|
|
|
|
or croak "Cannot TIOCSWINSZ - $!"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub set_raw($) { |
90
|
3
|
|
|
3
|
0
|
3579
|
require POSIX; |
91
|
3
|
|
|
|
|
18
|
my $self = shift; |
92
|
3
|
50
|
|
|
|
79
|
return 1 if not POSIX::isatty($self); |
93
|
3
|
|
|
|
|
55
|
my $ttyno = fileno($self); |
94
|
3
|
|
|
|
|
83
|
my $termios = new POSIX::Termios; |
95
|
3
|
50
|
|
|
|
37
|
unless ($termios) { |
96
|
0
|
|
|
|
|
0
|
warn "set_raw: new POSIX::Termios failed: $!"; |
97
|
0
|
|
|
|
|
0
|
return undef; |
98
|
|
|
|
|
|
|
} |
99
|
3
|
50
|
|
|
|
41
|
unless ( $termios->getattr($ttyno) ) { |
100
|
0
|
|
|
|
|
0
|
warn "set_raw: getattr($ttyno) failed: $!"; |
101
|
0
|
|
|
|
|
0
|
return undef; |
102
|
|
|
|
|
|
|
} |
103
|
3
|
|
|
|
|
30
|
$termios->setiflag(0); |
104
|
3
|
|
|
|
|
20
|
$termios->setoflag(0); |
105
|
3
|
|
|
|
|
10
|
$termios->setlflag(0); |
106
|
3
|
|
|
|
|
34
|
$termios->setcc( &POSIX::VMIN, 1 ); |
107
|
3
|
|
|
|
|
21
|
$termios->setcc( &POSIX::VTIME, 0 ); |
108
|
3
|
50
|
|
|
|
56
|
unless ( $termios->setattr( $ttyno, &POSIX::TCSANOW ) ) { |
109
|
0
|
|
|
|
|
0
|
warn "set_raw: setattr($ttyno) failed: $!"; |
110
|
0
|
|
|
|
|
0
|
return undef; |
111
|
|
|
|
|
|
|
} |
112
|
3
|
|
|
|
|
46
|
return 1; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |