geekdevs/cli-highlighter

There is no license information available for the latest version (1.0.3) of this package.

Library which is used to colorize syntax of xml, yaml and json in console.

1.0.3 2019-03-18 10:16 UTC

This package is auto-updated.

Last update: 2024-04-06 21:30:51 UTC


README

This is a syntax highlighter library used to colorize output of xml, json and yaml formats to be displayed in command-line utilities.

Installation

composer require geekdevs/cli-highlighter

Usage

Use individual highlighters:

$highlighter = new JsonHighlighter($jsonOptions);
echo $highlighter->highlight($input);

$highlighter = new XmlHighlighter($xmlOptions);
echo $highlighter->highlight($input);

$highlighter = new YamlHighlighter($yamlOptions);
echo $highlighter->highlight($input);

Use helper service for multiple formats

$options = [
    'json' => [
        'keys'   => 'magenta',
        'values' => 'green',
        'braces' => 'light_white',
    ],

    'xml' => [
        'elements'   => 'yellow',
        'attributes' => 'green',
        'values'     => 'green',
        'innerText'  => 'light_white',
        'comments'   => 'gray',
        'meta'       => 'yellow',
    ],

    'yaml' => [
        'separators' => 'blue',
        'keys'       => 'yellow',
        'values'     => 'light_white',
        'comments'   => 'gray',
    ],
];

$highlighter = new \CliHighlighter\Service\Highlighter($options);

echo $highlighter->highlight($input, 'json');
echo $highlighter->highlight($input, 'xml');
echo $highlighter->highlight($input, 'yaml');

Use as console tool

You can use vendor/bin/highlighter script with preconfigured colors for json, xml, yaml. Like this

vendor/bin/highlighter json < input.json
vendor/bin/highlighter xml < input.xml
vendor/bin/highlighter yaml < yaml.xml

Alternativelym you can pipe this command like so:

echo "<hello name=\"world\" />" | vendor/bin/highlighter xml