]> git.nbdom.net Git - nb.git/commitdiff
better ascii bars
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 12 Dec 2023 23:42:03 +0000 (00:42 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 12 Dec 2023 23:42:03 +0000 (00:42 +0100)
bin/csv2human

index 3784ffd31719fc01ab2e3f4dc657caf843a2bf1e..3186aa18415588003c6bf7ace2072aaa3844497e 100755 (executable)
@@ -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};
 
 #################################################################################