line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Raps2::UI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
16
|
use 5.010; |
|
1
|
|
|
|
|
2
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp qw(cluck confess); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
8
|
1
|
|
|
1
|
|
739
|
use POSIX; |
|
1
|
|
|
|
|
6352
|
|
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
3789
|
use Term::ReadLine; |
|
1
|
|
|
|
|
2935
|
|
|
1
|
|
|
|
|
604
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.54'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
1
|
|
my ($obj) = @_; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $ref = {}; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
return bless( $ref, $obj ); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub list { |
22
|
0
|
|
|
0
|
1
|
|
my ( $self, @list ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $format = "%-20s %-20s %s\n"; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
if ( not $self->{list}->{header} ) { |
27
|
0
|
|
|
|
|
|
printf( $format, map { $_->[0] } @list ); |
|
0
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$self->{list}->{header} = 1; |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
0
|
|
|
|
printf( $format, map { $_->[1] // q{} } @list ); |
|
0
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
return 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub read_line { |
36
|
0
|
|
|
0
|
1
|
|
my ( $self, $str, $pre ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Term::ReadLine->new() takes quite long but is not always required. |
39
|
|
|
|
|
|
|
# So create it here (if needed) instead of in ->new |
40
|
0
|
0
|
|
|
|
|
if ( not $self->{term_readline} ) { |
41
|
0
|
|
|
|
|
|
$self->{term_readline} = Term::ReadLine->new('App::Raps2'); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $input = $self->{term_readline}->readline( "${str}: ", $pre ); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $input; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub read_multiline { |
50
|
0
|
|
|
0
|
1
|
|
my ( $self, $str ) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $in; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
say "${str} (^D or empty line to quit)"; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
while ( my $line = $self->read_line('multiline') ) { |
57
|
0
|
|
|
|
|
|
$in .= "${line}\n"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $in; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub read_pw { |
64
|
0
|
|
|
0
|
1
|
|
my ( $self, $str, $verify ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my ( $in1, $in2 ); |
67
|
0
|
|
|
|
|
|
my $term = POSIX::Termios->new(); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$term->getattr(0); |
70
|
0
|
|
|
|
|
|
$term->setlflag( $term->getlflag() & ~POSIX::ECHO ); |
71
|
0
|
|
|
|
|
|
$term->setattr( 0, POSIX::TCSANOW ); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
print "${str}: "; |
74
|
0
|
|
|
|
|
|
$in1 = readline(STDIN); |
75
|
0
|
|
|
|
|
|
print "\n"; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if ($verify) { |
78
|
0
|
|
|
|
|
|
print 'Verify: '; |
79
|
0
|
|
|
|
|
|
$in2 = readline(STDIN); |
80
|
0
|
|
|
|
|
|
print "\n"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
$term->setlflag( $term->getlflag() | POSIX::ECHO ); |
84
|
0
|
|
|
|
|
|
$term->setattr( 0, POSIX::TCSANOW ); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
0
|
|
|
|
if ( $verify and $in1 ne $in2 ) { |
87
|
0
|
|
|
|
|
|
confess('Input lines did not match'); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
chomp $in1; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return $in1; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub to_clipboard { |
96
|
0
|
|
|
0
|
1
|
|
my ( $self, $str, $cmd ) = @_; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
0
|
|
|
|
$cmd //= 'xclip -l 1'; |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
open( my $clipboard, q{|-}, $cmd ) |
101
|
|
|
|
|
|
|
or return; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
print $clipboard $str; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
close($clipboard) |
106
|
|
|
|
|
|
|
or cluck("Failed to close pipe to ${cmd}: ${!}"); |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return 1; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub output { |
112
|
0
|
|
|
0
|
1
|
|
my ( $self, @out ) = @_; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
for my $pair (@out) { |
115
|
0
|
|
0
|
|
|
|
printf( "%-8s : %s\n", $pair->[0], $pair->[1] // q{}, ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return 1; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |