nvan/cli-plus

CLI Plus 是一个用于为 CLI 应用程序添加颜色和效果的 PHP 小型库

资助包维护!
Paypal

v1.0.0 2022-10-11 12:19 UTC

This package is not auto-updated.

Last update: 2024-09-25 19:44:52 UTC


README

CLI Plus 是一个小型 PHP 库,允许您为输出到终端/命令行的文本设置颜色和格式。

如果您制作在命令行上运行的应用程序并希望使它们看起来更美观,这将非常有用。

它基于 C# 或其他语言中使用的控制台的概念。

如何使用

首先,通过 composer 导入库

composer require nvan/cli-plus

一旦安装了库

use nvan\CliPlus\Console;
Console::writeLine('Hello world!');
Console::write('This is on the next line!');
Console::write('But this is not!');

您可以通过以下方式应用前景(文本)颜色和背景颜色

use nvan\CliPlus\Colors;
Console::setForegroundColor(Colors::White);
Console::setBackgroundColor(Colors::Red);
Console::write('This text is white with red background!');

要应用样式,请执行

use nvan\CliPlus\Formats;
Console::setFormat(Formats::Bold);
Console::write('This text is bold!');

格式和颜色列表(带示例)可在以下位置找到:https://misc.flogisoft.com/bash/tip_colors_and_formatting

未来更新

我计划添加某种用户输入处理,类似于 Java 中的 nextInt、nextX(type)。

此外,我想实现一些功能,如读取在文本隐藏时(类似小 Linux 风格)的密码,尽管这可以通过,但不会像更新后那样简单,通过执行以下操作

Console::write('Enter your password: ');
Console::addFormat(Formats::Hidden);
Console::write();
$pass = readline();
Console::removeFormat(Formats::Hidden);

if($pass === '12345') {
    Console::setForegroundColor(Colors::LightGreen);
    Console::writeLine('Password is correct! Welcome!');
}

捐赠

如果您使用并喜欢这个库,考虑给我买一瓶 🍺 啤酒。

您可以通过 PayPal 捐赠

paypal

许可协议

MIT