sitnikovik / clipher
CLI tool to beatify your scripts with colors, bolds, loading bars and much more
Requires
- php: >=7.1
- ext-readline: *
This package is auto-updated.
Last update: 2024-12-24 08:19:16 UTC
README
Beatifies your cli scripts with colors, bolds, loading bars and much more
Get started
Just create an object of Sitnikovik\Console\Console
and go on:
$console = new \Sitnikovik\Console\Console();
Input
confirm
\Sitnikovik\Console\Console::confirm(string $question, bool $yesOnDefault = false): void
Make user approve or decline some process with the y/n
prompt
\Sitnikovik\Console\Console::prompt(string $question): string
Asks user input the answer needed to continue the program
Output
println
\Sitnikovik\Console\Console::println(string $text): void
Prints the text console output with new line
separate
\Sitnikovik\Console\Console::separate(int $width = 0): void
Prints a separate bar with provided width or stretched if width is 0
quit
\Sitnikovik\Console\Console::quit(string $message = '')
Exit the program with 0
code and prints message text if not empty
panic
\Sitnikovik\Console\Console::panic(string $message = '', int $code = 1)
Exit the program with provided code signalizing the program failed and prints message in red color if not empty
Colors
If you want to switch color styles you have to provide Sitnikovik\Console\Style\StyleInterface
classes for text and background layout to colorize the output.
// set colors $console->setTextStyle(new Sitnikovik\Console\Style\Text\Bold()); $console->setBackgroundStyle(new Sitnikovik\Console\Style\Background()); // or via constructor $console = new Console(new Sitnikovik\Console\Style\Text\Regular(), new Sitnikovik\Console\Style\Background());
Customize style colors
Eitherway, you can create custom classes extended by Sitnikovik\Console\Style\AbstractStyle
or others implemented Sitnikovik\Console\Style\StyleInterface
and modify colors you prefer.
Colorize text
There are at least 8 methods to colorize text implemented by Sitnikovik\Console\Style\AbstractStyle
and Sitnikovik\Console\Style\StyleInterface
. Class calls the interface methods:
- black()
- red()
- green()
- yellow()
- blue()
- purple()
- cyan()
- white()
$text = $console->red('some text'); // colorize text // or $text = $console->bgRed('some text'); // set background to text
They return provided text colorized to called color.
Progress bar
If you need to visualize some process progress you can use Sitnikovik\Console\Progressbar\Progressbar
// Create the bar like that $maxValue = 100; $progressbar = $console::createProgressbar($maxValue); // or $progressbar = Sitnikovik\Console\Progressbar\Progressbar($maxValue); // Advancing for ($current = 0; $current < $maxValue; $current++) { $progressbar->advance(); // increment with 1 point of the max value } // Or advance it manually $progressbar->advance(40); // or another value