| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::JobLog::Log::Format; | 
| 2 |  |  |  |  |  |  | $App::JobLog::Log::Format::VERSION = '1.040'; | 
| 3 |  |  |  |  |  |  | # ABSTRACT: pretty printer for log | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 2 |  |  | 2 |  | 1306 | use Exporter 'import'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 98 |  | 
| 7 |  |  |  |  |  |  | our @EXPORT_OK = qw( | 
| 8 |  |  |  |  |  |  | display | 
| 9 |  |  |  |  |  |  | duration | 
| 10 |  |  |  |  |  |  | single_interval | 
| 11 |  |  |  |  |  |  | summary | 
| 12 |  |  |  |  |  |  | wrap | 
| 13 |  |  |  |  |  |  | ); | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 2 |  |  | 2 |  | 11 | use Modern::Perl; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 21 |  | 
| 16 | 2 |  |  |  |  | 112 | use App::JobLog::Config qw( | 
| 17 |  |  |  |  |  |  | day_length | 
| 18 |  |  |  |  |  |  | is_workday | 
| 19 |  |  |  |  |  |  | precision | 
| 20 | 2 |  |  | 2 |  | 243 | ); | 
|  | 2 |  |  |  |  | 4 |  | 
| 21 | 2 |  |  | 2 |  | 12 | use App::JobLog::Log::Synopsis qw(collect :merge); | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 331 |  | 
| 22 | 2 |  |  | 2 |  | 1414 | use Text::WrapI18N qw(); | 
|  | 2 |  |  |  |  | 4979 |  | 
|  | 2 |  |  |  |  | 49 |  | 
| 23 | 2 |  |  | 2 |  | 1513 | use App::JobLog::TimeGrammar qw(parse); | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 132 |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 2 |  |  | 2 |  | 17 | use constant TAG_COLUMN_LIMIT => 10; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 133 |  | 
| 26 | 2 |  |  | 2 |  | 10 | use constant MARGIN           => 5; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1913 |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | # minimum width of description column | 
| 29 | 2 |  |  | 2 |  | 11 | use constant MIN_WIDTH       => 20; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 110 |  | 
| 30 | 2 |  |  | 2 |  | 10 | use constant DURATION_FORMAT => '%0.' . precision . 'f'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 11 |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub summary { | 
| 34 | 15 |  |  | 15 | 0 | 418 | my ( $phrase, $test, $hidden, $do_notes ) = @_; | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # we skip flex days if the events are at all filtered | 
| 37 | 15 |  | 66 |  |  | 127 | my $skip_flex = !$do_notes && ( $test || 0 ); | 
| 38 | 15 |  | 100 | 197 |  | 158 | $test //= sub { $_[0] }; | 
|  | 197 |  |  |  |  | 698 |  | 
| 39 | 15 |  |  |  |  | 95 | my ( $start, $end ) = parse $phrase; | 
| 40 | 15 |  |  |  |  | 61 | my $show_year = $start->year < $end->year; | 
| 41 | 15 | 100 |  |  |  | 177 | unless ($skip_flex) { | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | # if we are chopping off any of the first and last days we ignore flex time | 
| 44 | 9 | 100 | 66 |  |  | 61 | $skip_flex = 1 | 
|  |  |  | 66 |  |  |  |  | 
| 45 |  |  |  |  |  |  | unless $do_notes || _break_of_dawn($start) && _witching_hour($end); | 
| 46 |  |  |  |  |  |  | } | 
| 47 | 15 | 100 |  |  |  | 141 | my $method = $do_notes ? 'find_notes' : 'find_events'; | 
| 48 | 15 |  |  |  |  | 130 | my $events = App::JobLog::Log->new->$method( $start, $end ); | 
| 49 | 15 |  |  |  |  | 333 | my @days = @{ _days( $start, $end, $skip_flex, $do_notes ) }; | 
|  | 15 |  |  |  |  | 1873 |  | 
| 50 |  |  |  |  |  |  | my @periods = | 
| 51 | 15 | 100 |  |  |  | 662 | $hidden->{vacation} ? () : App::JobLog::Vacation->new->periods; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # drop the vacation days that can't be relevant | 
| 54 | 15 | 100 |  |  |  | 74 | unless ( $hidden->{vacation} ) { | 
| 55 | 13 |  |  |  |  | 112 | my $e = | 
| 56 |  |  |  |  |  |  | App::JobLog::Log::Event->new( | 
| 57 |  |  |  |  |  |  | App::JobLog::Log::Line->new( time => $start ) ); | 
| 58 | 13 |  |  |  |  | 70 | $e->end = $end; | 
| 59 | 13 |  |  |  |  | 92 | for ( my $i = 0 ; $i < @periods ; $i++ ) { | 
| 60 | 0 |  |  |  |  | 0 | my $p = $periods[$i]; | 
| 61 | 0 | 0 | 0 |  |  | 0 | if ( $skip_flex && $p->flex || !$p->conflicts($e) ) { | 
|  |  |  | 0 |  |  |  |  | 
| 62 | 0 |  |  |  |  | 0 | splice @periods, $i, 1; | 
| 63 | 0 |  |  |  |  | 0 | $i--; | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | # collect events into days | 
| 69 | 15 |  |  |  |  | 33 | my @gathered; | 
| 70 | 15 |  |  |  |  | 49 | for my $big_e (@$events) { | 
| 71 | 203 |  |  |  |  | 962 | for my $e ( $big_e->split_days ) { | 
| 72 | 205 | 100 |  |  |  | 483 | if ( $e = $test->($e) ) { | 
| 73 | 203 |  | 100 |  |  | 991 | push @gathered, shift @days | 
| 74 |  |  |  |  |  |  | while @days && $days[0]->end < $e->start; | 
| 75 | 203 |  |  |  |  | 18765 | for my $d (@days) { | 
| 76 | 233 | 100 |  |  |  | 3418 | if ( $e->intersects( $d->pseudo_event ) ) { | 
| 77 | 200 |  |  |  |  | 18498 | push @{ $d->events }, $e; | 
|  | 200 |  |  |  |  | 592 |  | 
| 78 | 200 |  |  |  |  | 836 | last; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | # I believe these is_open bits are mistaken | 
| 82 |  |  |  |  |  |  | # last if $e->is_open; | 
| 83 | 33 | 50 |  |  |  | 3162 | unless ($do_notes) { | 
| 84 | 33 | 50 |  |  |  | 105 | last if $d->start > $e->end; | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  | } | 
| 90 | 15 |  |  |  |  | 208 | unshift @days, @gathered; | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | # add in vacation times | 
| 93 | 15 |  |  |  |  | 47 | for my $p (@periods) { | 
| 94 | 0 |  |  |  |  | 0 | for my $d (@days) { | 
| 95 | 0 | 0 | 0 |  |  | 0 | if ( is_workday( $d->start ) && $p->conflicts( $d->pseudo_event ) ) | 
| 96 |  |  |  |  |  |  | { | 
| 97 | 0 |  |  |  |  | 0 | my $clone = $p->clone; | 
| 98 | 0 | 0 |  |  |  | 0 | if ( $clone->fixed ) { | 
| 99 | 0 |  |  |  |  | 0 | push @{ $d->events }, $clone->overlap( $d->start, $d->end ); | 
|  | 0 |  |  |  |  | 0 |  | 
| 100 |  |  |  |  |  |  | } | 
| 101 |  |  |  |  |  |  | else { | 
| 102 | 0 |  |  |  |  | 0 | $clone->start = $d->start->clone; | 
| 103 | 0 | 0 |  |  |  | 0 | if ( $clone->flex ) { | 
| 104 | 0 |  |  |  |  | 0 | $d->{deferred} = $clone; | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  | else { | 
| 107 | 0 |  |  |  |  | 0 | $clone->end = | 
| 108 |  |  |  |  |  |  | $clone->start->clone->add( hours => day_length ); | 
| 109 | 0 |  |  |  |  | 0 | push @{ $d->vacation }, $clone; | 
|  | 0 |  |  |  |  | 0 |  | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  | } | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | # delete empty days | 
| 117 | 15 |  |  |  |  | 68 | for ( my $i = 0 ; $i < @days ; $i++ ) { | 
| 118 | 11133 |  |  |  |  | 72834 | my $d = $days[$i]; | 
| 119 | 11133 | 100 | 100 |  |  | 29649 | if ( $d->is_empty && !is_workday( $d->start ) ) { | 
| 120 | 3163 |  |  |  |  | 22725 | splice @days, $i, 1; | 
| 121 | 3163 |  |  |  |  | 24150 | $i--; | 
| 122 |  |  |  |  |  |  | } | 
| 123 |  |  |  |  |  |  | } | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | # fix deferred flex time and ensure events are chronologically ordered | 
| 126 | 15 |  |  |  |  | 52 | for my $d (@days) { | 
| 127 | 7970 |  |  |  |  | 18137 | my $flex   = $d->{deferred}; | 
| 128 | 7970 |  |  |  |  | 10578 | my @events = @{ $d->events }; | 
|  | 7970 |  |  |  |  | 20199 |  | 
| 129 | 7970 | 50 |  |  |  | 16844 | if ($flex) { | 
| 130 | 0 |  |  |  |  | 0 | delete $d->{deferred}; | 
| 131 | 0 |  |  |  |  | 0 | my $tr = $d->time_remaining; | 
| 132 | 0 | 0 |  |  |  | 0 | if ( $tr > 0 ) { | 
| 133 | 0 |  |  |  |  | 0 | $flex->end = $flex->start->clone->add( seconds => $tr ); | 
| 134 | 0 |  |  |  |  | 0 | push @events, $flex; | 
| 135 |  |  |  |  |  |  | } | 
| 136 |  |  |  |  |  |  | } | 
| 137 | 7970 | 100 |  |  |  | 19775 | $d->{events} = [ sort { $a->cmp($b) } @events ] if @events > 1; | 
|  | 155 |  |  |  |  | 374 |  | 
| 138 |  |  |  |  |  |  | } | 
| 139 |  |  |  |  |  |  |  | 
| 140 | 15 |  |  |  |  | 353 | return \@days, $show_year; | 
| 141 |  |  |  |  |  |  | } | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | # whether the date is the first moment in its day | 
| 144 |  |  |  |  |  |  | sub _break_of_dawn { | 
| 145 | 7 |  |  | 7 |  | 18 | my ($date) = @_; | 
| 146 | 7 |  | 66 |  |  | 28 | return $date->hour == 0 && $date->minute == 0 && $date->second == 0; | 
| 147 |  |  |  |  |  |  | } | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | # whether the date is the last moment in its day | 
| 150 |  |  |  |  |  |  | sub _witching_hour { | 
| 151 | 2 |  |  | 2 |  | 71 | my ($date) = @_; | 
| 152 | 2 |  | 33 |  |  | 8 | return $date->hour == 23 && $date->minute == 59 && $date->second == 59; | 
| 153 |  |  |  |  |  |  | } | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | # create a list of days about which we wish to collect information | 
| 156 |  |  |  |  |  |  | sub _days { | 
| 157 | 15 |  |  | 15 |  | 63 | my ( $start, $end, $skip_flex, $doing_notes ) = @_; | 
| 158 | 15 |  |  |  |  | 28 | my @days; | 
| 159 | 15 |  |  |  |  | 40 | my $b1 = $start; | 
| 160 | 15 |  |  |  |  | 78 | my $b2 = $start->clone->add( days => 1 )->truncate( to => 'day' ); | 
| 161 | 15 |  |  |  |  | 24707 | while ( $b2 < $end ) { | 
| 162 | 11118 | 100 |  |  |  | 11430168 | push @days, | 
| 163 |  |  |  |  |  |  | App::JobLog::Log::Day->new( | 
| 164 |  |  |  |  |  |  | start     => $b1, | 
| 165 |  |  |  |  |  |  | end       => $b2, | 
| 166 |  |  |  |  |  |  | skip_flex => $skip_flex, | 
| 167 |  |  |  |  |  |  | $doing_notes ? ( notes => 1 ) : (), | 
| 168 |  |  |  |  |  |  | ); | 
| 169 | 11118 |  |  |  |  | 21273 | $b1 = $b2; | 
| 170 | 11118 |  |  |  |  | 33212 | $b2 = $b2->clone->add( days => 1 ); | 
| 171 |  |  |  |  |  |  | } | 
| 172 | 15 | 100 |  |  |  | 10020 | push @days, | 
| 173 |  |  |  |  |  |  | App::JobLog::Log::Day->new( | 
| 174 |  |  |  |  |  |  | start     => $b1, | 
| 175 |  |  |  |  |  |  | end       => $end, | 
| 176 |  |  |  |  |  |  | skip_flex => $skip_flex, | 
| 177 |  |  |  |  |  |  | $doing_notes ? ( notes => 1 ) : (), | 
| 178 |  |  |  |  |  |  | ); | 
| 179 | 15 |  |  |  |  | 4022 | return \@days; | 
| 180 |  |  |  |  |  |  | } | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | sub display { | 
| 184 | 15 |  |  | 15 | 1 | 308 | my ( $days, $merge_level, $hidden, $screen_width, $show_year ) = @_; | 
| 185 |  |  |  |  |  |  |  | 
| 186 | 15 | 50 |  |  |  | 121 | if (@$days) { | 
| 187 | 15 |  |  |  |  | 247 | collect $_, $merge_level for @$days; | 
| 188 | 15 |  |  |  |  | 127 | my @synopses = map { @{ $_->synopses } } @$days; | 
|  | 7970 |  |  |  |  | 10059 |  | 
|  | 7970 |  |  |  |  | 18851 |  | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | my $columns = { | 
| 191 |  |  |  |  |  |  | time => single_interval($merge_level) && !$hidden->{time}, | 
| 192 |  |  |  |  |  |  | date => !$hidden->{date}, | 
| 193 |  |  |  |  |  |  | tags => !$hidden->{tags}, | 
| 194 |  |  |  |  |  |  | description => !$hidden->{description}, | 
| 195 |  |  |  |  |  |  | duration    => !$hidden->{duration}, | 
| 196 | 15 |  | 33 |  |  | 123 | }; | 
| 197 | 15 |  | 66 |  |  | 116 | $show_year &&= $columns->{date}; | 
| 198 | 15 |  |  |  |  | 121 | my $format = _define_format( \@synopses, $columns, $screen_width ); | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | # keep track of various durations | 
| 201 | 15 |  |  |  |  | 230 | my $times = { | 
| 202 |  |  |  |  |  |  | total    => 0, | 
| 203 |  |  |  |  |  |  | untagged => 0, | 
| 204 |  |  |  |  |  |  | expected => 0, | 
| 205 |  |  |  |  |  |  | vacation => 0, | 
| 206 |  |  |  |  |  |  | tags     => {} | 
| 207 |  |  |  |  |  |  | }; | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | # display synopses and add up durations | 
| 210 | 15 |  |  |  |  | 71 | for my $d (@$days) { | 
| 211 | 7970 |  |  |  |  | 20739 | $d->times($times); | 
| 212 | 7970 |  |  |  |  | 64068 | $d->display( $format, $columns, $screen_width, $show_year ); | 
| 213 |  |  |  |  |  |  | } | 
| 214 |  |  |  |  |  |  |  | 
| 215 | 15 | 100 |  |  |  | 265 | unless ( $hidden->{totals} ) { | 
| 216 |  |  |  |  |  |  | my ( $m1, $m2 ) = | 
| 217 | 13 |  |  |  |  | 79 | ( length 'TOTAL HOURS', length duration( $times->{total} ) ); | 
| 218 | 13 |  |  |  |  | 37 | my @keys = keys %{ $times->{tags} }; | 
|  | 13 |  |  |  |  | 93 |  | 
| 219 | 13 | 100 |  |  |  | 95 | push @keys, 'UNTAGGED' if $times->{untagged}; | 
| 220 | 13 | 50 |  |  |  | 63 | push @keys, 'VACATION' if $times->{vacation}; | 
| 221 | 13 |  |  |  |  | 38 | for my $tag (@keys) { | 
| 222 | 14 |  |  |  |  | 53 | my $l = length $tag; | 
| 223 | 14 | 50 |  |  |  | 64 | $m1 = $l if $l > $m1; | 
| 224 |  |  |  |  |  |  | } | 
| 225 | 13 |  |  |  |  | 77 | $format = sprintf "  %%-%ds %%%ds\n", $m1, $m2; | 
| 226 | 13 |  |  |  |  | 48 | printf $format, 'TOTAL HOURS', duration( $times->{total} ); | 
| 227 |  |  |  |  |  |  | printf $format, 'VACATION',    duration( $times->{vacation} ) | 
| 228 | 13 | 50 |  |  |  | 416 | if $times->{vacation}; | 
| 229 | 13 | 100 |  |  |  | 24 | if ( %{ $times->{tags} } ) { | 
|  | 13 |  |  |  |  | 100 |  | 
| 230 |  |  |  |  |  |  | printf $format, 'UNTAGGED', duration( $times->{untagged} ) | 
| 231 | 11 | 50 |  |  |  | 60 | if $times->{untagged}; | 
| 232 | 11 |  |  |  |  | 39 | for my $key ( sort keys %{ $times->{tags} } ) { | 
|  | 11 |  |  |  |  | 62 |  | 
| 233 | 12 |  |  |  |  | 68 | my $d = $times->{tags}{$key}; | 
| 234 | 12 |  |  |  |  | 54 | printf $format, $key, duration($d); | 
| 235 |  |  |  |  |  |  | } | 
| 236 |  |  |  |  |  |  | } | 
| 237 |  |  |  |  |  |  | } | 
| 238 |  |  |  |  |  |  | } | 
| 239 |  |  |  |  |  |  | else { | 
| 240 | 0 |  |  |  |  | 0 | say 'No events in interval specified.'; | 
| 241 |  |  |  |  |  |  | } | 
| 242 |  |  |  |  |  |  | } | 
| 243 |  |  |  |  |  |  |  | 
| 244 |  |  |  |  |  |  | # generate printf format for synopses | 
| 245 |  |  |  |  |  |  | # returns format and wrap widths for tags and descriptions | 
| 246 |  |  |  |  |  |  | sub _define_format { | 
| 247 | 15 |  |  | 15 |  | 40 | my ( $synopses, $hash, $screen_width ) = @_; | 
| 248 |  |  |  |  |  |  |  | 
| 249 |  |  |  |  |  |  | #determine maximum width of each column | 
| 250 | 15 |  |  |  |  | 41 | my $widths; | 
| 251 | 15 |  |  |  |  | 65 | for my $s (@$synopses) { | 
| 252 | 76 | 50 |  |  |  | 342 | if ( $hash->{tags} ) { | 
| 253 | 76 |  | 50 |  |  | 445 | my $w1 = $hash->{widths}{tags} || 0; | 
| 254 | 76 |  |  |  |  | 290 | my $ts = $s->tag_string; | 
| 255 | 76 | 50 | 66 |  |  | 320 | if ( $screen_width > -1 && length $ts > TAG_COLUMN_LIMIT ) { | 
| 256 | 0 |  |  |  |  | 0 | my $wrapped = wrap( $ts, TAG_COLUMN_LIMIT ); | 
| 257 | 0 |  |  |  |  | 0 | $ts = ''; | 
| 258 | 0 |  |  |  |  | 0 | for my $line (@$wrapped) { | 
| 259 | 0 | 0 |  |  |  | 0 | $ts = $line if length $line > length $ts; | 
| 260 |  |  |  |  |  |  | } | 
| 261 |  |  |  |  |  |  | } | 
| 262 | 76 |  |  |  |  | 139 | my $w2 = length $ts; | 
| 263 | 76 | 100 |  |  |  | 223 | $hash->{widths}{tags} = $w2 if $w2 > $w1; | 
| 264 |  |  |  |  |  |  | } | 
| 265 | 76 | 50 |  |  |  | 221 | if ( $hash->{time} ) { | 
| 266 | 76 |  | 100 |  |  | 255 | my $w1 = $hash->{widths}{time} || 0; | 
| 267 | 76 |  |  |  |  | 247 | my $w2 = length $s->time_fmt; | 
| 268 | 76 | 100 |  |  |  | 336 | $hash->{widths}{time} = $w2 if $w2 > $w1; | 
| 269 |  |  |  |  |  |  | } | 
| 270 | 76 | 100 |  |  |  | 273 | if ( $hash->{duration} ) { | 
| 271 | 44 |  | 100 |  |  | 168 | my $w1 = $hash->{widths}{duration} || 0; | 
| 272 | 44 |  |  |  |  | 208 | my $w2 = length duration( $s->duration ); | 
| 273 | 44 | 100 |  |  |  | 220 | $hash->{widths}{duration} = $w2 if $w2 > $w1; | 
| 274 |  |  |  |  |  |  | } | 
| 275 |  |  |  |  |  |  | } | 
| 276 | 15 |  |  |  |  | 102 | my $margins = 0; | 
| 277 | 15 | 100 | 33 |  |  | 196 | if ( $hash->{tags} && $hash->{widths}{tags} ) { | 
| 278 | 11 |  |  |  |  | 48 | $margins++; | 
| 279 | 11 |  |  |  |  | 202 | $hash->{formats}{tags} = sprintf '%%-%ds', $hash->{widths}{tags}; | 
| 280 |  |  |  |  |  |  |  | 
| 281 |  |  |  |  |  |  | # there seems to be a bug in Text::Wrap that requires tinkering with the column width | 
| 282 | 11 |  |  |  |  | 49 | $hash->{widths}{tags}++; | 
| 283 |  |  |  |  |  |  | } | 
| 284 | 15 | 50 | 33 |  |  | 137 | if ( $hash->{time} && $hash->{widths}{time} ) { | 
| 285 | 15 |  |  |  |  | 29 | $margins++; | 
| 286 | 15 |  |  |  |  | 100 | $hash->{formats}{time} = sprintf '%%%ds', $hash->{widths}{time}; | 
| 287 |  |  |  |  |  |  | } | 
| 288 | 15 | 50 | 66 |  |  | 121 | if ( $hash->{duration} && $hash->{widths}{duration} ) { | 
| 289 | 13 |  |  |  |  | 20 | $margins++; | 
| 290 | 13 |  |  |  |  | 63 | $hash->{formats}{duration} = sprintf '%%%ds', $hash->{widths}{duration}; | 
| 291 |  |  |  |  |  |  | } | 
| 292 | 15 | 50 |  |  |  | 142 | if ( $hash->{description} ) { | 
| 293 | 15 | 100 |  |  |  | 52 | if ( $screen_width == -1 ) { | 
| 294 | 3 |  |  |  |  | 11 | $hash->{formats}{description} = '%s'; | 
| 295 |  |  |  |  |  |  | } | 
| 296 |  |  |  |  |  |  | else { | 
| 297 | 12 |  |  |  |  | 30 | $margins++; | 
| 298 | 12 |  |  |  |  | 47 | my $max_description = $screen_width; | 
| 299 | 12 |  |  |  |  | 67 | for my $col (qw(time duration tags)) { | 
| 300 | 36 |  | 100 |  |  | 195 | $max_description -= $hash->{widths}{$col} || 0; | 
| 301 |  |  |  |  |  |  | } | 
| 302 | 12 |  |  |  |  | 41 | $max_description -= $margins * 2;    # left margins | 
| 303 | 12 |  |  |  |  | 45 | $max_description -= MARGIN;          # margin on the right | 
| 304 | 12 | 50 |  |  |  | 92 | $max_description = MIN_WIDTH if $max_description < MIN_WIDTH; | 
| 305 | 12 |  |  |  |  | 42 | $hash->{widths}{description} = $max_description; | 
| 306 | 12 |  |  |  |  | 87 | $hash->{formats}{description} = sprintf '%%-%ds', $max_description; | 
| 307 |  |  |  |  |  |  | } | 
| 308 |  |  |  |  |  |  | } | 
| 309 |  |  |  |  |  |  |  | 
| 310 | 15 |  |  |  |  | 49 | my $format = ''; | 
| 311 | 15 |  |  |  |  | 59 | for my $col (qw(time duration tags description)) { | 
| 312 | 60 |  |  |  |  | 111 | my $f = $hash->{formats}{$col}; | 
| 313 | 60 | 100 |  |  |  | 208 | $format .= "  $f" if $f; | 
| 314 |  |  |  |  |  |  | } | 
| 315 | 15 |  |  |  |  | 78 | return $format; | 
| 316 |  |  |  |  |  |  | } | 
| 317 |  |  |  |  |  |  |  | 
| 318 |  |  |  |  |  |  |  | 
| 319 |  |  |  |  |  |  | sub wrap { | 
| 320 | 24 |  |  | 24 | 1 | 72 | my ( $text, $columns ) = @_; | 
| 321 | 24 |  |  |  |  | 48 | my @ar; | 
| 322 | 24 |  |  |  |  | 83 | eval { | 
| 323 | 24 |  |  |  |  | 85 | $Text::WrapI18N::columns = $columns; | 
| 324 | 24 |  |  |  |  | 188 | my $s = Text::WrapI18N::wrap( '', '', $text ); | 
| 325 | 24 |  |  |  |  | 42781 | @ar = $s =~ /^.*$/mg; | 
| 326 |  |  |  |  |  |  | }; | 
| 327 | 24 | 50 |  |  |  | 217 | return \@ar unless $@; | 
| 328 | 0 |  |  |  |  | 0 | return [$text]; | 
| 329 |  |  |  |  |  |  | } | 
| 330 |  |  |  |  |  |  |  | 
| 331 |  |  |  |  |  |  |  | 
| 332 |  |  |  |  |  |  | sub single_interval { | 
| 333 | 15 | 100 | 66 | 15 | 0 | 829 | $_[0] == MERGE_ADJACENT | 
| 334 |  |  |  |  |  |  | || $_[0] == MERGE_ADJACENT_SAME_TAGS | 
| 335 |  |  |  |  |  |  | || $_[0] == MERGE_NONE; | 
| 336 |  |  |  |  |  |  | } | 
| 337 |  |  |  |  |  |  |  | 
| 338 |  |  |  |  |  |  |  | 
| 339 | 126 |  |  | 126 | 1 | 2455 | sub duration { sprintf DURATION_FORMAT, $_[0] / ( 60 * 60 ) } | 
| 340 |  |  |  |  |  |  |  | 
| 341 |  |  |  |  |  |  | 1; | 
| 342 |  |  |  |  |  |  |  | 
| 343 |  |  |  |  |  |  | __END__ |