Skip to content
This repository has been archived by the owner on Feb 6, 2019. It is now read-only.
/ php-crayon Public archive

A simple functional PHP library for formatting string output 🌈

License

Notifications You must be signed in to change notification settings

troublete/php-crayon

Repository files navigation

Crayon

A simple functional PHP library for formatting string output 🌈

Build Status Reliability

Preview

preview

Install

$ composer require troublete/crayon

Introduction

The purpose of the library is to simplify the usage of formatting of strings on the PHP CLI. The usage should be strictly a functional one, to write the least code with the biggest impact. Simple use the function Crayon\text which returns a Crayon\Font instance which handles the formatting and return as string. Formatting calls may be chained.

⚠️ Be aware that there is a formatting order: underline > italic > bold > color. Last color set will be used and that italic weighs more than bold formatting. So if both options are set the prior one will be used.

Usage

<?php
require_once 'path/to/vendor/autoload.php';

use function Crayon\{text as crayon, error, success};

echo crayon('text')->green(); // returns green text
echo crayon('text')->green()->bold(); // returns bold green text
echo crayon('text')->green()->underline()->bold(); // returns underlined bold green text
echo crayon('text')->green()->underline()->bold()->background(); // returns underlined bold green backgrounded text

echo success('text'); // returns green bold text with checkmark at the end
echo error('text'); // returns red bold text with x at the end

API

Crayon\Font

->bold() – sets text bold

->italic() – sets text italic

->underline() – sets text underlined

->red() – sets text color to red

->green() – sets text color to green

->yellow() – sets text color to yellow

->blue() – sets text color to blue

->magenta() – sets text color to magenta

->cyan() – sets text color to cyan

->background() – turns coloring from fore to background coloring

License

GPL-2.0 © Willi Eßer