From: Nicolas Boisselier Date: Sat, 29 Apr 2023 08:32:58 +0000 (+0200) Subject: Add colors X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=6e86e21814f8f68d4b083c0e1d8b178d321c6411;p=nb.git Add colors --- diff --git a/bin/color.pl b/bin/color.pl index 7370bdde..9bf502ce 100755 --- a/bin/color.pl +++ b/bin/color.pl @@ -55,12 +55,14 @@ if ($Opt{all}) { $PRINT_CODE = $PRINT_CODE ? 2 : 0; my $length = length($input)+3; + my $fmt; print "\nEffect:\n"; + $fmt = (sort {$b <=> $a} map {length($_)} (keys(%EFFECT)))[0]; for my $e (sort keys %EFFECT) { my $e_num = $EFFECT{$e}; - printf "%21s", "$e ($e_num) | "; + printf "%${fmt}s (%2s) | ", $e, $e_num; print color($input,{ effect => $e, @@ -69,10 +71,11 @@ if ($Opt{all}) { } print "\nForgrounds:\n"; + $fmt = (sort {$b <=> $a} map {length($_)} (keys(%FG)))[0]; for my $fg (sort keys %FG) { my $fg_num = $FG{$fg}; - printf "%17s", "$fg ($fg_num) | "; + printf "%${fmt}s (%2s) | ", $fg, $fg_num; print color($input,{ fg => $fg, @@ -83,10 +86,11 @@ if ($Opt{all}) { } print "\nBackgrounds:\n"; + $fmt = (sort {$b <=> $a} map {length($_)} (keys(%BG)))[0]; for my $bg (sort keys %BG) { my $bg_num = $BG{$bg}; - printf "%17s", "$bg ($bg_num) | "; + printf "%${fmt}s (%3s) | ", $bg, $bg_num; print color($input,{ fg => $FG, diff --git a/lib/perl/NB/Color.pm b/lib/perl/NB/Color.pm index 9dd40d00..6d354af0 100644 --- a/lib/perl/NB/Color.pm +++ b/lib/perl/NB/Color.pm @@ -13,28 +13,44 @@ push(@EXPORT, @EXPORT_OK); our %EXPORT_TAGS; $EXPORT_TAGS{all} = [@EXPORT_OK]; -our %BG = ( - 'black' => 40, - 'red' => 41, - 'green' => 42, - 'yellow' => 43, - 'blue' => 44, - 'magenta' => 45, - 'cyan' => 46, - 'white' => 47, - 'default' => 49, +our %FG = ( + 'black' => 30, + 'red' => 31, + 'green' => 32, + 'yellow' => 33, + 'blue' => 34, + 'magenta' => 35, + 'cyan' => 36, + 'gray' => 90, + 'white' => 97, + 'default' => 39, + 'lightred' => 91, + 'lightgreen' => 92, + 'lightyellow' => 93, + 'lightblue' => 94, + 'lightmagenta' => 95, + 'lightcyan' => 96, + 'lightgray' => 37, ); -our %FG = ( - 'black' => 30, - 'red' => 31, - 'green' => 32, - 'yellow' => 33, - 'blue' => 34, - 'magenta' => 35, - 'cyan' => 36, - 'white' => 37, - 'default' => 39, +our %BG = ( + 'black' => 40, + 'red' => 41, + 'green' => 42, + 'yellow' => 43, + 'blue' => 44, + 'magenta' => 45, + 'cyan' => 46, + 'gray' => 100, + 'white' => 107, + 'default' => 49, + 'lightred' => 101, + 'lightgreen' => 102, + 'lightyellow' => 103, + 'lightblue' => 104, + 'lightmagenta' => 105, + 'lightcyan' => 106, + 'lightgray' => 47, ); our %EFFECT = (