$npx -y skills add AdamBien/airails --skill zclAdd colored terminal output to Java applications using zcl (Zero-dependency Colour Logger). Use when adding colored console output, terminal logging with colors, ANSI color support, or integrating zcl into a Java project. Triggers on "zcl", "colored output", "colored logging", "t
| 1 | Add colored terminal output to a Java application using $ARGUMENTS. Apply all rules below. |
| 2 | |
| 3 | ## What is zcl |
| 4 | |
| 5 | zcl is a zero-dependency, single-enum Java logging utility using ANSI 24-bit true-colour escape sequences from the [Solarized Dark](https://github.com/altercation/solarized) accent palette. zcl is designed as a source-reuse project — the `Log.java` file is copied directly into your source tree, not consumed as a Maven/Gradle dependency or JAR. This keeps the project free of external dependencies. |
| 6 | |
| 7 | - Source: https://github.com/AdamBien/zcl |
| 8 | - Requires: Java 21+ |
| 9 | - API: Static methods only — all interaction is via `Log.info(...)`, `Log.error(...)`, etc. |
| 10 | |
| 11 | ## Integration |
| 12 | |
| 13 | Copy the `Log.java` enum below into the application's source tree. Adjust the package declaration to match the target package. |
| 14 | |
| 15 | ```java |
| 16 | import java.io.PrintStream; |
| 17 | |
| 18 | public enum Log { |
| 19 | |
| 20 | ERROR(Color.RED, System.err), |
| 21 | USER(Color.CYAN, System.out), |
| 22 | INFO(Color.GREEN, System.out), |
| 23 | SYSTEM(Color.BLUE, System.out), |
| 24 | WARNING(Color.YELLOW, System.out), |
| 25 | DEBUG(Color.VIOLET, System.out), |
| 26 | SUCCESS(Color.MAGENTA, System.out); |
| 27 | |
| 28 | private PrintStream out; |
| 29 | |
| 30 | enum Color { |
| 31 | YELLOW("\033[38;2;181;137;0m"), // Solarized Yellow #b58900 |
| 32 | ORANGE("\033[38;2;203;75;22m"), // Solarized Orange #cb4b16 |
| 33 | RED("\033[38;2;220;50;47m"), // Solarized Red #dc322f |
| 34 | MAGENTA("\033[38;2;211;54;130m"), // Solarized Magenta #d33682 |
| 35 | VIOLET("\033[38;2;108;113;196m"), // Solarized Violet #6c71c4 |
| 36 | BLUE("\033[38;2;38;139;210m"), // Solarized Blue #268bd2 |
| 37 | CYAN("\033[38;2;42;161;152m"), // Solarized Cyan #2aa198 |
| 38 | GREEN("\033[38;2;133;153;0m"); |
| 39 | |
| 40 | String code; |
| 41 | |
| 42 | Color(String code) { |
| 43 | this.code = code; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | private final String value; |
| 48 | private final static String RESET = "\u001B[0m"; |
| 49 | |
| 50 | private Log(Color color, PrintStream out) { |
| 51 | this.value = (color.code + "%s" + RESET); |
| 52 | this.out = out; |
| 53 | } |
| 54 | |
| 55 | String formatted(String raw) { |
| 56 | return this.value.formatted(raw); |
| 57 | } |
| 58 | |
| 59 | void out(String message) { |
| 60 | var colored = formatted(message); |
| 61 | this.out.println(colored); |
| 62 | } |
| 63 | |
| 64 | public static void debug(String message) { |
| 65 | Log.DEBUG.out(message); |
| 66 | } |
| 67 | |
| 68 | public static void error(String message) { |
| 69 | Log.ERROR.out(message); |
| 70 | } |
| 71 | |
| 72 | public static void error(String message, Exception e) { |
| 73 | Log.ERROR.out(message + ": " + e.getMessage()); |
| 74 | e.printStackTrace(System.err); |
| 75 | } |
| 76 | |
| 77 | public static void user(String message){ |
| 78 | Log.USER.out(message); |
| 79 | } |
| 80 | |
| 81 | public static void info(String message){ |
| 82 | Log.INFO.out(message); |
| 83 | } |
| 84 | |
| 85 | public static void system(String message){ |
| 86 | Log.SYSTEM.out(message); |
| 87 | } |
| 88 | |
| 89 | public static void clearScreen(){ |
| 90 | IO.println("\033c"); |
| 91 | } |
| 92 | |
| 93 | public static void warning(String message){ |
| 94 | Log.WARNING.out(message); |
| 95 | } |
| 96 | |
| 97 | public static void success(String message){ |
| 98 | Log.SUCCESS.out(message); |
| 99 | } |
| 100 | |
| 101 | public static void stop(String message){ |
| 102 | error(message); |
| 103 | System.exit(0); |
| 104 | } |
| 105 | } |
| 106 | ``` |
| 107 | |
| 108 | ## Log Levels |
| 109 | |
| 110 | | Level | Solarized Color | Stream | Static Method | Purpose | |
| 111 | |-------|----------------|--------|---------------|---------| |
| 112 | | `ERROR` | Red | `System.err` | `Log.error(msg)` | Critical failures | |
| 113 | | `USER` | Cyan | `System.out` | `Log.user(msg)` | User messages and interactive elements | |
| 114 | | `INFO` | Green | `System.out` | `Log.info(msg)` | General information | |
| 115 | | `SYSTEM` | Blue | `System.out` | `Log.system(msg)` | System-level messages | |
| 116 | | `WARNING` | Yellow | `System.out` | `Log.warning(msg)` | Warning conditions | |
| 117 | | `DEBUG` | Violet | `System.out` | `Log.debug(msg)` | Debug information for developers | |
| 118 | | `SUCCESS` | Magenta | `System.out` | `Log.success(msg)` | Success messages and completions | |
| 119 | |
| 120 | ## Usage |
| 121 | |
| 122 | All interaction uses the public static convenience methods. The instance methods `out()` and `formatted()` are package-private. |
| 123 | |
| 124 | ```java |
| 125 | Log.error("Database connection failed"); |
| 126 | Log.error("Connection failed", exception); // logs message + full stack trace to stderr |
| 127 | Log.user("Welcome to the application"); |
| 128 | Log.info("Operation completed"); |
| 129 | Log.system("Server started on port 8080"); |
| 130 | Log.warning("Cache miss detected"); |
| 131 | Log.debug("Processing item #42"); |
| 132 | Log.success("Build completed successfully"); |
| 133 | Log.clearScreen(); // sends ESC c to reset the terminal |
| 134 | Log.stop("Fatal error — shutting down"); // logs error and calls System.exit(0) |
| 135 | `` |