An easy way to add colors in your CLI scripts.

Related tags

Laravel colors.php
Overview

COLORS

Build Status Coverage Status Scrutinizer Code Quality Latest Stable Version Total Downloads

Here is a preview of what you can achieve with the library:

Example

256 colors

Installation

Installation via composer is highly recommended.

{
    "require": {
        "kevinlebrun/colors.php": "1.0.*"
    }
}

Install composer.

$ php composer.phar install

Usage

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Colors\Color;

$c = new Color();

// highlight('green') === bg('green') === bg_green()
// white() === fg('white')
echo $c('Hello World!')->white()->bold()->highlight('green') . PHP_EOL;

// using some magic
echo $c('Hello World!')->white->bold->bg_green . PHP_EOL;

// create your own theme
$c->setTheme(
    array(
        'welcome' => array('white', 'bg_green'),
        'bye' => 'blue',
    )
);

echo $c('Hello World!')->welcome->bold . PHP_EOL;
echo $c('Bye!')->bye . PHP_EOL;

// use style tags
$text = <<<EOF
1 : <welcome>Hello <bold>World!</bold></welcome>
2 : <bye>Bye!</bye>
EOF;

echo $c($text)->colorize() . PHP_EOL;

// center text
$text = 'hello' . PHP_EOL . '✩' . PHP_EOL . 'world';
echo $c($text)->center() . PHP_EOL;

// use standard API
$message = $c->apply('bold', $c->white('Hello World!'));
echo $message . PHP_EOL;
echo $c->clean($message) . PHP_EOL;

Contributing

Install composer.

$ php composer.phar install --dev

All tests must pass:

$ bin/phpunit

Code style conventions must be followed:

$ bin/phpcs --standard=phpcs.xml -p .

Contributors

License

(The MIT License)

