File Coverage

blib/lib/BeamerReveal/Log/Ansi.pm
Criterion Covered Total %
statement 9 45 20.0
branch 0 6 0.0
condition n/a
subroutine 3 12 25.0
pod 2 4 50.0
total 14 67 20.9


line stmt bran cond sub pod time code
1             # -*- cperl -*-
2             # ABSTRACT: Log::Ansi
3              
4              
5             package BeamerReveal::Log::Ansi;
6             our $VERSION = '20260208.1851'; # VERSION
7              
8 1     1   7 use parent 'BeamerReveal::Log';
  1         2  
  1         7  
9 1     1   82 use Carp;
  1         2  
  1         67  
10 1     1   694 use Term::ReadKey;
  1         3215  
  1         904  
11              
12              
13             sub new {
14 0     0 1   my $class = shift;
15 0           my $self = { @_ };
16 0 0         $class = (ref $class ? ref $class : $class );
17 0           bless $self, $class;
18 0           return $self;
19             }
20              
21              
22             sub activate {
23 0     0 1   my $self = shift;
24 0           my $nofTasks = @{$self->{tasks}};
  0            
25             # make initial drawing
26 0           for( my $i = 0; $i < $nofTasks; ++$i ) {
27 0           print "\n";
28             }
29 0           for( my $i = 0; $i < $nofTasks; ++$i ) {
30 0           $self->progress( $i, 0 );
31             }
32             }
33              
34             sub progress {
35 0     0 0   my $self = shift;
36 0           my ( $taskId, $progress, $activity, $total ) = @_;
37 0           my $task = $self->{tasks}->[$taskId];
38 0 0         $task->{total} = $total if defined( $total );
39 0 0         $task->{activity} = $activity if defined( $activity );
40 0           $task->{progress} = $progress;
41              
42 0           my $nofTasks = @{$self->{tasks}};
  0            
43              
44 0           _ansi_up( $nofTasks - $taskId );
45 0           _ansi_clr_eol();
46             print BeamerReveal::Log::_bar_line( $task->{label}, $self->{labelsize},
47             $task->{activity}, $self->{activitysize},
48 0           $progress, $task->{total}, $self->{barsize} );
49              
50 0           print "\n" x ( $nofTasks - $taskId );
51             }
52              
53             sub finalize {
54 0     0 0   my $self = shift;
55 0           _ansi_down( scalar @{$self->{tasks}} );
  0            
56 0           print BeamerReveal::Log::_formatLines( $self->{closing}, $self->{termwidth}, $self->{extra} );
57 0           $self->log( '0', 'Done' );
58             }
59              
60 0     0     sub _ansi_up { print "\e[" . $_[0] . "A"; }
61 0     0     sub _ansi_down { print "\e[" . $_[0] . "B"; }
62 0     0     sub _ansi_cr { print "\r"; }
63 0     0     sub _ansi_clr_eol { print "\e[K"; }
64              
65             sub _terminal_width {
66 0     0     my $self = shift;
67 0           my ($cols, $rows) = Term::ReadKey::GetTerminalSize();
68 0           return $cols;
69             };
70              
71             1;
72              
73             __END__