文本属性:
| 值 | 属性 |
|---|---|
| 0 | 重置所有属性 |
| 1 | 加粗 |
| 3 | 斜体 |
| 4 | 下划线 |
| 5 | 文字闪烁 |
| 7 | 反色 |
| 9 | 删除线 |
颜色如下枚举类所示:
enum Color {
BLACK(30),
RED(31),
GREEN(32),
YELLOW(33),
BLUE(34),
PINKISH_RED(35),
CYAN(36),
WHITE(37);
public int code;
Color(int code) {
this.code = code;
}
}
public class ConsoleColorfulUtils {
public static String output(Color color, String str) {
return "\033[" + color.code + ";2m" + str + "\033[0m";
}
public static String outputRed(String str) {
return output(Color.RED, str);
}
public static String outputGreen(String str) {
return output(Color.GREEN, str);
}
public static String outputBlue(String str) {
return output(Color.BLUE, str);
}
private ConsoleColorfulUtils() {
}
}