1 package jdk.code.tools.renderer;
 2 
 3 
 4 public final class TerminalColors {
 5     private TerminalColors() {
 6     }
 7 
 8     public interface Colorizer {
 9         String colorize(String text);
10     }
11 
12     public enum Color implements Colorizer {
13         // https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#8-colors
14         NONE("0"),
15         BLACK("38;5;0"), DARKGREEN("38;5;22"), DARKBLUE("38;5;27"),
16         GREY("38;5;247"), RED("38;5;1"), GREEN("38;5;77"), YELLOW("38;5;185"),
17         BLUE("38;5;31"), WHITE("38;5;251"), ORANGE("38;5;208"), PURPLE("38;5;133");
18         final String escSequence;
19 
20         Color(String seq) {
21             escSequence = "\u001b[" + seq + "m";
22         }
23 
24         public String colorize(String string) {
25             return (this == NONE) ? string : escSequence + string + NONE.escSequence;
26         }
27     }
28 }