diff --git a/phosta b/phosta
index 046787b1416e26e0571b5aa6d916f2fb634b6f2f..c9e30d6768115204f26ee8d46f45691813a37604 100755
--- a/phosta
+++ b/phosta
@@ -38,10 +38,11 @@ our $opt_r=0;
our $opt_f=undef;
our $opt_e=0;
our $opt_W=80;
+our $opt_T='auto';
getconfig();
-getopts('vcrp:n:g:s:t:D:E:o:f:eW:') or die "Invalid parameters provided! See 'phosta --help' for more details.";
+getopts('vcrp:n:g:s:t:D:E:o:f:eW:T:') or die "Invalid parameters provided! See 'phosta --help' for more details.";
validate() or die "Invalid parameters provided! See 'phosta --help' for more details.";
my $dsn = "DBI:SQLite:dbname=$opt_D";
@@ -64,7 +65,7 @@ {
my @group_params = ('year', 'month', 'week', 'hour');
!defined($opt_g) || grep /$opt_g/, @group_params or return 0;
- my @select_params = ('file', 'maker', 'model', 'lensmake', 'lens', 'aperture', 'exposuretime', 'iso', 'focallength', 'focallength35mm', '');
+ my @select_params = qw(file maker model lensmake lens aperture exposuretime iso focallength focallength35mm);
if (defined($opt_s))
{
foreach (split (/,/, $opt_s))
@@ -89,6 +90,9 @@
$opt_E =~ /^([a-z]{2,4}){1,}(\,[a-z]{2,4}){0,}$/ or return 0;
!defined($opt_f) || $opt_f =~ /^(,{0,1}[\w\-]{2,}(!){0,1}=[\w\-\s]{1,}){1,}$/ or return 0;
+
+ my @table_params = qw(on off auto);
+ $opt_T ~~ @table_params or return 0;
return 1;
}
@@ -103,7 +107,8 @@ open(my $filehandle, '>', $configfile) or die "Could not open file '$configfile': $!";
say $filehandle '$opt_D="'. $opt_D .'";';
say $filehandle '$opt_E="'. $opt_E .'";';
say $filehandle '$opt_W="'. $opt_W .'";';
- close $filehandle;
+ say $filehandle '$opt_T="'. $opt_T .'";';
+ close $filehandle;
}
sub getaliases
@@ -317,8 +322,14 @@
my ($limited_rows, $skippedlines) = limit_results($rows);
print_filterinfo(scalar @$limited_rows, $skippedlines, $sum);
- if (@$headers == 3) { result_to_graph($headers, $limited_rows, $sum); }
- else { result_to_table($headers, $limited_rows, $sum); }
+ if ($opt_T eq 'off' || (@$headers == 3 and $opt_T eq 'auto') )
+ {
+ result_to_graph($headers, $limited_rows, $sum);
+ }
+ else
+ {
+ result_to_table($headers, $limited_rows, $sum);
+ }
}
sub limit_results
@@ -391,10 +402,27 @@
my $barwidth = POSIX::lround(($opt_W - 17) * 0.7);
my $titlewidth = POSIX::lround(($opt_W - 17) * 0.3);
my $chartformat = '%'.$titlewidth.'.'.$titlewidth.'s |%-'.$barwidth.'s| %5s (%s)';
-
+
+ my $countcolumn = @$headers - 2;
+ my $percentcolumn = @$headers - 1;
+
foreach (@$rows)
{
- say sprintf($chartformat, @$_[0], "*"x(50/$sum*@$_[1]), @$_[2], @$_[1]);
+ # join columns for display before the chart
+ if ( @$headers >= 4)
+ {
+ # TODO: give remaining columns more room if first columns are shorter
+ # TODO: remove trailing whitespace
+ my $titlecolumns = @$headers - 2;
+ my $columnwidth = POSIX::lround($titlewidth / $titlecolumns);
+ my $title = '';
+ for (my $i = 0; $i < $titlecolumns; $i++)
+ {
+ $title = $title . ((length(@$_[$i]) > $columnwidth) ? substr(@$_[$i], 0, $columnwidth-1).'~ ' : @$_[$i] . ' ');
+ }
+ @$_[0] = $title;
+ }
+ say sprintf($chartformat, @$_[0], "*"x(50/$sum*@$_[$countcolumn]), @$_[$percentcolumn], @$_[$countcolumn]);
}
}