troublete / crayon

此包已废弃,不再维护。未建议替代包。

一个简单的PHP库,用于格式化字符串输出

1.2.0 2018-02-21 21:25 UTC

This package is not auto-updated.

Last update: 2020-01-24 17:06:40 UTC


README

一个简单的PHP库,用于格式化字符串输出 🌈

Build Status Reliability

预览

preview

安装

$ composer require troublete/crayon

简介

库的目的是简化PHP CLI上字符串格式化的使用。使用应严格为函数式,以最少的代码实现最大的影响。简单使用函数Crayon\text,它返回一个Crayon\Font实例,用于处理格式化并将结果作为字符串返回。格式化调用可以链式调用。

⚠️ 注意:存在格式化顺序:下划线 > 斜体 > 粗体 > 颜色。最后设置的颜色将被使用,并且斜体比粗体格式化更重要。所以如果两个选项都设置了,将使用先前的选项。

使用

<?php
require_once 'path/to/vendor/autoload.php';

use function Crayon\{text as crayon, error, success};

echo crayon('text')->green(); // returns green text
echo crayon('text')->green()->bold(); // returns bold green text
echo crayon('text')->green()->underline()->bold(); // returns underlined bold green text
echo crayon('text')->green()->underline()->bold()->background(); // returns underlined bold green backgrounded text

echo success('text'); // returns green bold text with checkmark at the end
echo error('text'); // returns red bold text with x at the end

API

Crayon\Font

->bold() – 设置文本粗体

->italic() – 设置文本斜体

->underline() – 设置文本下划线

->red() – 设置文本颜色为红色

->green() – 设置文本颜色为绿色

->yellow() – 设置文本颜色为黄色

->blue() – 设置文本颜色为蓝色

->magenta() – 设置文本颜色为洋红色

->cyan() – 设置文本颜色为青色

->background() – 将着色从前景色转换为背景色着色

许可证

GPL-2.0 © Willi Eßer