php-parallel-lint/php-console-color
Adds easy, cross-platform console text styling for PHP: colors, background colors, and formatting like bold/underline. Lightweight, dependency-free, and commonly used in CLI tools to improve readability of output and error messages.
Install via Composer: composer require php-parallel-lint/php-console-color. It’s designed for minimal overhead—just one class (ConsoleColor) with static methods. Begin by using ConsoleColor::getSetup() to retrieve an instance, then call colorize() with a color code and message (e.g., ConsoleColor::getSetup()->colorize('<fg=green>Success!</>')). Full color support is auto-detected (Windows 10+, Unix, etc.), and the package gracefully falls back to plain text on unsupported terminals. Check the examples/ directory in the repo for quick demos.
<fg=color> or <bg=color> tags—e.g., <fg=red;bg=white>Bold error</>. Use colorize() on arbitrary strings, including nested tags like <fg=cyan>Request <fg=yellow>sent</>.ConsoleColor instance across commands (e.g., inject it into your CLI service classes) to avoid repeated setup overhead and ensure consistent styling.ConsoleColor::hasColorSupport() to conditionally apply colors only when needed (e.g., detect via CI or terminal detection).'<fg=blue>[INFO]</> %s') and interpolate via sprintf() after colorize().<fg=red><bg=white> work, but deeply nested or unbalanced tags may break—ensure proper pairing of <...> and </>.CONOUT$ isn’t properly initialized. Call putenv('ANSICON=1') or ensure virtualTerminalProcessing is enabled.<...> in the string. Escape literal </> characters by doubling them (e.g., <<fg=green>> → <<fg=green>>>).getSetup() call caches settings globally—safe for most CLIs, but avoid in long-running workers without resetting state via setColorsEnabled(false) during shutdowns.How can I help you explore Laravel packages today?