File tree Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -898,6 +898,74 @@ sub color {
898
898
}
899
899
}
900
900
901
+ sub git_ansi_color {
902
+ my $str = shift ();
903
+ my @parts = split (' ' , $str );
904
+
905
+ if (!@parts ) {
906
+ return ' ' ;
907
+ }
908
+
909
+ my $colors = {
910
+ ' black' => 0,
911
+ ' red' => 1,
912
+ ' green' => 2,
913
+ ' yellow' => 3,
914
+ ' blue' => 4,
915
+ ' magenta' => 5,
916
+ ' cyan' => 6,
917
+ ' white' => 7,
918
+ };
919
+
920
+ my $fg = $parts [0] || " " ;
921
+ my $mod = $parts [1] || " " ;
922
+ my $bg = $parts [2] || " " ;
923
+
924
+ my @ansi_part = ();
925
+ # ############################################
926
+
927
+ if ($mod eq ' bold' ) {
928
+ push (@ansi_part , " 1" );
929
+ }
930
+
931
+ # ############################################
932
+
933
+ # It's an RGB value
934
+ if (is_numeric($fg )) {
935
+ push (@ansi_part , " 38;5;$fg " );
936
+ # It's a simple 16 color OG ansi
937
+ } elsif ($fg ) {
938
+ push (@ansi_part , $colors -> {$fg } + 30);
939
+ }
940
+
941
+ # ############################################
942
+
943
+ # It's an RGB value
944
+ if (is_numeric($bg )) {
945
+ push (@ansi_part , " 48;5;$bg " );
946
+ # It's a simple 16 color OG ansi
947
+ } elsif ($bg ) {
948
+ push (@ansi_part , $colors -> {$fg } + 40);
949
+ }
950
+
951
+ # ############################################
952
+
953
+ my $ansi_str = join (" ;" , @ansi_part );
954
+ my $ret = " \e [" . $ansi_str . " m" ;
955
+
956
+ return $ret ;
957
+ }
958
+
959
+ sub is_numeric {
960
+ my $s = shift ();
961
+
962
+ if ($s =~ / ^\d +$ / ) {
963
+ return 1;
964
+ }
965
+
966
+ return 0;
967
+ }
968
+
901
969
sub starts_with_ansi {
902
970
my $str = shift ();
903
971
You can’t perform that action at this time.
0 commit comments