webbtj/clico 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

webbtj/clico

Composer 安装命令:

composer require webbtj/clico

包简介

Expressive API to colour and format text output to stdOut for CLI interactions

README 文档

README

Command Line Interface Coloured Output

Clico is a PHP package that gives you an expressive API to format text for CLI output. Clico gives chainable methods to set text background and foreground colours, weight, and other text decorations like underlining and blinking.

Clico also provides functionality for formatting tabular data for CLI output. The table class can also format the text in each row, each column, and each individual cell.

Clico is framework agnostic, just install and use the provided classes.

Full API Docs

Full API documentation can be found here, however the below guide should be enough to get most users started. Source Code

Installation

Install via composer.

composer require webbtj/clico

Useage

Once installed you can use the Text and Table classes in your own code.

use Webbtj\Clico\Text;
use Webbtj\Clico\Table;

Both the Text and Table classes return strings via their __toString methods.

Using Text

The Text class provides several chainable methods to alter the rendering of text in the CLI output.

Colours

  • black() - set the text or background colour to black.
  • blue() - set the text or background colour to blue.
  • cyan() - set the text or background colour to cyan.
  • green() - set the text or background colour to green.
  • magenta() - set the text or background colour to magenta.
  • red() - set the text or background colour to red.
  • white() - set the text or background colour to white.
  • yellow() - set the text or background colour to yellow.

Effects

  • b(), bold(), heavyWeight(), strong() - make the text bold.
  • blink(), flash() - make the text blink.
  • dim(), lightWeight(), thin() - make the text light weight (dimmer).
  • hidden(), hide() - make the text invisible.
  • highlight() - highlight the text (reverse background and foreground colours).
  • normal(), normalWeight() - make the text normal weight.
  • u(), underline() - underline the text.

Background/Foreground

By default the foreground (text) colour is being manipulated, however you can switch between changing the background and foreground colours with chain methods. Switching to either layer causes future chained colour methods to affect that layer.

  • background() - switch to manipulating the background colour.
  • foreground() - switch to manipulating the foreground colour.

Shading

  • dark() - makes subsequent colour methods use their dark variants.
  • darken() - changes the currently set colour (back- or foreground) to its dark variant.
  • light() - makes subsequent colour methods use their light variants.
  • lighten() - changes the currently set colour (back- or foreground) to its light variant.

Utilities

  • getText() - returns the plain (undecorated) text.
  • length() - returns the length of the undecorated string.
  • repeat(int $repeat) - set the text to repeat $repeat times at render. repeat() does not affect the outputs of getText() or length().
  • setDefault(bool $setAll) - sets the currently set layer (back- or foreground) to its default colour. $setAll = true to change both layers.
  • text(string $text) - sets the text value. Multiple calls will override previously set values. $text can also be passed to the constructor.

Examples

use Webbtj\Clico\Text;

echo (new Text())->text('Example #1')->red()->bold();
  // will output "Example #1" in bold, red text.

echo (new Text('Example #2))->blue()->blink();
  //will output "Example #2" in blinking, blue text.

$text = new Text();
$text->test('Example #3');
$text->foreground()->dark()->blue()->background()->light()->red();
$text->underline();
echo $text;
  // will output "Example #3" in underlined, dark blue text
  // with a light red background

Using Table

The Table class provides an expressive API for formatting tabular data for CLI output. The class provides methods for adding header and body content, manipulating the characters used for the table layout, and provides all of the Text methods which can target the whole table, a row, a column, or a single cell.

Adding Data

  • __construct(Array $data, bool $firstRowAsHeader) - the constructor can optionally set the table data and can sepcify if the first row is the header.
  • addHeader(Array $row) - adds the provided data as the header row. Unsets the previous header row.
  • addRow(Row $row) - add a single Row to the end of the table.
  • populate(Array $data) - adds new rows for each entry in the provided array.
  • setFirstRowAsHeader() - make the first row the header row.

Setting Table Characters

  • setHeaderLineCharacter(string $char) - sets the character used to separate the header row from the table body.
  • setPipeCharacter(string $char) - sets the character used to separate table columns.
  • setRowLineCharacter(string $char) - sets the character used to separate tabke body rows.

Formatting

The Table class provides all of the text formatting methods of the Text class. Those methods are, by default, applied to all cells in the table. You can specify an entire row, column, or single cell to target with subsequent text formatting methods.

  • cell(int $column, int $row) - set the specific cell to target for formatting. $column and $row are zero based.
  • column(int $index) - set the column to target for formatting. $index is zero based. Omit $index to unset a previously selected column.
  • distributeColumns(int $width) - sets the desired width (in characters) of the table. This happens automatically by default with a width of 160. If you want a different width, this should be called after all data has been populated and before rendering.
  • row(int $index) - set the row to target for formatting. $index is zero based. Omit $index to unset a previously selected row.

Meta Data

  • getHeaderLineCharacter() - gets the character used to separate the header row from the table body. This returns the decorated text version.
  • getHeight() - gets the number of rows in the table.
  • getPipeCharacter() - gets the character used to separate table columns. This returns the decorated text version.
  • getRowLineCharacter() - gets the character used to separate tabke body rows. This returns the decorated text version.
  • getWidth() - gets the number of columns in the table.

Contributing

Contributions are always welcome on GitHub. Please open issues before submitting PRs and do tag the issue in your commit messages/PR description. Also, please adhere to PSR-2 as much as possible.

webbtj/clico 适用场景与选型建议

webbtj/clico 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 webbtj/clico 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-08