jfcherng/php-color-output
Lightweight PHP utility to add ANSI colors and styles to CLI output. Provides named foreground/background styles, special effects (bold, underline, blink, reverse), aliases, and a simple CliColor::color() helper to format strings for terminals.
Install the package via Composer with composer require jfcherng/php-color-output. Begin by using the core CliColor class: inject or import \Jfcherng\Utility\CliColor, then call CliColor::color($string, $colors) to apply ANSI formatting. Start simple — wrap a single string like CliColor::color('Hello', 'f_red') to see colored output in your CLI. For multi-style strings, pass comma-separated strings ('f_white,b_blue') or arrays (['f_white', 'b_blue']). Always test in your target shell environment — especially Windows (ensure ANSI support via color in cmd.exe or use winpty, or consider enabling --ansi in phpunit runs).
CliColor::color() calls inside Symfony\Component\Console\Command\Command subclasses — e.g., for success/error messages: echo CliColor::color('✓ Success!', 'f_green, b'), while maintaining consistency with style tokens.Logger::info(CliColor::color($msg, 'f_cyan')) or add a custom monolog handler that processes records.color() in loops for dynamic status: echo CliColor::color("Processing {$i}/{$total}...", 'f_yellow'), "\r";.self::SUCCESS = 'f_green,b';) to centralize styling.CliColor::noColor() before writing to files or remote logs: file_put_contents('debug.log', CliColor::noColor($coloredOutput)).color() or noColor() — they were removed in v3.0.0. Always use \Jfcherng\Utility\CliColor::color(...).--ansi flag when invoking PHP or consider bentools/terminfo or squizlabs/php_codesniffer’s phpcbf’s color handling patterns as fallback.$reset = false, remember to append 'reset' manually: CliColor::color('Start', 'f_blue', false) . CliColor::color('End', 'reset').'b', 'blk', 'u', 'h', 'rev', 'rst' instead of full names — they’re shorter and widely adopted (e.g., 'b' for bold).color() only formats the string — add PHP_EOL or \n yourself where needed; avoid "foo\n" without \r on Windows if cross-platform compatibility is required.Terminal service class for consistent, app-wide formatting.noColor() outputs — ensure downstream processing (e.g., file I/O, APIs) doesn’t break on unescaped ANSI codes.How can I help you explore Laravel packages today?