daijulong/console

A simple, lightweight console for php

1.1.0 2018-08-03 02:53 UTC

This package is not auto-updated.

Last update: 2024-04-14 21:28:07 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::class and Daijulong\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, alert and 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.