ColorUtil { public synchronized static String RgbToAnsi(String rgb, ColorSetting colorSetting) { switch(colorSetting) { case OFF: return ""; case ON: return getClosestTerminalCode(colors.get(rgb), ansiColorsToTerminalCodes); case EXTENDED: return getClosestTerminalCode(colors.get(rgb), eightBitColorsToTerminalCodes); default: throw new UnsupportedOperationException("colorSettung: " + colorSetting); } } private  ColorUtil(); static Map<String, Color> colors(); synchronized static String RgbToAnsi(String rgb, ColorSetting colorSetting); static void main(String[] args); static Color getColorByName(String colorName); static final String ANSI_NORMAL; }
@Test public void testGetColor() { System.setProperty("java.awt.headless", "true"); assertEquals("", ColorUtil.RgbToAnsi("red", ColorSetting.OFF)); assertEquals("\u001b[31m", ColorUtil.RgbToAnsi("red", ColorSetting.ON)); }