antibiotics11/ansi-styler

Utility for applying ANSI colors and text styles to console output.

v1.0 2024-04-15 07:45 UTC

This package is auto-updated.

Last update: 2024-09-15 08:46:09 UTC


README

A PHP utility for applying ANSI colors and text styles to console output.

use antibiotics11\AnsiStyler\{AnsiColorCode, AnsiFormatter};

// create a new AnsiFormatter instance
$styler = new AnsiFormatter();

// apply yellow background color, red foreground color and bold style
$formattedText = $styler->withBackgroundColor(AnsiColorCode::BACKGROUND_YELLOW)
                        ->withForegroundColor(AnsiColorCode::FOREGROUND_RED)
                        ->withBold()
                        ->format("Hello, World!");

printf("%s\r\n", $formattedText);

// reinitialize the AnsiFormatter
$styler->initialize();

screenshot

Requirements

  • PHP >= 8.1

Installation

composer require antibiotics11/ansi-styler