vaneves / console
Console Tools
v1.0.0
2022-03-25 00:43 UTC
Requires
- php: >=7.4
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-12-25 20:08:37 UTC
README
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