ckoumpis/php-prompt

A PHP console utility package providing spinners, progress bars, and error handling for better command-line user experience.

v1.0.0 2024-09-07 14:12 UTC

This package is auto-updated.

Last update: 2024-11-07 17:42:50 UTC


README

A PHP console utility package that provides spinners, progress bars, and color-coded console messages for better command-line user experience.

Installation

To install the PhpPrompt, you need to have Composer installed.

composer require ckoumpis/php-prompt

Usage

Console

The Console class provides several methods to output colored messages.

List of available colors

  • White: For simple logs (white)
  • Success: For success messages (green)
  • Error: For error messages (red)
  • Warning: For warning messages (yellow)
  • Blue: For information messages (blue)
  • Magenta: For important messages (magenta)
  • Cyan: For notifications (cyan)
Console::log("Hello from ckoumpis/php-prompt!");
Console::success("Operation successful!");
Console::error("An error occurred!");
Console::warning("Warning");
Console::blue("This is a blue message");
Console::magenta("This is a magenta message");
Console::cyan("Cyan message for notification");

Progress Bar

The ProgressBar class allows you to visually display the progress of a task. You can use it with 2 ways.

  1. Basic way.
for($i =1; $i <=$total; $i++) {
    ProgressBar::display($i, $total);
    usleep(10000);
}
  1. Using withSteps method
ProgressBar::withSteps(1, 10,1);

Spinner

The Spinner class provides a simple loading animation for console, useful for indicating that an operation is in progress.You can use Spinner bar with 2 ways.

  1. Basic way
for($i = 0; $i < 10; $i++) {
    Spinner::spin();
    sleep(1);
}
  1. Using withSteps method. Or withSteps method
Spinner::withSteps(0, 10, 1);

Contributing

We welcome contributions! If you find a bug or have a feature request, please open an issue or submit a pull request on Github.