btrbk: change table output format: remove separator line, uppercase column headings

Print table output column headings single-line uppercase instead of
lowercase and underlined.

This is common ascii table format, is easy parseable and offers better
readability e.g. in pager.
pull/299/head
Axel Burri 2019-08-02 22:56:36 +02:00
parent 485bc3ab0c
commit 4629d5ae11
1 changed files with 22 additions and 13 deletions

15
btrbk
View File

@ -4673,6 +4673,7 @@ sub print_formatted(@)
my %args = @_; my %args = @_;
my $title = $args{title}; my $title = $args{title};
my $format = $args{output_format} || $output_format || $default_format; my $format = $args{output_format} || $output_format || $default_format;
my $pretty = $args{pretty};
my $key_defs = $table_formats{$format_key}->{$format}; my $key_defs = $table_formats{$format_key}->{$format};
my $ralign = $table_formats{$format_key}->{RALIGN} // {}; my $ralign = $table_formats{$format_key}->{RALIGN} // {};
my $fh = $args{outfile} // *STDOUT; my $fh = $args{outfile} // *STDOUT;
@ -4703,7 +4704,7 @@ sub print_formatted(@)
{ {
# output: value0 value1, ... # output: value0 value1, ...
unless($args{no_header}) { unless($args{no_header}) {
print $fh join(' ', @keys) . "\n"; print $fh join(' ', map uc($_), @keys) . "\n"; # unaligned upper case headings
} }
foreach my $row (@$data) { foreach my $row (@$data) {
my $line = join(' ', map { ((defined($row->{$_}) && ($_ eq "message")) ? '# ' : '') . ($row->{$_} // "-") } @keys); my $line = join(' ', map { ((defined($row->{$_}) && ($_ eq "message")) ? '# ' : '') . ($row->{$_} // "-") } @keys);
@ -4740,6 +4741,7 @@ sub print_formatted(@)
# print title # print title
if($title) { if($title) {
print $fh "$title\n"; print $fh "$title\n";
print $fh '-' x length($title) . "\n"; # separator line
} }
# print keys (headings) # print keys (headings)
@ -4749,25 +4751,32 @@ sub print_formatted(@)
next unless($print_row{$_}); next unless($print_row{$_});
print $fh ' ' x $fill; print $fh ' ' x $fill;
$fill = $maxlen{$_} - length($_); $fill = $maxlen{$_} - length($_);
if($pretty) {
# use aligned lower case headings (with separator line below)
if($ralign->{$_}) { if($ralign->{$_}) {
print $fh ' ' x $fill; print $fh ' ' x $fill;
$fill = 0; $fill = 0;
} }
print $fh $_; print $fh $_;
} else {
print $fh uc($_); # default unaligned upper case headings
}
$fill += $table_spacing; $fill += $table_spacing;
} }
print $fh "\n"; print $fh "\n";
$fill = 0; $fill = 0;
if($pretty) { # separator line after header
foreach (@keys) { foreach (@keys) {
next unless($print_row{$_}); next unless($print_row{$_});
print $fh ' ' x $fill; print $fh ' ' x $fill;
print $fh '-' x $maxlen{$_}; print $fh '-' x $maxlen{$_};
$fill = $table_spacing; $fill = $table_spacing;
} }
# alternatively (all above in one line ;)
#print $fh join(' ' x $table_spacing, map { '-' x ($maxlen{$_}) } @keys) . "\n";
print $fh "\n"; print $fh "\n";
# alternative (all above in one line ;)
#print $fh join(' ' x $table_spacing, map { '-' x ($maxlen{$_}) } @keys) . "\n";
}
} }
# print values # print values