$ show onevcat/Rainbow
Rainbow is a zero-runtime-dependency Swift library that applies ANSI escape sequences to strings for colored terminal output. It supports the named 16-color palette plus light variants, 8-bit 256-color mode (38;5;N), 24-bit true color (38;2;R;G;B), hex colors approximated to the nearest 256-color cube, HSL colors converted to RGB, and styles (bold, dim, italic, underline, blink, swap, strikethrough). Output is gated by OutputTarget detection that checks isatty() on POSIX/Windows plus NO_COLOR/FORCE_COLOR environment variables, so redirected output degrades to plain text automatically.
The LLM identified 3 files worth highlighting for reuse:
Self-contained HSL to RGB conversion with hue wrap-around (mod 360 with negative handling), saturation/lightness clamping to 0-100, an achromatic fast path for s=0, and standard sector-based hueToRGB interpolation. Imports Foundation but references zero Rainbow types — it is pure color math that can be dropped into any image-processing, charting, or theming project unchanged.
Parses hex color strings (#RGB/#RRGGBB or bare 3/6-digit, plus UInt32) into RGB tuples and quantizes them to the nearest ANSI 256-color cube using the formula 16 + 36r + 6g + b, with nibble-duplication for 3-digit hex shorthand. Includes validated test pairs mapping known hex values to exact 256-color indices. Isolated logic with no internal Rainbow imports — the quantization routine is directly reusable in any nearest-color matching context.
A character-by-character streaming lexer for ANSI escape sequences (ConsoleEntryParser). It walks a String.Iterator, treats ESC-prefixed '[...m' groups as style codes and everything else as text segments, correctly handles 8-bit and 24-bit color control markers via lookahead, preserves empty segments for style-only strings, and terminates naturally on malformed input (no infinite-loop risk). The parser strategy — interleaving code groups with text segments using a single iterator — is non-obvious lexer design that transfers well to ANSI-stripping tools, terminal emulators, or log formatters.