Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Console Color Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Direct usage in CLI tools: Wrap output strings in <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</>.
  • Class-based configuration: Reuse a ConsoleColor instance across commands (e.g., inject it into your CLI service classes) to avoid repeated setup overhead and ensure consistent styling.
  • Conditional formatting: Pair with ConsoleColor::hasColorSupport() to conditionally apply colors only when needed (e.g., detect via CI or terminal detection).
  • Template-like formatting: Build reusable color templates as static strings (e.g., '<fg=blue>[INFO]</> %s') and interpolate via sprintf() after colorize().

Gotchas and Tips

  • No nested tag support beyond 1 level: Nested tags like <fg=red><bg=white> work, but deeply nested or unbalanced tags may break—ensure proper pairing of <...> and </>.
  • Windows 10 legacy mode quirks: Even on modern Windows, colors fail if CONOUT$ isn’t properly initialized. Call putenv('ANSICON=1') or ensure virtualTerminalProcessing is enabled.
  • Overzealous tag parsing: The regex-based parser matches any <...> in the string. Escape literal </> characters by doubling them (e.g., <<fg=green>><<fg=green>>>).
  • Memory efficiency: The static getSetup() call caches settings globally—safe for most CLIs, but avoid in long-running workers without resetting state via setColorsEnabled(false) during shutdowns.
  • No themeing or palette extensions: Colors are fixed (red, green, etc.) with no custom hex support—consider forking if you need 256-color or RGB mapping.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4