From d2667c644d7e936b39f59c9ed229c24c33e24e18 Mon Sep 17 00:00:00 2001
From: Vojtech Moravec <vojtech.moravec.st@vsb.cz>
Date: Fri, 25 Sep 2020 09:10:40 +0200
Subject: [PATCH] Colored console output utility.

---
 .../azgracompress/utilities/ColorConsole.java | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 src/main/java/azgracompress/utilities/ColorConsole.java

diff --git a/src/main/java/azgracompress/utilities/ColorConsole.java b/src/main/java/azgracompress/utilities/ColorConsole.java
new file mode 100644
index 0000000..18857e3
--- /dev/null
+++ b/src/main/java/azgracompress/utilities/ColorConsole.java
@@ -0,0 +1,50 @@
+package azgracompress.utilities;
+
+public final class ColorConsole {
+    private static final String ANSI_RESET = "\u001B[0m";
+    private static final String ANSI_BLACK = "\u001B[30m";
+    private static final String ANSI_RED = "\u001B[31m";
+    private static final String ANSI_GREEN = "\u001B[32m";
+    private static final String ANSI_YELLOW = "\u001B[33m";
+    private static final String ANSI_BLUE = "\u001B[34m";
+    private static final String ANSI_PURPLE = "\u001B[35m";
+    private static final String ANSI_CYAN = "\u001B[36m";
+    private static final String ANSI_WHITE = "\u001B[37m";
+
+    public enum Color {Black, Red, Green, Yellow, Blue, Purple, Cyan, White}
+
+    public enum Target {stdout, stderr}
+
+    private static String getColor(final Color color) {
+        switch (color) {
+            case Black:
+                return ANSI_BLACK;
+            case Red:
+                return ANSI_RED;
+            case Green:
+                return ANSI_GREEN;
+            case Yellow:
+                return ANSI_YELLOW;
+            case Blue:
+                return ANSI_BLUE;
+            case Purple:
+                return ANSI_PURPLE;
+            case Cyan:
+                return ANSI_CYAN;
+            default:
+                return ANSI_WHITE;
+        }
+    }
+
+    public static void fprintf(final Target target, final Color color, final String format, final Object... args) {
+
+        switch (target) {
+            case stdout:
+                System.out.println(getColor(color) + String.format(format, args) + ANSI_RESET);
+                break;
+            case stderr:
+                System.err.println(getColor(color) + String.format(format, args) + ANSI_RESET);
+                break;
+        }
+    }
+}
-- 
GitLab