Copyright (c) 2018 Kevin Le Brun [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • isSupported() returns false even if coloring actually works

    isSupported() returns false even if coloring actually works

    I tried to use this module on windows and found that if I override the isSupported() method to return true, the coloring works just fine, but otherwise the library thinks that coloring is not supported and so does not color the output.

    opened by PunchyRascal 3
  • Add more colors.

    Add more colors.

    New you can use all xterm-256 colors. Add following colors : light_gray, dark_gray, light_red, light_green, light_yellow, light_blue, light_magenta and light_cyan

    Add 2 color converter gray and rgb.

    gray => 24 level of gray. you can use gray[0-255] of gray[0-100%] rgb => 216 colors. you can use rgb[0-255|0-100%,0-255|0-100%,0-255|0-100%]

    ex :

    <?php
    $c = new Colors\Color();
    echo $c('gray')->fg('gray[75%]');
    echo $c('color')->fg('rgb[200,10,30%]');
    
    opened by menthol 3
  • Forcetty option for use when colours are desired but php's STDOUT is not a tty

    Forcetty option for use when colours are desired but php's STDOUT is not a tty

    Love the project. Thanks a lot for it.

    There are certain situations where forcing colors.php to output colors is desirable regardless of whether php is reporting that STDIN is a tty. In my particular situation grunt (node) is executing a php script using colors.php and I am unable to pass the tty to php regardless of what I do in node. Perhaps others will also experience a similar problem, and having the option will be as useful as it is to me.

    opened by camspiers 3
  • Adds center support

    Adds center support

    Add support for a center method.

    • Includes a test coverage
    • Supports UTF-8 / multibyte strings
    • Supports multiline strings
    <?php
    echo $c('')->center(80)->bg('blue') . PHP_EOL;
    echo $c('Hello World!')->center(80)->white()->bold()->bg('blue') . PHP_EOL;
    echo $c('This is centered text!')->center(80)->white()->bg('blue') . PHP_EOL;
    echo $c('')->center(80)->bg('blue') . PHP_EOL;
    

    screen shot

    Did not add anything to the example file or documentation.

    opened by nategood 3
  • Version 0.4

    Version 0.4

    Can you please release version 0.4 so we can use the new colors. I'm more comfortable with using a stable version instead of an unstable dev-master in Composer.

    Thanks!

    opened by TheFox 2
  • Minor commenting change

    Minor commenting change

    I went through the code and updated link references to use the docblock coding convention. Mainly just two links. I was wondering if the docblock coding convention way of doing things was something being considered for this project?

    opened by tvandame 2
  • Test enhancement

    Test enhancement

    Changed log

    • Add the php-7.2 and php-7.3 tests in Travis CI build.
    • Set the PHPUnit be 4.8 version to support the latest stable PHPUnit versions in the future.
    • Using the class-based PHPUnit namespace to be compatible with latest stable PHPUnit version.
    • Remove the require_once 'PHPUnit/Framework/Assert/Functions.php'; file because this is not necessary and using the $this class instance for every assertion methods defined in PHPUnit\Framework\TestCase` class.
    • The satooshi/php-coveralls is deprecated. Using the php-coveralls/php-coveralls instead.
    opened by peter279k 1
  • Using a color as a style name leads to recursion.

    Using a color as a style name leads to recursion.

    $c->setTheme(
        array(
           'green' => ['green'],
        )
    );
    

    leads to recursion between:

    Colors\Color->stylize() /src/Colors/Color.php:210
    Colors\Color->applyUserStyle() /src/Colors/Color.php:152
    
    opened by gwagroves 1
  • Adding simple singleton support

    Adding simple singleton support

    This way it's possible to use colorize() more efficiently everywhere, without having to re-instance the class. Example: echo Color::instance()->colorize('<bold>ERROR:</bold> You made a mistake');

    opened by igorsantos07 1
  • Call to undefined method

    Call to undefined method

    echo $c('Hello World!')->white()->bold()->highlight('green') . PHP_EOL;

    if I use this in object and it will be like this: public $c = new \Colors\Color(); $this->c('Hello,World!); And this will give a message : Call to undefind method xxx\xxx::c();

    opened by btainleeR 0
  • Added setString method

    Added setString method

    setString method can be used to set the content, $c('Hello World!') cannot be used in some situations.

    $c = new Color();
    echo $c->setString('Hello World!')->white;
    
    opened by GoneTone 0
  • Drop php-5.x supports

    Drop php-5.x supports

    As title, I think it's time to drop the php-5.x version supports.

    The php-5.x versions are too old to maintain and they're not maintained by official team anymore.

    opened by peter279k 2
Owner
Kevin Le Brun
Kevin Le Brun
Laravel Breadcrumbs - An easy way to add breadcrumbs to your @Laravel app.

Introduction Breadcrumbs display a list of links indicating the position of the current page in the whole site hierarchy. For example, breadcrumbs lik

Alexandr Chernyaev 269 Dec 21, 2022
A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly.

PHPColors A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly. Requirements PHPColo

Arlo Carreon 423 Dec 20, 2022
Laravel-tagmanager - An easier way to add Google Tag Manager to your Laravel application.

Laravel TagManager An easier way to add Google Tag Manager to your Laravel application. Including recommended GTM events support. Requirements Laravel

Label84 16 Nov 23, 2022
A simple way to add 301/302 redirects within CraftCMS.

Redirector plugin for Craft CMS 3.x A simple way to add 301/302 redirects within CraftCMS. This is the first CraftCMS plugin written by myself so plea

Jae Toole 1 Nov 25, 2021
Entrust is a succinct and flexible way to add Role-based Permissions to Laravel 5.

ENTRUST (Laravel 5 Package) Entrust is a succinct and flexible way to add Role-based Permissions to Laravel 5. If you are looking for the Laravel 4 ve

Zizaco 6.1k Dec 31, 2022
Laravel Homestead Build Scripts

Laravel Settler The scripts that build the Laravel Homestead development environment. End result can be found at https://app.vagrantup.com/laravel/box

The Laravel Framework 1k Dec 22, 2022
Collection of scripts, thoughts about CSP (Content Security Policy)

CSP useful, a collection of scripts, thoughts about CSP I'm testing and using CSP (Content Security Policy), and here are some thoughts, resources, sc

Nicolas Hoffmann 417 Jan 3, 2023
Scripts em PHP para um processo seletivo, onde trabalho com lógica básica para testar minhas competências na linguagem referida.

Processo-Seletivo-PHP-Junior Scripts em PHP para um processo seletivo, onde trabalho com lógica básica para testar minhas competências na linguagem re

Gabriel Silva Araujo 2 Dec 10, 2021
Scripts, helpers and configs to make hacking on Synack less painful

SynackMoPleasure Scripts, helpers and configs to make hacking on Synack less painful TuPOC HTTP OOB PHP Logger This PHP script was created to test/exp

Osirys 3 Sep 20, 2022
Laravel Serializable Closure provides an easy way to serialize closures in PHP.

Serializable Closure Introduction This package is a work in progress Laravel Serializable Closure provides an easy way to serialize closures in PHP. I

The Laravel Framework 316 Jan 1, 2023
An easy way to integrate Google Maps with Laravel

An easy way to integrate Google Maps with Laravel For Laravel 5.x, check version 2.35.1 For Laravel 4.x, check version 1.27.0 Think of Googlmapper as

Bradley Cornford 450 Nov 29, 2022
🏭 An easy way to generate populated factories for models.

Laravel Populated Factory provides an easy way to generate populated factories for models according to types & names of their columns. Install You can

Coderello 241 Nov 25, 2022
An easy way to get vendor and package data from Packagist via API calls

Laravel Packagist Laravel Packagist (LaravelPackagist) is a package for Laravel 5 to interact with the packagist api quickly and easily. Table of cont

Jeremy Kenedy 5 Jul 18, 2022
Easy way to upload Laravel model related files from the request.

Easy way to upload laravel model related file from the requset.

Emon Khan 5 Dec 15, 2022
Easy Way to integrate API in you laravel application.

Easy Api Easy Way to integrate API in you laravel application. Installation Guide Install Package using Composer. composer require flutterbuddy1/easy-

Mayank Diwakar 1 Oct 9, 2022
Bunny CLI - Replicate and store your files to the edge!

Bunny CLI - Replicate and store your files to the edge! What is Bunny CLI? Bunny CLI is a tool for the console to upload frontend frameworks such as A

own3d media GmbH 11 Apr 18, 2022
Add tags and taggable behaviour to your Laravel app

Add tags and taggable behaviour to a Laravel app This package offers taggable behaviour for your models. After the package is installed the only thing

Spatie 1.4k Dec 29, 2022
This package lets you add uuid as primary key in your laravel applications

laravel-model-uuid A Laravel package to add uuid to models Table of contents Installation Configuration Model Uuid Publishing files / configurations I

salman zafar 10 May 17, 2022
A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

Munaf Aqeel Mahdi 1.7k Jan 5, 2023