psdi / motif
本软件包最新版本(v1.0)没有提供许可证信息。
PHP CLI 输出格式化工具
v1.0
2020-03-23 17:25 UTC
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-24 03:49:20 UTC
README
一个简单的PHP工具,用于在终端上格式化输出文本。
安装
使用composer安装
composer require psdi/motif [--no-dev]
如果您想排除安装PHPUnit(它不是一个轻量级框架),请包含标志
--no-dev
。
用法
Formatter
类有三个主要的输出函数
format
函数接受一个字符串以及一个样式字符串
样式字符串的语法如下:
[format,styles]|color:[color]|bg:[background]
。样式的顺序不重要;您甚至可以省略它们。
formatLine
函数扩展了format
;然而,它将在文本末尾添加一个换行符display
函数接受一个文本以及一个模式(成功、警告、错误、信息)。该函数将使用相应的背景颜色(绿色、黄色、红色、蓝色)打印文本。
<?php // index.php require 'vendor/autoload.php'; use Motif\Formatter; // [1] Prints 'Hello, world!' (bold and underlined) in green on console echo Formatter::formatLine('Hello, world!', 'bold|color:green'); // [2,3] Examples with and without line breaks echo Formatter::format('Somebody once told me,', 'strike|color:black|bg:blue'); echo Formatter::formatLine(' the world was gonna roll me.', 'underline|color:cyan'); // [4] Prints 'Error downloading files.' in white with a red background echo Formatter::display('Error downloading files.', 'error'); // [5,6,7] Some more examples echo Formatter::formatLine('This is a sample text. ', 'bold,italic|color:yellow'); echo Formatter::formatLine( 'This is also a sample text, but in magenta.', 'italic|color:magenta' ); echo Formatter::display('Success! •ᴗ•', 'success');
以上代码将产生以下效果
贡献
如果您发现错误或有任何建议,请随时将其添加到问题跟踪器。