mirror of https://github.com/digint/btrbk
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
parent
485bc3ab0c
commit
4629d5ae11
35
btrbk
35
btrbk
|
@ -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($ralign->{$_}) {
|
if($pretty) {
|
||||||
print $fh ' ' x $fill;
|
# use aligned lower case headings (with separator line below)
|
||||||
$fill = 0;
|
if($ralign->{$_}) {
|
||||||
|
print $fh ' ' x $fill;
|
||||||
|
$fill = 0;
|
||||||
|
}
|
||||||
|
print $fh $_;
|
||||||
|
} else {
|
||||||
|
print $fh uc($_); # default unaligned upper case headings
|
||||||
}
|
}
|
||||||
print $fh $_;
|
|
||||||
$fill += $table_spacing;
|
$fill += $table_spacing;
|
||||||
}
|
}
|
||||||
print $fh "\n";
|
print $fh "\n";
|
||||||
|
|
||||||
$fill = 0;
|
$fill = 0;
|
||||||
foreach (@keys) {
|
if($pretty) { # separator line after header
|
||||||
next unless($print_row{$_});
|
foreach (@keys) {
|
||||||
print $fh ' ' x $fill;
|
next unless($print_row{$_});
|
||||||
print $fh '-' x $maxlen{$_};
|
print $fh ' ' x $fill;
|
||||||
$fill = $table_spacing;
|
print $fh '-' x $maxlen{$_};
|
||||||
|
$fill = $table_spacing;
|
||||||
|
}
|
||||||
|
print $fh "\n";
|
||||||
|
# alternative (all above in one line ;)
|
||||||
|
#print $fh join(' ' x $table_spacing, map { '-' x ($maxlen{$_}) } @keys) . "\n";
|
||||||
}
|
}
|
||||||
# alternatively (all above in one line ;)
|
|
||||||
#print $fh join(' ' x $table_spacing, map { '-' x ($maxlen{$_}) } @keys) . "\n";
|
|
||||||
print $fh "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# print values
|
# print values
|
||||||
|
|
Loading…
Reference in New Issue