]> git.nbdom.net Git - nb.git/commitdiff
export color function
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 20 Apr 2023 21:20:43 +0000 (23:20 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 20 Apr 2023 21:20:43 +0000 (23:20 +0200)
bin/color.pl
lib/perl/NB/Color.pm

index aee49b3d3c99838d9c2ab1c7770152efaf06b4dd..7370bddecbd79c1d7e3ab7c6c2b00dbbcdb015fc 100755 (executable)
@@ -3,7 +3,7 @@ use strict qw(subs vars refs);
 ###############################################################################
 #                             V E R S I O N S 
 ###############################################################################
-my $VERSION = '0.0.2';
+my $VERSION = '0.0.3';
 # english only - NB 07.02.14
 # NB 23.11.01 
 # - creation !
@@ -11,48 +11,6 @@ my $VERSION = '0.0.2';
 #                               G L O B A L E 
 ###############################################################################
 my ($NAME) = $0 =~ m#([^/]+)$#;
-my %BG = (
-       'black'   => 40,
-       'red'     => 41,
-       'green'   => 42,
-       'yellow'  => 43,
-       'blue'    => 44,
-       'magenta' => 45,
-       'cyan'    => 46,
-       'white'   => 47,
-       'default' => 49,
-);
-
-my %FG = (
-       'black'   => 30,
-       'red'     => 31,
-       'green'   => 32,
-       'yellow'  => 33,
-       'blue'    => 34,
-       'magenta' => 35,
-       'cyan'    => 36,
-       'white'   => 37,
-       'default' => 39,
-);
-
-my %EFFECT = (
-       'none'          => 0, 
-       'bold'          => 1, 
-       'pale'          => 2, 
-       'evidence'      => 3, 
-       'underline'     => 4, 
-       'blink'         => 5, 
-       'invert'        => 7, 
-       'cache'         => 8, 
-       'normal'        => 22,
-       'no_evidence'   => 23,
-       'no_souligne'   => 24,
-       'no_underline'  => 24,
-       'no_clignotant' => 25,
-       'no_blink'      => 25,
-       'no_inverse'    => 27,
-       'no_invert'     => 27,
-);
 ###############################################################################
 #                        V A L E U R  P A R  D E F A U T 
 ###############################################################################
@@ -90,6 +48,7 @@ use Getopt::Long qw(:config default no_ignore_case); my %Opt;
 ###############################################################################
 #                    P R O G R A M M E  P R I N C I P A L 
 ###############################################################################
+use NB::Color qw/color %BG %FG %EFFECT/;
 my $input = join('',@ARGV) || 'My Text';
 
 if ($Opt{all}) {
@@ -103,7 +62,7 @@ if ($Opt{all}) {
 
     printf "%21s", "$e ($e_num) | ";
 
-    print in_color($input,{
+    print color($input,{
       effect => $e,
       num => $PRINT_CODE,
     }),"\n";
@@ -115,7 +74,7 @@ if ($Opt{all}) {
 
     printf "%17s", "$fg ($fg_num) | ";
 
-    print in_color($input,{
+    print color($input,{
       fg => $fg,
       bg => $BG,
       effect => $EFFECT,
@@ -129,7 +88,7 @@ if ($Opt{all}) {
 
     printf "%17s", "$bg ($bg_num) | ";
 
-    print in_color($input,{
+    print color($input,{
       fg => $FG,
       bg => $bg,
       effect => $EFFECT,
@@ -140,7 +99,7 @@ if ($Opt{all}) {
   exit 0;
 }
 
-print in_color($input,{
+print color($input,{
   fg => $FG,
   bg => $BG,
   effect => $EFFECT,
@@ -152,48 +111,6 @@ exit 0;
 ###############################################################################
 #                            F O N C T I O N S 
 ###############################################################################
-sub in_color {
-#------------------------------------------------------------------------------
-# NB 18.11.01 
-#------------------------------------------------------------------------------
-my ($txt,$hparam) = @_;
-
-       my $new = "";
-       $hparam->{bg} ||= 'default';
-       $hparam->{fg} ||= 'default';
-       $hparam->{effect} ||= 'normal';
-       #die $hparam->{num};
-
-  if (!$hparam->{num} or $hparam->{num} == 2) {
-
-    $new .= 
-      "\e["
-      . $BG{$hparam->{bg}}
-      . ";".$FG{$hparam->{fg}}
-      . ";".$EFFECT{$hparam->{effect}}
-      . "m".$txt
-      . "\e[0m"
-    ;
-       $new .= " | " if $hparam->{num} == 2;
-
-  }
-
-  if ($hparam->{num}) {
-
-    $new .= 
-      '\e['
-      . $BG{$hparam->{bg}}
-      . ";".$FG{$hparam->{fg}}
-      . ";".$EFFECT{$hparam->{effect}}
-      . "m".$txt
-      . '\e[0m'
-    ;
-
-  }
-
-       return $new;
-}
-
 sub version {
 #------------------------------------------------------------------------------
 # Affiche la version
index 246fa528967be8bc19e27bb9cab481fe9e5ffec0..9dd40d007a64fba3879e918c405d78f801d0b76e 100644 (file)
@@ -8,7 +8,7 @@ our @ISA = qw(Exporter);  # inherit all of Exporter's methods
 our @EXPORT_OK = qw/
        color
 /;
-our @EXPORT = qw//;
+our @EXPORT = qw/%BG %FG %EFFECT/;
 push(@EXPORT, @EXPORT_OK);
 our %EXPORT_TAGS;
 $EXPORT_TAGS{all} = [@EXPORT_OK];