From 42985d5fd1375d137ddcb32b2601fa7b0f98f042 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 2 Dec 2020 10:07:44 +0100 Subject: [PATCH] LXDebug dump_sql_result: Spaltenanordnung je nach Inhalt MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Spalten, die komplett numerisch sind, werden rechtsbündig angeordnet; alle anderen linksbündig. --- SL/LXDebug.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/SL/LXDebug.pm b/SL/LXDebug.pm index 0503dcb6c..a1e19767c 100644 --- a/SL/LXDebug.pm +++ b/SL/LXDebug.pm @@ -19,8 +19,9 @@ use constant FILE_TARGET => 0; use constant STDERR_TARGET => 1; use Data::Dumper; +use List::MoreUtils qw(all); use POSIX qw(strftime getpid); -use Scalar::Util qw(blessed refaddr weaken); +use Scalar::Util qw(blessed refaddr weaken looks_like_number); use Time::HiRes qw(gettimeofday tv_interval); use SL::Request (); use SL::YAML; @@ -231,8 +232,14 @@ sub dump_sql_result { map { $column_lengths{$_} = length $row->{$_} if (length $row->{$_} > $column_lengths{$_}) } keys %{ $row }; } + my %alignment; + foreach my $column (keys %column_lengths) { + my $all_look_like_number = all { (($_->{$column} // '') eq '') || looks_like_number($_->{$column}) } @{ $results }; + $alignment{$column} = $all_look_like_number ? '' : '-'; + } + my @sorted_names = sort keys %column_lengths; - my $format = join '|', map { '%' . $column_lengths{$_} . 's' } @sorted_names; + my $format = join '|', map { '%' . $alignment{$_} . $column_lengths{$_} . 's' } @sorted_names; $prefix .= ' ' if $prefix; -- 2.20.1