adhocore/cli-syntax

_ _ _
___ | | (_) ___ | |__
/ __| | | | | / __| ' _ \
| (__ | | | | \___ \ | | | |
\___| |_| |_| |____/ |_| |_|
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:
clish -h
clish -f file.php
echo '<?php date("Ymd");' | clish
cat file.php | clish
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
cat file.php | bin/clish
bin/clish < file.php
bin/clish --file file.php --output file.png
bin/clish --file file.php --output file.png --echo
bin/clish --file file.php --with-line-no
bin/clish -f file.php -o file.png -F dejavu
Programatically
You can either highlight PHP code in terminal output or export to png image.
Highlight
use Ahc\CliSyntax\Highlighter;
echo new Highlighter('<?php echo "Hello world!";');
echo (new Highlighter)->highlight('<?php echo "Hello world!";', $options);
echo Highlighter::for('/path/to/file.php', $options);
[
'lineNo' => true,
];
Export
use Ahc\CliSyntax\Exporter;
Exporter::for('/path/to/file.php')->export('file.png', $options);
[
'lineNo' => true,
'font' => 'full/path/of/font.ttf',
'size' => 'font size',
];
See example usage. Here's how the export looks like:

And 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.