/** * Color on the text terminal can be produced using the "ANSI escape sequences". For example: * * <p>echo -e "\033[44;37;5m ME \033[0m COOL" * * <p>The above sets the background to blue, foreground white, blinking video, and prints " ME ", * then resets the terminal back to defaults and prints " COOL". The "-e" is an option specific to * the echo command--it enables the interpretations of the special characters. The "\033[" * introduces the escape sequence. The "m" means "set attribute" and thus finishes the sequence. * The actual codes in the example above are "44;37;5" and "0". * * <p>Change the "44;37;5" to produce different color combinations--the number/order of codes do * not matter. The codes to choose from are listed below: * * <p>Code Action/Color * * <p>--------------------------- * * <p>0 reset all attributes to their defaults 1 set bold 2 set half-bright (simulated with color * on a color display) 4 set underscore (simulated with color on a color display) 5 set blink 7 * set reverse video 22 set normal intensity 24 underline off 25 blink off 27 reverse video off 30 * set black foreground 31 set red foreground 32 set green foreground 33 set brown foreground 34 * set blue foreground 35 set magenta foreground 36 set cyan foreground 37 set white foreground * * <p>38 set underscore on, set default foreground color 39 set underscore off, set default * foreground color * * <p>40 set black background 41 set red background 42 set green background 43 set brown * background 44 set blue background 45 set magenta background 46 set cyan background 47 set white * background * * <p>49 set default background color * * <p>Other interesting codes: * * <p>\033[2J clear screen \033[0q clear all keyboard LEDs (won't work from Xterm) \033[1q set * "Scroll Lock" LED \033[2q set "Num Lock" LED \033[3q set Caps Lock LED \033[15;40H move the * cursor to line 15, column 40 \007 bell (beep) * * @param color */ public static void setConsoleColor(Colors color) { if (color == Colors.RESET) { printInline("\033[0m"); } else printInline("\033[1;3" + color.ordinal() + "m"); }