adachsoft/console-io
Advanced PHP console input/output library with colors, icons and interactive features
Maintainers
Requires
- php: >=8.3
Requires (Dev)
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT 31caa9182e2dae83cf7e0f8362f6408e6a1132b1
- Arkadiusz Adach
This package is not auto-updated.
Last update: 2026-06-27 07:53:02 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
