diff --git a/README.md b/README.md
index ee8b27fde4f74a9a79ca58907f3eba9d4e90b7a6..89ab1b56974b9f2e36385dfcfe569c72c2bb7d54 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,8 @@ You can add different folders one by another to the database, the import will take care the files added and avoid duplicates (currently based on file path). If you think something is messed up you can clean your database and start over.
After you've added some data, you can query different statistics which might be interesting. There are no predefined stats, instead you have the option to adjust the output to your needs using the different params.
+For a complete list of params and example querys use `phosta --help` or have a look at the [wiki](https://man.sr.ht/~rwa/photo-workflow/index.md).
+
### example output
The output will be shown as a bar graph when you select only one output column:
```
diff --git a/phosta.pl b/phosta.pl
index 8dbdf307042190f01d889929e16ebe4d38e596b2..1e4d1738e8a2e71e7b10ed8010842db713213583 100755
--- a/phosta.pl
+++ b/phosta.pl
@@ -37,10 +37,11 @@ our $opt_o='count';
our $opt_r=0;
our $opt_f=undef;
our $opt_e=0;
+our $opt_W=80;
getconfig();
-getopts('vcrp:n:g:s:t:D:E:o:f:e') or die "Invalid parameters provided! See 'phosta --help' for more details.";
+getopts('vcrp:n:g:s:t:D:E:o:f:eW:') 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";
@@ -80,7 +81,8 @@ {
$_ ~~ @order_params or return 0;
}
}
- !defined($opt_n) || !looks_like_number($opt_n) || $opt_n > 0 or return 0;
+ (!defined($opt_n) || (looks_like_number($opt_n) && $opt_n > 0)) or return 0;
+ (looks_like_number($opt_W) && $opt_W >= 50) or return 0;
!defined($opt_t) || $opt_t =~ /^([0-9]{8}){0,1}\-([0-9]{8}){0,1}$/ or return 0;
@@ -100,6 +102,7 @@ {
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;
}
@@ -380,9 +383,13 @@ sub result_to_graph
{
my ( $headers, $rows, $sum ) = @_;
+ 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)';
+
foreach (@$rows)
{
- say sprintf("%20s | %-50s | %5s (%s)", @$_[0], "*"x(50/$sum*@$_[1]), @$_[2], @$_[1]);
+ say sprintf($chartformat, @$_[0], "*"x(50/$sum*@$_[1]), @$_[2], @$_[1]);
}
}
@@ -390,7 +397,7 @@ sub result_to_table
{
my ( $headers, $rows, $sum, $skippedlines ) = @_;
- my $tb = Text::SimpleTable::AutoWidth->new();
+ my $tb = Text::SimpleTable::AutoWidth->new('max_width' => $opt_W);
$tb->captions($headers);
foreach (@$rows)
@@ -446,6 +453,8 @@ say ' -o <fields> : sort your output by the given fields (sequence matters!) in descending order';
say ' allowed values: any comma separated combination of the values of -t and -s param and \'count\'';
say ' -r : sort in reverse (ascending) order, default is descending order';
say ' -e : skip lines with empty selected or grouping fields';
+ say ' -W <number> : define max char width of output, default: 80, a minimum of 50 is required for meaningful output';
+ say ' This option is automatically saved to the user config.';
say '';
say 'examples:';
say ' phosta -E jpg,jpeg,tiff -D ~/Documents/stats.db -p ~/Pictures';