adachsoft / console-io
Advanced PHP console input/output library with colors, icons and interactive features
Installs: 11
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/adachsoft/console-io
Requires
- php: >=8.3
Requires (Dev)
- phpunit/phpunit: ^11.0
This package is not auto-updated.
Last update: 2025-11-14 17:49:38 UTC
README
Framework-agnostic console input/output utilities for PHP 8.3+. Provides simple, chainable decorators for colored output and icons, plus convenient input helpers.
- Output:
CliOutput,ColoredCliOutput,IconCliOutput - Input:
CliInput - Examples: see the
examples/directory
Installation
Install via Composer in your project:
composer require adachsoft/console-io
Then make sure Composer's autoloader is included in your application entry point:
require_once __DIR__ . '/vendor/autoload.php';
Quick Start
Basic output
use Adachsoft\ConsoleIo\Output\CliOutput;
$output = new CliOutput();
$output->writeLine('Hello World!');
$output->write('Same line... ');
$output->writeLine('continued');
More examples: examples/basic_output.php (section "1. Basic output").
Colored output
ColoredCliOutput decorates any OutputInterface and replaces color tags with ANSI escape codes.
Foreground tags like <red>...</red> and background tags like <bg-green>...</bg-green> are supported.
use Adachsoft\ConsoleIo\Output\CliOutput;
use Adachsoft\ConsoleIo\Output\ColoredCliOutput;
$colored = new ColoredCliOutput(new CliOutput());
$colored->writeLine('<red>Red text</red>');
$colored->writeLine('<bg-yellow><black>Black on yellow</black></bg-yellow>');
More examples: examples/basic_output.php (section "2. Colored output").
Icons output
IconCliOutput decorates any OutputInterface and replaces icon tags like <icon_success/> with Unicode glyphs.
use Adachsoft\ConsoleIo\Output\CliOutput;
use Adachsoft\ConsoleIo\Output\IconCliOutput;
$icon = new IconCliOutput(new CliOutput());
$icon->writeLine('<icon_success/> Operation completed');
$icon->writeLine('<icon_error/> Error occurred');
More examples: examples/basic_output.php (section "3. Icons and symbols").
Combine decorators
Chain decorators to use icons and colors together.
use Adachsoft\ConsoleIo\Output\CliOutput;
use Adachsoft\ConsoleIo\Output\ColoredCliOutput;
use Adachsoft\ConsoleIo\Output\IconCliOutput;
$output = new ColoredCliOutput(new IconCliOutput(new CliOutput()));
$output->writeLine('<icon_success/> <green>All good!</green>');
$output->writeLine('<icon_error/> <bg-red><white>Critical error</white></bg-red>');
More examples: examples/basic_output.php (sections "4. Combined styles" and "5. Mixed in a single line").
Interactive Input
CliInput provides simple helpers for reading from STDIN, including prompting directly inside readLine().
use Adachsoft\ConsoleIo\Input\CliInput;
use Adachsoft\ConsoleIo\Output\CliOutput;
use Adachsoft\ConsoleIo\Output\ColoredCliOutput;
$input = new CliInput();
$output = new ColoredCliOutput(new CliOutput());
$name = $input->readLine("What's your name? ");
$output->writeLine('<cyan>Hello, ' . $name . '!</cyan>');
More examples: examples/interactive_input.php.
Progress Bars and Tables
Simple progress output can be achieved with carriage-return ("\r") updates. With ColoredCliOutput, you can color whole lines.
use Adachsoft\ConsoleIo\Output\CliOutput;
use Adachsoft\ConsoleIo\Output\ColoredCliOutput;
$output = new ColoredCliOutput(new CliOutput());
for ($i = 0; $i <= 100; $i += 5) {
$bar = str_repeat('█', intdiv($i, 2)) . str_repeat('░', 50 - intdiv($i, 2));
$color = ['red','yellow','green','cyan','blue','magenta'][intdiv($i, 20) % 6];
$output->write("\r<{$color}>[{$bar}] {$i}%</{$color}>");
usleep(50000);
}
For simple tables, print each formatted row and wrap it with a color tag depending on status. More examples: examples/progress_and_tables.php.
Supported Colors
ColoredCliOutput supports foreground and background colors via tags.
Foreground colors:
- black, red, green, yellow, blue, magenta, cyan, white, gray
- bright-black, bright-red, bright-green, bright-yellow, bright-blue, bright-magenta, bright-cyan, bright-white
Background colors:
- bg-black, bg-red, bg-green, bg-yellow, bg-blue, bg-magenta, bg-cyan, bg-white, bg-gray
- bg-bright-black, bg-bright-red, bg-bright-green, bg-bright-yellow, bg-bright-blue, bg-bright-magenta, bg-bright-cyan, bg-bright-white
Examples:
<red>Error</red><bg-green><black>OK</black></bg-green><bright-yellow>Warning</bright-yellow>
Note: The color reset is applied after each matched tag. Nesting like <bg-yellow><red>…</red></bg-yellow> is supported.
Supported Icons (Icon + Tag)
Below tables list all available icon tags with their glyphs. Use them in output as <tag/>, e.g., <icon_success/>.
Base set
| Icon | Tag |
|---|---|
| ❌ | icon_error |
| ⚠️ | icon_warning |
| 🤖 | icon_ai |
| ✅ | icon_success |
| ℹ️ | icon_info |
| 🏷️ | icon_label |
| 🔧 | icon_tool |
| 🚀 | icon_rocket |
| 👋 | icon_wave |
| 🧑 | icon_user |
| ❓ | icon_question |
| ⭐ | icon_star |
| 📁 | icon_folder |
| ➡️ | icon_arrow |
| ⏰ | icon_clock |
| 📥 | icon_inbox |
| 📧 | icon_mail |
| 📄 | icon_file |
| 💾 | icon_save |
| 🔍 | icon_search |
| 🔄 | icon_refresh |
| ✔️ | icon_check |
| ✖️ | icon_cross |
| ▶️ | icon_play |
| ⏹️ | icon_stop |
| ⏸️ | icon_pause |
Actions / Management
| Icon | Tag |
|---|---|
| ✏️ | icon_edit |
| 🗑️ | icon_trash |
| ⬆️ | icon_upload |
| ⬇️ | icon_download |
| 🔒 | icon_lock |
| 🔓 | icon_unlock |
| 🔑 | icon_key |
| ⚙️ | icon_settings |
System / Dev
| Icon | Tag |
|---|---|
| 💻 | icon_code |
| 🖥️ | icon_terminal |
| 🐛 | icon_bug |
| 🛡️ | icon_shield |
| ⚡ | icon_bolt |
Files / Data
| Icon | Tag |
|---|---|
| 🛢️ | icon_database |
| 🗓️ | icon_calendar |
| 📋 | icon_clipboard |
| 📎 | icon_paperclip |
| 🔖 | icon_bookmark |
| 📘 | icon_book |
Media
| Icon | Tag |
|---|---|
| 🎵 | icon_music |
| 📷 | icon_camera |
| 🎬 | icon_video |
| ⏺️ | icon_record |
| ⏩ | icon_fast_forward |
| ⏪ | icon_rewind |
| ⏭️ | icon_skip_next |
| ⏮️ | icon_skip_prev |
Communication / Network
| Icon | Tag |
|---|---|
| 🔗 | icon_link |
| 📶 | icon_wifi |
| ☁️ | icon_cloud |
| 🌐 | icon_globe |
| 🌍 | icon_globe_europe |
Weather / Time
| Icon | Tag |
|---|---|
| ☀️ | icon_sun |
| 🌙 | icon_moon |
| 🌧️ | icon_rain |
| ❄️ | icon_snowflake |
| ⏳ | icon_hourglass |
Status / Reactions
| Icon | Tag |
|---|---|
| ❤️ | icon_heart |
| 👍 | icon_thumb_up |
| 👎 | icon_thumb_down |
| 🔔 | icon_bell |
| 🔕 | icon_mute |
| ✨ | icon_sparkles |
| 🏆 | icon_trophy |
Location / Logistics
| Icon | Tag |
|---|---|
| 🏠 | icon_home |
| 🏢 | icon_office |
| 🗺️ | icon_map |
| 📍 | icon_location |
| 🛒 | icon_cart |
| 🚚 | icon_truck |
| 💰 | icon_money |
| 💳 | icon_credit_card |
| 📈 | icon_chart |
Development (for contributors)
Clone the repository and install dev dependencies:
git clone https://github.com/adachsoft/console-io.git
cd console-io
composer install
Notes
- ANSI colors depend on terminal support. On Windows, modern terminals (Windows Terminal, VS Code) work well. Legacy cmd.exe may not fully support colors or emoji.
- This library is framework-agnostic. You can wire classes manually or via any DI container you prefer.
More Examples
- examples/basic_output.php – basic, colored, icons, and combined usage
- examples/interactive_input.php – interactive prompts and colored responses
- examples/progress_and_tables.php – progress bars and simple colored tables