| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::GitHooks::Terminal; |
|
2
|
|
|
|
|
|
|
|
|
3
|
35
|
|
|
35
|
|
17133
|
use strict; |
|
|
35
|
|
|
|
|
41
|
|
|
|
35
|
|
|
|
|
823
|
|
|
4
|
35
|
|
|
35
|
|
106
|
use warnings; |
|
|
35
|
|
|
|
|
34
|
|
|
|
35
|
|
|
|
|
641
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# External dependencies. |
|
7
|
35
|
|
|
35
|
|
97
|
use Carp; |
|
|
35
|
|
|
|
|
37
|
|
|
|
35
|
|
|
|
|
1488
|
|
|
8
|
35
|
|
|
35
|
|
13118
|
use Term::Encoding (); |
|
|
35
|
|
|
|
|
14398
|
|
|
|
35
|
|
|
|
|
535
|
|
|
9
|
35
|
|
|
35
|
|
15897
|
use Term::ReadKey (); |
|
|
35
|
|
|
|
|
99335
|
|
|
|
35
|
|
|
|
|
9929
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
App::GitHooks::Terminal - Information about the current terminal in which App::GitHook is running. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 1.8.0 |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '1.8.0'; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use App::GitHooks::Terminal; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $terminal = App::GitHooks::Terminal->new(); |
|
31
|
|
|
|
|
|
|
my $get_encoding = $terminal->get_encoding(); |
|
32
|
|
|
|
|
|
|
my $get_width = $terminal->get_width(); |
|
33
|
|
|
|
|
|
|
my $is_interactive = $terminal->is_interactive(); |
|
34
|
|
|
|
|
|
|
my $is_utf8 = $terminal->is_utf8(); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 new() |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Return a new C object. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $terminal = App::GitHooks::Terminal->new(); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
48
|
|
|
48
|
1
|
17617
|
my ( $class ) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
48
|
|
|
|
|
375
|
return bless( |
|
52
|
|
|
|
|
|
|
{}, |
|
53
|
|
|
|
|
|
|
$class, |
|
54
|
|
|
|
|
|
|
); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 get_encoding() |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Determine the current terminal's encoding. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $get_encoding = $terminal->get_encoding(); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_encoding |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
21
|
|
|
21
|
1
|
63
|
my ( $self ) = @_; |
|
69
|
|
|
|
|
|
|
|
|
70
|
21
|
|
66
|
|
|
123
|
$self->{'encoding'} //= Term::Encoding::term_encoding(); |
|
71
|
|
|
|
|
|
|
|
|
72
|
21
|
|
|
|
|
18427
|
return $self->{'encoding'}; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 get_width() |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Get the width (in the number of characters) of the current terminal. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $get_width = $terminal->get_width(); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub get_width |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
24
|
|
|
24
|
1
|
80
|
my ( $self ) = @_; |
|
87
|
|
|
|
|
|
|
|
|
88
|
24
|
50
|
33
|
|
|
94
|
if ( $self->is_interactive() && !defined( $self->{'width'} ) ) |
|
89
|
|
|
|
|
|
|
{ |
|
90
|
0
|
|
|
|
|
0
|
my $output_width = (Term::ReadKey::GetTerminalSize())[0]; |
|
91
|
0
|
|
0
|
|
|
0
|
$output_width //= 80; |
|
92
|
0
|
|
|
|
|
0
|
$self->{'width'} = $output_width; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
24
|
|
|
|
|
86
|
return $self->{'width'}; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 is_interactive() |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Determine whether the current terminal is interactive or not. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $is_interactive = $terminal->is_interactive(); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub is_interactive |
|
108
|
|
|
|
|
|
|
{ |
|
109
|
43
|
|
|
43
|
1
|
97
|
my ( $self ) = @_; |
|
110
|
|
|
|
|
|
|
|
|
111
|
43
|
100
|
|
|
|
128
|
if ( !defined( $self->{'is_interactive'} ) ) |
|
112
|
|
|
|
|
|
|
{ |
|
113
|
17
|
50
|
|
|
|
98
|
$self->{'is_interactive'} = -t STDOUT ? 1 : 0; ## no critic (InputOutput::ProhibitInteractiveTest) |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
43
|
|
|
|
|
205
|
return $self->{'is_interactive'}; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 is_utf8() |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Determine if the current terminal supports utf-8. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $is_utf8 = $terminal->is_utf8(); |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Optionally, you can override the utf-8 support by passing an extra boolean |
|
127
|
|
|
|
|
|
|
argument: |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$terminal->is_utf8(1); # Force utf-8 output. |
|
130
|
|
|
|
|
|
|
$terminal->is_utf8(0); # Force non-utf-8 output. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub is_utf8 |
|
135
|
|
|
|
|
|
|
{ |
|
136
|
48
|
|
|
48
|
1
|
127
|
my ( $self, $value ) = @_; |
|
137
|
|
|
|
|
|
|
|
|
138
|
48
|
100
|
|
|
|
183
|
if ( defined( $value ) ) |
|
|
|
100
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
{ |
|
140
|
17
|
50
|
|
|
|
74
|
croak "Invalid override value" |
|
141
|
|
|
|
|
|
|
if $value !~ /^(?:0|1)$/; |
|
142
|
|
|
|
|
|
|
|
|
143
|
17
|
|
|
|
|
59
|
$self->{'is_utf8'} = $value; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
elsif ( !defined( $self->{'is_utf8'} ) ) |
|
146
|
|
|
|
|
|
|
{ |
|
147
|
2
|
|
|
|
|
9
|
my $terminal_encoding = $self->get_encoding(); |
|
148
|
2
|
50
|
|
|
|
11
|
$self->{'is_utf8'} = $terminal_encoding =~ /^utf-?8$/xi ? 1 : 0; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
48
|
|
|
|
|
155
|
return $self->{'is_utf8'}; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 BUGS |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
|
158
|
|
|
|
|
|
|
L. |
|
159
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
160
|
|
|
|
|
|
|
your bug as I make changes. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SUPPORT |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
perldoc App::GitHooks::Terminal |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
You can also look for information at: |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=over |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * GitHub's request tracker |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
L |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
L |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * MetaCPAN |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
L |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=back |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 AUTHOR |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
L, |
|
196
|
|
|
|
|
|
|
C<< >>. |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Copyright 2013-2016 Guillaume Aubert. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
This code is free software; you can redistribute it and/or modify it under the |
|
204
|
|
|
|
|
|
|
same terms as Perl 5 itself. |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY |
|
207
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
|
208
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the LICENSE file for more details. |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
1; |