line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Image::TextMode::Writer::ANSI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
560
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
320
|
use charnames ':full'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'Image::TextMode::Writer'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _write { |
9
|
1
|
|
|
1
|
|
2
|
my ( $self, $image, $fh, $options ) = @_; |
10
|
1
|
|
|
|
|
13
|
my ( $width, $height ) = $image->dimensions; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# clear screen |
13
|
1
|
|
|
|
|
36
|
print $fh "\N{ESCAPE}[2J"; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
2
|
my $prevattr = ''; |
16
|
1
|
|
|
|
|
3
|
for my $y ( 0 .. $height - 1 ) { |
17
|
1
|
|
|
|
|
8
|
my $max_x = $image->max_x( $y ); |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
5
|
unless ( defined $max_x ) { |
20
|
0
|
|
|
|
|
0
|
print $fh "\n"; |
21
|
0
|
|
|
|
|
0
|
next; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
3
|
for my $x ( 0 .. $max_x ) { |
25
|
4
|
|
50
|
|
|
17
|
my $pixel = $image->getpixel( $x, $y ) |
26
|
|
|
|
|
|
|
|| { char => ' ', attr => 7 }; |
27
|
4
|
|
|
|
|
27
|
my $attr = _gen_args( $pixel->{ attr } ); |
28
|
4
|
50
|
|
|
|
10
|
if ( $attr ne $prevattr ) { |
29
|
4
|
|
|
|
|
6
|
print $fh "\N{ESCAPE}[0;", _gen_args( $pixel->{ attr } ), 'm'; |
30
|
4
|
|
|
|
|
5
|
$prevattr = $attr; |
31
|
|
|
|
|
|
|
} |
32
|
4
|
|
|
|
|
9
|
print $fh $pixel->{ char }; |
33
|
|
|
|
|
|
|
} |
34
|
1
|
50
|
|
|
|
5
|
print $fh "\n" unless $max_x == 79; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# clear attrs |
38
|
1
|
|
|
|
|
3
|
print $fh "\N{ESCAPE}[0m"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _gen_args { |
42
|
8
|
|
|
8
|
|
10
|
my $attr = shift; |
43
|
8
|
|
|
|
|
9
|
my $fg = 30 + ( $attr & 7 ); |
44
|
8
|
|
|
|
|
5
|
my $bg = 40 + ( ( $attr & 112 ) >> 4 ); |
45
|
8
|
100
|
|
|
|
11
|
my $bl = ( $attr & 128 ) ? 5 : ''; |
46
|
8
|
100
|
|
|
|
11
|
my $in = ( $attr & 8 ) ? 1 : ''; |
47
|
8
|
|
|
|
|
6
|
return join( q{;}, grep { length } ( $bl, $in, $fg, $bg ) ); |
|
32
|
|
|
|
|
39
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 NAME |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Image::TextMode::Writer::ANSI - Writes ANSI files |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Provides writing capabilities for the ANSI format. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 AUTHOR |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Brian Cassidy Ebricas@cpan.orgE |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Copyright 2008-2014 by Brian Cassidy |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
67
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |