adhocore / cli-syntax
PHP CLI 代码语法高亮器
0.4.0
2020-01-08 07:41 UTC
Requires
- php: >=7.0.0
- ext-dom: *
- ext-gd: *
- adhocore/cli: ^0.8.3
Requires (Dev)
- phpunit/phpunit: ^6.5 || ^7.5
README
_ _ _
___ | | (_) ___ | |__
/ __| | | | | / __| ' _ \
| (__ | | | | \___ \ | | | |
\___| |_| |_| |____/ |_| |_|
PHP CLI Syntax Highlight Tool
=============================
安装
作为 phar 二进制文件
curl -SsLo ~/clish.phar https://github.com/adhocore/php-cli-syntax/releases/latest/download/clish.phar chmod +x ~/clish.phar && sudo ln -s ~/clish.phar /usr/local/bin/clish
升级时遵循相同步骤。
作为独立二进制文件
composer global require adhocore/cli-syntax
升级时遵循相同步骤。
作为项目依赖项
composer require adhocore/cli-syntax
用法
Shell 命令
如果您按照上述任何一种方法安装了二进制文件,则
# you will be able to run it as clish -h clish -f file.php echo '<?php date("Ymd");' | clish cat file.php | clish # export png clish -f file.php -o file.png
clish
代表 CLI 语法高亮。
选项
参数选项
[-e|--echo] Forces echo to STDOUT when --output is passed
[-f|--file] Input PHP file to highlight and/or export
(will read from piped input if file not given)
[-F|--font] Font to use for export to png
[-l|--with-line-no] Highlight with line number
[-o|--output] Output filepath where PNG image is exported
运行
clish -h
显示帮助。
示例
bin/clish --file file.php # print cat file.php | bin/clish # from piped stream bin/clish < file.php # from redirected stdin bin/clish --file file.php --output file.png # export bin/clish --file file.php --output file.png --echo # print + export bin/clish --file file.php --with-line-no # print with lineno bin/clish -f file.php -o file.png -F dejavu # export in dejavu font
程序化
您可以在终端输出中突出显示 PHP 代码或导出为 png 图像。
突出显示
use Ahc\CliSyntax\Highlighter; // PHP code echo new Highlighter('<?php echo "Hello world!";'); // OR echo (new Highlighter)->highlight('<?php echo "Hello world!";', $options); // PHP file echo Highlighter::for('/path/to/file.php', $options); // $options array is optional and can contain: [ 'lineNo' => true, // bool ];
导出
use Ahc\CliSyntax\Exporter; // PHP file Exporter::for('/path/to/file.php')->export('file.png', $options); // $options array is optional and can contain: [ 'lineNo' => true, // bool 'font' => 'full/path/of/font.ttf', // str 'size' => 'font size', // int ];
见 示例用法。以下是导出的外观
并带有行号
定制
如果您想更改颜色等,扩展 Highlighter
和 Exporter
类,然后重写接收 DOMNode
的 visit()
方法。
贡献
请查看 指南。
许可证
© MIT | 2019, Jitendra Adhikari