Skip to content

vaneves/console

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Console

PHP Simple Console

Install

composer require vaneves/console

Basic Usage

require_once('../vendor/autoload.php');

use Vaneves\Console\Console;

Console

use Vaneves\Console\Console;

$console = new Console();

$console->title('A highlighted title for the section');

$console->line('A regular line.');

$console->success('Operation executed successfully!');
$console->info('This is just highlighted information.');
$console->warning('This requires your attention!');
$console->error('Oops! Error during execution!');
$console->comment('Just a comment.');
$console->comment('Just a comment without slash.', false);

$console->successWithIcon('Operation executed successfully!');
$console->infoWithIcon('This is just highlighted information.');
$console->warningWithIcon('This requires your attention!');
$console->errorWithIcon('Oops! Error during execution!');

$console->successWithIcon('Operation executed successfully!', '❀');
$console->infoWithIcon('This is just highlighted information.', 'βž₯');
$console->warningWithIcon('This requires your attention!', '➀');
$console->errorWithIcon('Oops! Error during execution!', 'βœ–');

Output:

===================================
A highlighted title for the section
===================================

A regular line.
Operation executed successfully!
This is just highlighted information.
This requires your attention!
Oops! Error during execution!
// Just a comment.
Just a comment without slash.
βœ” Operation executed successfully!
β˜› This is just highlighted information.
⚠ This requires your attention!
✘ Oops! Error during execution!
❀ Operation executed successfully!
βž₯ This is just highlighted information.
➀ This requires your attention!
βœ– Oops! Error during execution!

Progress

use Vaneves\Console\Progress;

$total = 150;

$progress = new Progress($total);
$progress->start();

for ($i = 1; $i <= $total; $i++) {
    $progress->advance();
    usleep(30000);
}
$progress->finish();

Output:

74/150 [β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘] 49%

Table

use Vaneves\Console\Table;

$data = [
    [
        'name' => 'Van Neves',
        'domain' => 'vaneves.com',
        'profession' => 'PHP Developer',
    ],
    [
        'name' => 'Luiz Carvalho',
        'domain' => 'luizcarvalho.com',
        'profession' => 'Ruby Developer',
    ],
    [
        'name' => 'Nyl Marcos',
        'domain' => '',
        'profession' => 'PHP Developer',
    ],
];

$table = new Table($data);
$table->show();

Output:

+---------------+------------------+----------------+
| name          | domain           | profession     |
+---------------+------------------+----------------+
| Van Neves     | vaneves.com      | PHP Developer  |
| Luiz Carvalho | luizcarvalho.com | Ruby Developer |
| Nyl Marcos    |                  | PHP Developer  |
+---------------+------------------+----------------+

Padding

use Vaneves\Console\Padding;

$padding = new Padding(20);
$padding->line('Apples', '$0.99');
$padding->line('Bananas', '$0.39');
$padding->line('Clementines', '$3.99');
$padding->line('Lemons', '$0.69');
$padding->line('Strawberriess', '$1.99');

Output:

Apples.........$0.99
Bananas........$0.39
Clementines....$3.99
Lemons.........$0.69
Strawberriess..$1.99