From 0d842a62bc9e6f1b64cafe8d41a98261c82de16c Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 13 Dec 2023 00:42:03 +0100 Subject: [PATCH] better ascii bars --- bin/csv2human | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/bin/csv2human b/bin/csv2human index 3784ffd3..3186aa18 100755 --- a/bin/csv2human +++ b/bin/csv2human @@ -26,7 +26,7 @@ my $VERBOSE = $main::VERBOSE = 1; my $DEBUG = $main::DEBUG = 0; my %Opt = ( - 'header' => 1, + 'header' => 0, 'total' => 1, 'sep' => "\t", ); @@ -41,7 +41,8 @@ $main::_DATA_ = undef; ################################################################################# #use Data::Dumper; print Dumper(\%Opt); use Encode; -binmode( STDOUT, "utf8:" ); +binmode( STDOUT, "raw:" ); +# NB 13.12.23 binmode( STDOUT, "utf8:" ); # @@ -56,7 +57,7 @@ while (<>) { for (my $i=0;$i<@F;$i++) { chomp($F[$i]); - $F[$i] = Encode::decode_utf8($F[$i]); + # NB 13.12.23 $F[$i] = Encode::decode_utf8($F[$i]); my $l; $len[$i] = $l if ( $l = length($F[$i]) ) >= ($len[$i] || 0); } @@ -73,46 +74,46 @@ my $tot = @lines - ($Opt{header} ? 1 : 0); my $t = -1; -my $format = "| ".join(" | ",map {$t+=$_+3; "\%-".$_."s"} @len)." |".chr(10); -my $sep_line = "+".join("+",map {("-"x($_+2))} @len)."+".chr(10); +my $format = "│ ".join(" │ ",map {$t+=$_+3; "\%-".$_."s"} @len)." │".chr(10); +my $sep_line_first = "┌".join("┬",map {("─"x($_+2))} @len)."┐".chr(10); +my $sep_line = "├".join("┼",map {("─"x($_+2))} @len)."┤".chr(10); +my $sep_line_last = "└".join("┴",map {("─"x($_+2))} @len)."┘".chr(10); +# NB 13.12.23 my $format = "| ".join(" | ",map {$t+=$_+3; "\%-".$_."s"} @len)." |".chr(10); +# NB 13.12.23 my $sep_line = "+".join("+",map {("-"x($_+2))} @len)."+".chr(10); +# NB 13.12.23 my $sep_line_first = $sep_line; +# NB 13.12.23 my $sep_line_last = $sep_line; +# +# Format / align +# # a => 1 # b => 222222 if ($Opt{format}) { my $sep = " ".$Opt{sep}." "; my $i; $format = join($sep,map - { - $i++; - $t+=$_+length($sep); - $i == @len ? '%s' : "\%-".$_."s"; - } - @len).chr(10); + { + $i++; + $t+=$_+length($sep); + $i == @len ? '%s' : "\%-".$_."s"; + } @len + ).chr(10); + $sep_line_first = ""; $sep_line = ""; + $sep_line_last = ""; $VERBOSE = 0; $Opt{total} = 0; + $Opt{header} = 0; } # # Print # -print $sep_line; +print $sep_line_first; my $i = 0; my $count; while (my $line = shift @lines) { - # NB 16.04.23: I guess it was supposed ad missing columns - # NB 16.04.23 if ($i == 0) - # NB 16.04.23 { - # NB 16.04.23 $count = @$line; - # NB 16.04.23 } - # NB 16.04.23 else - # NB 16.04.23 { - # NB 16.04.23 for (my $j=@$line; $j<$count; $j++ ) - # NB 16.04.23 { - # NB 16.04.23 $line->[$j] = ''; - # NB 16.04.23 } - # NB 16.04.23 } # Add missing empty columns for (my $j=@$line; $j<@len; $j++ ) { @@ -123,7 +124,7 @@ while (my $line = shift @lines) print $sep_line if $Opt{header} and !$i++; } -print $sep_line; +print $sep_line_last; print "$tot Records\n" if $Opt{total}; ################################################################################# -- 2.47.3