daijulong / console
A simple, lightweight console for php
Installs: 60
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/daijulong/console
Requires
- php: >=5.4
This package is not auto-updated.
Last update: 2025-10-27 04:29:21 UTC
README
A simple, lightweight console for php
Require
- php: >= 5.4
Install
Via Composer
$  composer require daijulong/console
composer.json
"daijulong/console": "^1.1"
Usage
Output
Create a console instance
$console = \Daijulong\Console\Console::instance();
Print a message at the console
$console->text('I am a message!');
Print a message with a foreground color and a background color
$console->text('I am a message with red foreground color and yellow background color.', 'red', 'yellow');
You can get all supported colors from
Daijulong\Console\Color\Foreground::classandDaijulong\Console\Color\Background::class.
Print a message in a shortcut
$console->success('I am a success message.');
This will print a line of green text. Other similar methods are
error,warning,alertand more.
Input
Ask a question and get the answer
$name = $console->ask('Who are you?');
You can use second parameter as the default value. If there are third parameter equal to
true, the answer can not be empty, even if the default value is set.
Often, you just need to answer yes or no.
$bool = $console->yesOrNo('Are you going to give me your money?');
The console will be kept asking until you answer yes or no. Similarly, if any, the second parameter is the default value.
Other
Coloring string
$console->colored('I am a message with red foreground color and yellow background color.', 'red', 'yellow');
Similar to
text, it does not output directly, which is very useful in displaying a variety of styles in a piece of content.
License
The MIT License (MIT). Please see License File for more information.