Giter VIP home page Giter VIP logo

php-cli's People

Contributors

jblond avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

5l1v3r1

php-cli's Issues

CliColors is missing formats.

Please support all formats as described at https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting

One of my quick 'n dirty written codes:

/**
 * Echo an ANSI formatted value.
 *
 * The argument must be an array with an even amount of elements.
 * The odd element values define the format, the following element contains the value to echo.
 *
 * @see https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
 *
 * @param mixed ...$arguments Format and values to echo.
 */
function echoFormatted(...$arguments)
{
    // Extract colors.
    $formats = $texts = [];
    foreach ($arguments as $key => $value) {
        $value = @(string)$value;
        if ($key % 2) {
            $texts[] = $value;
        } else {
            $formats[] = $value;
        }
    }

    if (count($formats) != count($texts)) {
        throw new InvalidArgumentException('Given formats and texts are out of balance!');
    }

    // Echo colorized texts.
    $availableFormats = [
        'default'      => 0,
        'bold'         => 1,
        'underlineYes' => 4,
        'underlineNo'  => 24,
        'negative'     => 7,
        'positive'     => 27,

        'fBlack'    => 30,
        'fRed'      => 31,
        'fGreen'    => 32,
        'fYellow'   => 33,
        'fBlue'     => 34,
        'fMagenta'  => 35,
        'fCyan'     => 36,
        'fWhite'    => 37,
        'fExtended' => 38,
        'fDefault'  => 39,

        'bBlack'    => 40,
        'bRed'      => 41,
        'bGreen'    => 42,
        'bYellow'   => 43,
        'bBlue'     => 44,
        'bMagenta'  => 45,
        'bCyan'     => 46,
        'bWhite'    => 47,
        'bExtended' => 48,
        'bDefault'  => 49,

        'fbBlack'   => 90,
        'fbRed'     => 91,
        'fbGreen'   => 92,
        'fbYellow'  => 93,
        'fbBlue'    => 94,
        'fbMagenta' => 95,
        'fbCyan'    => 96,
        'fbWhite'   => 97,

        'bbBlack'   => 100,
        'bbRed'     => 101,
        'bbGreen'   => 102,
        'bbYellow'  => 103,
        'bbBlue'    => 104,
        'bbMagenta' => 105,
        'bbCyan'    => 106,
        'bbWhite'   => 107,
    ];

    for ($i = 0; $i < count($formats); $i++) {
        echo "\033[{$availableFormats[$formats[$i]]}m", $texts[$i], "\033[0m";
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.