定制 adachsoft/console-io 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adachsoft/console-io

Composer 安装命令:

composer require adachsoft/console-io

包简介

Advanced PHP console input/output library with colors, icons and interactive features

README 文档

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

IconTag
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

IconTag
✏️icon_edit
🗑️icon_trash
⬆️icon_upload
⬇️icon_download
🔒icon_lock
🔓icon_unlock
🔑icon_key
⚙️icon_settings

System / Dev

IconTag
💻icon_code
🖥️icon_terminal
🐛icon_bug
🛡️icon_shield
icon_bolt

Files / Data

IconTag
🛢️icon_database
🗓️icon_calendar
📋icon_clipboard
📎icon_paperclip
🔖icon_bookmark
📘icon_book

Media

IconTag
🎵icon_music
📷icon_camera
🎬icon_video
⏺️icon_record
icon_fast_forward
icon_rewind
⏭️icon_skip_next
⏮️icon_skip_prev

Communication / Network

IconTag
🔗icon_link
📶icon_wifi
☁️icon_cloud
🌐icon_globe
🌍icon_globe_europe

Weather / Time

IconTag
☀️icon_sun
🌙icon_moon
🌧️icon_rain
❄️icon_snowflake
icon_hourglass

Status / Reactions

IconTag
❤️icon_heart
👍icon_thumb_up
👎icon_thumb_down
🔔icon_bell
🔕icon_mute
icon_sparkles
🏆icon_trophy

Location / Logistics

IconTag
🏠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

adachsoft/console-io 适用场景与选型建议

adachsoft/console-io 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 87 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cli」 「console」 「output」 「colors」 「command-line」 「input」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 adachsoft/console-io 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 adachsoft/console-io 我们能提供哪些服务?
定制开发 / 二次开发

基于 adachsoft/console-io 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 87
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 12
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-04