ogbitblt / output
用于以流行格式记录文本输出的库
v1.0.0
2022-12-27 04:03 UTC
Requires
- php: ^8.2.0
This package is not auto-updated.
Last update: 2024-10-02 11:23:13 UTC
README
安装
您可以从github下载源代码并将其直接用于您的项目,或者您可以使用composer通过以下方式安装它:
composer require ogbitblt-output
使用方法
将文本输出到终端控制台
use OGBitBlt\Output\Console; use OGBitBlt\Output\OutputFactory; // alternatively, you can also // $console = new Console(); $console = OutputFactory::Create(Console::class); // clear the terminal $console->Clear(); // draw a line 80 characters wide using the % character $console->DrawLn('%',80); /* * You can output text in different colors using the following macros * %RED() -- red * %GREEN() -- green * %YELLOW() -- yellow * %BLUE() -- blue * %MAGENTA() -- magenta * %CYAN() -- cyan * %LGRAY() -- light gray * %DGRAY() -- dark gray * %LRED() -- light red * %LGREEN() -- light green * %LYELLOW() -- light yellow * %LBLUE() -- light blue * %LMAGENTA() -- light magenta * %LCYAN() -- light cyan * %WHITE() -- white */ // write a text without a newline character $console->Write("Hello,"); // write with a newline character $console->WriteLn("World!"); // change text colors $console->WriteLn("The american flag is %RED(red), %WHITE(white), and %BLUE(blue)");
输出到文件
use OGBitBlt\Output\OutputCompressionType; use OGBitBlt\Output\OutputEncodingType; use OGBitBlt\Output\OutputFactory; use OGBitBlt\Output\TextFile; // alternatively you can also: // $outfile = new TextFile("somefile.txt"); $outfile = OutputFactory::Create(TextFile::class,['file' => "somefile.txt"]); $outfile->Write("string without a newline character"); $outfile->WriteLn("string with a newline character"); // change encoding to base64 $outfile->Write("this is base64 encoded",['encoding' => OutputEncodingType::Base64]); // gzip output $outfile->Write("this is gzipped",['compression' => OutputCompressionType::Gzip]);
贡献
欢迎提交拉取请求。对于重大更改,请首先提交一个问题以讨论您希望进行的更改。
请确保根据需要更新测试。