Skip to content
[DRAFT] Library to work with the console enabled ascii control characters
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
src/Terminal
.gitignore
README.md
composer.json

README.md

Terminal

Library to work with the console enabled ascii control characters

Installation:

{
    "require": {
        "serafim/terminal": "dev-master"
    }
}

Usage example:

Example preview

<?php
use Terminal\Progress;
use Terminal\Char;
use Terminal\Stdout;
use Terminal\Stdin;

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

// Progress style
$progress = (new Progress())

    // Before drawing
    ->before(function($render){
        $render->setAlignment(20);      // Set progress alignment
        $render->setProgressColors([    // Set colors for 0%-90% and 90%-100%
            0 => Char::FONT_L_RED,
            90 => Char::FONT_L_GREEN
        ]);
    })

    // On value change event
    ->onProgress(function($render){
        return $render
            ->drawLine()                // Draw progress line
            ->prefix(chr(219))          // With prefix chr(219)
            ->aggregate(chr(219))       // With chr(219) as highlighter
            ->postfix(
                chr(221) .
                $render->drawValue() .  // With percentage as postfix
                chr(222)
            )
            ->length(30);               // With length 30 chars
    });


// Write title
Stdout::writeln('%s%sExample progress', [Char::STYLE_BOLD, Char::STYLE_UNDERSCORE]);
Stdout::newLine();

// Get progress speed (as example)
$speed = (int)Stdin::read('Progress speed [1]: ', 1);

// Set new progress title
$progress->setTitle('Some progress: ');
for ($i=0; $i<=100; $i++) {
    $progress->setValue($i);            // Update progress value
    usleep($speed * 1000);
}
Stdout::newLine();


// Update progress title
$progress->setTitle('Another progress: ');
for ($i=0; $i<=100; $i++) {
    $progress->setValue($i);            // Update value
    usleep($speed * 1000);
}
Stdout::newLine();

// Write line
Stdout::writeln('Success!', Char::FONT_L_GREEN);
You can’t perform that action at this time.