This package is abandoned and no longer maintained. The author suggests using the sensiolabs/ansi-to-html package instead.

A twig extension for sensiolabs/ansi-to-html

v1.0.0 2013-03-23 01:53 UTC


Inspired by the sensiolabs/ansi-to-html release, I wanted to create a quick Twig extension for rendering ANSI as HTML inside Twig templates.


Add the requirement to your composer.json (it should fetch ansi-to-html automatically):

      "require": {
        "beryllium/twig-ansi-extension": "dev-master"


First, get sensiolabs/ansi-to-html configured the way you like it. Then you can do this:

Default usage:

    $twig->addExtension(new Beryllium\TwigAnsiExtension\TwigAnsiExtension($ansi));

Optional "themed" usage:

    $twig->addExtension(new Beryllium\TwigAnsiExtension\TwigAnsiExtension($ansi,$theme));

And now you can use it inside twig, like so:

    {{ 'my_ansi_string'|ansi|raw }}

If you opted to add the theme, you should be able to output the style CSS like so:

    {{ get_ansi_css()|raw }}

Current Status

At the moment this is just a quick prototype, I haven't even tested the theme support. In my local environment, I'm using the "colordiff" system utility to generate sample ANSI output. Other examples of ANSI output include PHPUnit with colors enabled, and especially PHPUnit results with NyanCat output enabled (although I don't think streaming would work).