Java library for displaying colored text in the terminal. Zero dependencies.
| Space | Example |
|---|---|
| RGB | UColor.rgb(255, 100, 50) |
| Hexadecimal | UColor.hex("#FF6432") |
| HSL | UColor.hsl(200, 80, 50) |
| OKLCH | UColor.oklch(0.7, 0.15, 150) |
| CSS (148 colors) | UColor.css("coral") |
import ucolor.UColor;
// Basic colors
UColor.css("coral").println("Hello world!");
UColor.hex("#00BFFF").bold().println("Deep Sky Blue in bold");
UColor.hsl(280, 70, 60).italic().println("Violet in italic");
// Printf
UColor.rgb(0, 200, 100).printf("Progress: %d%%%n", 87);
// Foreground + Background
UColor.css("white").on(UColor.css("darkred")).println(" CRITICAL ERROR ");
// OKLCH Gradient
for (int h = 0; h < 360; h += 10) {
UColor.oklch(0.7, 0.15, h).print("\u2588");
}
System.out.println();
// Conversions
UColor c = UColor.hex("#FF6432");
System.out.println("RGB: " + java.util.Arrays.toString(c.toRgb()));
System.out.println("HSL: " + java.util.Arrays.toString(c.toHsl()));
System.out.println("OKLCH: " + java.util.Arrays.toString(c.toOklch()));
System.out.println("Hex: " + c.toHex());UColor.css("red").bold().println("Bold");
UColor.css("blue").italic().println("Italic");
UColor.css("green").underline().println("Underlined");
UColor.css("yellow").strikethrough().println("Strikethrough");
UColor.css("coral").bold().underline().println("Chainable");| Style | Method |
|---|---|
| Bold | .bold() |
| Dim | .dim() |
| Italic | .italic() |
| Underline | .underline() |
| Blink | .blink() |
| Reverse | .reverse() |
| Strikethrough | .strikethrough() |
UColor.rgb(r, g, b) // RGB [0-255]
UColor.hex("#RRGGBB") // Hex (also #RGB, RRGGBB, RGB)
UColor.hsl(h, s, l) // HSL (h: 0-360, s: 0-100, l: 0-100)
UColor.oklch(L, C, h) // OKLCH (L: 0-1, C: 0-0.4, h: 0-360)
UColor.css("name") // 148 named CSS colorscolor.print("text"); // without newline
color.println("text"); // with newline
color.printf("x=%d", 42); // formatted
color.printTo(System.err, "err"); // to a stream
color.wrap("text"); // String with fg color
color.wrapBg("text"); // String with bg color
color.fg(); // ANSI foreground sequence
color.bg(); // ANSI background sequence
UColor.reset(); // "\033[0m"
UColor.strip(ansiString); // strip ANSI sequencescolor.toRgb(); // int[3]
color.toHex(); // "#RRGGBB"
color.toHsl(); // double[3]
color.toOklch(); // double[3]UColor.isSupported() // color support
UColor.is24BitSupported() // truecolor support
UColor.forceMode(ColorMode.NONE) // disable
UColor.forceMode(ColorMode.TRUE_COLOR) // force 24-bit
UColor.forceMode(ColorMode.AUTO) // auto-detection./gradlew build # compile
./gradlew test # run all 74 tests
./gradlew jar # generate build/libs/ucolor-1.0.0.jar- 74 tests JUnit 5
- Zero dependencies at runtime
- Immutable and thread-safe
- Java 11+
MIT