@@ -899,14 +899,14 @@ sub color {
899
899
}
900
900
}
901
901
902
+ # https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_colors_in_git
902
903
sub git_ansi_color {
903
904
my $str = shift ();
904
905
my @parts = split (' ' , $str );
905
906
906
907
if (!@parts ) {
907
908
return ' ' ;
908
909
}
909
-
910
910
my $colors = {
911
911
' black' => 0,
912
912
' red' => 1,
@@ -918,46 +918,47 @@ sub git_ansi_color {
918
918
' white' => 7,
919
919
};
920
920
921
- my $fg = $parts [0] || " " ;
922
- my $mod = $parts [1] || " " ;
923
- my $bg = $parts [2] || " " ;
924
-
925
921
my @ansi_part = ();
926
- # ############################################
927
922
928
- if ($mod eq ' bold' ) {
923
+ if (grep { / bold/ } @parts ) {
929
924
push (@ansi_part , " 1" );
925
+ @parts = grep { !/bold/ } @parts ; # Remove from array
930
926
}
931
927
928
+ if (grep { / reverse/ } @parts ) {
929
+ push (@ansi_part , " 7" );
930
+ @parts = grep { !/reverse / } @parts ; # Remove from array
931
+ }
932
+
933
+ my $fg = $parts [0] || " " ;
934
+ my $bg = $parts [1] || " " ;
935
+
932
936
# ############################################
933
937
934
- # It's an RGB value
938
+ # It's an numeric value, so it's an 8 bit color
935
939
if (is_numeric($fg )) {
936
940
push (@ansi_part , " 38;5;$fg " );
937
941
# It's a simple 16 color OG ansi
938
942
} elsif ($fg ) {
939
943
my $bright = $fg =~ s / bright// ;
940
944
my $color_num = $colors -> {$fg } + 30;
941
945
942
- if ($bright ) { $color_num += 8 ; }
946
+ if ($bright ) { $color_num += 60 ; } # Set bold
943
947
944
948
push (@ansi_part , $color_num );
945
949
}
946
950
947
951
# ############################################
948
952
949
- # It's an RGB value
953
+ # It's an numeric value, so it's an 8 bit color
950
954
if (is_numeric($bg )) {
951
955
push (@ansi_part , " 48;5;$bg " );
952
- # Inverse/Reverse
953
- } elsif ($bg =~ / reverse/i ) {
954
- push (@ansi_part , 7);
955
956
# It's a simple 16 color OG ansi
956
957
} elsif ($bg ) {
957
958
my $bright = $bg =~ s / bright// ;
958
- my $color_num = $colors -> {$bg } + 30 ;
959
+ my $color_num = $colors -> {$bg } + 40 ;
959
960
960
- if ($bright ) { $color_num += 8 ; }
961
+ if ($bright ) { $color_num += 60 ; } # Set bold
961
962
962
963
push (@ansi_part , $color_num );
963
964
}
0 commit comments