lupecode / console
一个用于控制台打印的库。
0.7.1
2020-12-15 20:26 UTC
This package is auto-updated.
Last update: 2024-09-06 19:35:22 UTC
README
这是什么?
这个库是一个用于ANSI颜色、进度条和表格的控制台助手。
如果你的控制台不是Windows命令提示符,并且你的控制台可以显示颜色,这个库将帮助你让你的PHP控制台应用程序更炫。
要求
此库需要PHP >= 7.0。
Readline
如果你希望使用 Console::readline
,Console::promptReadline
或 Console::optionsReadline
,你需要确保PHP中的readline模块已加载。在Windows上,这需要PHP >= 7.1.0。
安装
安装此控制台助手最佳方式是使用Composer。
composer require lupecode/console
如何使用
tl;dr
查看测试文件夹。
基本打印
Console::print('Hello World'); // Will not print a new line at the end Console::printLine('Hello World'); // Will print a new line at the end
内置样式
控制台有一些内置样式。
Console::printHeader('Header Message'); // Prints the text in a yellow box Console::printDebug('Debug Message'); // Prints the text in a gray color Console::printError('Error Message'); // Prints the text in a red color Console::printStatus('Status Message'); // Prints the text in a blue color Console::printSuccess('Success Message'); // Prints the text in a green color
16色调色板
控制台支持16色调色板。
$color = new Color16(); $color ->setBackgroundColor(Color::YELLOW) ->setForegroundColor(Color::BLACK) ->setFlag(Color::BOLD) ; Console::printLine('Print Line In Color', $color);
256色调色板
控制台支持256色调色板。这些颜色从0到5(对于216种颜色)以RGB形式变化。有24级灰度。
$color = new Color256(); $color ->setBackgroundColor(5,5,0) ->setForegroundColorGrayscale(0) ->setFlag(Color::BOLD) ; Console::printLine('Print Line In Color', $color);
进度条
控制台支持进度条。
$pBar = Console::progressBar(); $pBar->setBarSize(30)->setTotal(100)->startTimer(); for ($i = 0; $i < 100; $i++) { $pBar->increment(); } $pBar->finish();
表格
控制台支持表格。
Console::table() ->addColumn('ID') ->addColumn('Title') ->addColumn('ISBN') ->addRow([1, 'Lorem Ipsum and the Valley of Goblins', '987-12345678-1']) ->addRow([2, 'Lorem Ipsum and the Chair of Sadness', '987-12345678-2']) ->addRow([3, 'Lorem Ipsum and the Sands of Itchiness', '987-12345678-3']) ->addRow([4, 'Lorem Ipsum and the Lingua Franca', '987-12345678-4']) ->printTable() ;