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.

Installs: 314

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 1

pkg:composer/geekdevs/cli-highlighter

1.0.3 2019-03-18 10:16 UTC

This package is auto-updated.

Last update: 2025-10-07 01:07:56 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