adhocore/cli-syntax 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adhocore/cli-syntax

Composer 安装命令:

composer require adhocore/cli-syntax

包简介

PHP Code Syntax Highlighter for CLI

README 文档

README

Latest Version Travis Build Scrutinizer CI Codecov branch StyleCI Software License

        _   _          _
  ___  | | (_)  ___   | |__
 / __| | | | | / __|  '  _  \
| (__  | | | | \___ \ | | | |
 \___| |_| |_| |____/ |_| |_|

PHP CLI Syntax Highlight Tool
=============================

Installation

As phar binary

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

Follow same steps to upgrade.

As standalone binary

composer global require adhocore/cli-syntax

Follow same steps to upgrade.

As project dependency

composer require adhocore/cli-syntax

Usage

Shell command

If you installed as binary following any of the above methods, then:

# 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 stands for CLI syntax highlight.

Options

Parameter options:

  [-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

Run clish -h to show help.

Examples
  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

Programatically

You can either highlight PHP code in terminal output or export to png image.

Highlight

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
];

Export

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
];

See example usage. Here's how the export looks like:

adhocore/cli-syntax

And with line numbers:

Example with line numbers

Customisation

If you would like to change color etc, extend the classes Highlighter and Exporter, then override visit() method which recieves DOMNode.

Contributing

Please check the guide.

LICENSE

© MIT | 2019, Jitendra Adhikari

Credits

This project is bootstrapped by phint and releases managed by please.

统计信息

  • 总下载量: 129
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固