Git Product home page Git Product logo

ansi-to-html's People

Contributors

adam187 avatar cordoval avatar fabpot avatar jackbentley avatar jean85 avatar lyrixx avatar maxhelias avatar skolodyazhnyy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansi-to-html's Issues

How do I include this in my project?

Hi, I did a git clone of the project. How do I integrate it into my project? with the composer autoloader?
I get 'Uncaught error: Class 'AnsiToHtmlConverter' not found when I run it.

Does not handle CR LF with a color change in between appropriately

As I found out the very hard way (half of my output not showing and an hour of debugging), some programs throw a color change in their output between a CR and a LF. I.e. [CR][ESC][31m[LF]

AnsiToHtmlConverter.php erases a line followd by [CR][color change][LF] since it thinks the color change is text at the beginning of a new line so it "overwrites" (deletes) the old line. It isn't Terminals like Putty will handle this correctly.

Proposed fix: for me this change in AnsiToHtmlConverter.php (line 50) worked.

$text = preg_replace('#^.*\r((\x9B|\x1B\[)[0-?]*[ -\/]*[@-~])*(?!\n)#ms', '', $text);

Probably the regex can be a bit simpler (I included all ANSI codes in the regex, that's overkill. I took it from https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python#33925425 ).

Foreground color is set to background color if sequence lists background first

I came across a weird behavior while using the library - if background color (e.g. 42 - green) is specified before foreground (e.g. 30 - black) the render will contain black text on black background. Weirdly enough this happens only for separated sequences (e.g. ^[[0m^[[42m^[[30m) and not while parsing their short forms (e.g. ^[[42;30m).

I used following example to demonstrate the problem (also attached):
Download raw

^[[30;42mWORKS1^[[0m
^[[0m^[[42m^[[30mDOESNT1^[[0m
^[[0m^[[30m^[[42mWORKS2^[[0m
^[[42;30mWORKS1^[[0m

Rendering in GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
bash-render

HTML from ansi-to-html v1.1.3

<?php
$output = (new AnsiToHtmlConverter())->convert($test);
<span style="background-color: green; color: black">WORKS1</span><span style="background-color: black; color: white"><br />
</span><span style="background-color: black; color: black">DOESNT1</span><span style="background-color: black; color: white"><br />
</span><span style="background-color: green; color: white">WORKS2</span><span style="background-color: black; color: white"><br />
</span><span style="background-color: green; color: black">WORKS1</span><span style="background-color: black; color: white"><br />
</span>

Alternative css class naming doesn't work due to hardcoded values

I tried to shorten the output by defining the css prefix as 'ac', but realized that it will never work due to the fact that the converter has ansi_color_ hardcoded and there is no connection between the Theme and the Converter.

$converter = new AnsiToHtmlConverter();
$converter->convert('some random cli output'); // returns classes with "ansi_color" prefix
$converter->getTheme()->asCss('css_prefix_for_ansi_color'); // returns styles with given prefix

New 80's Hacker Theme

<?php

/*
 * This file is part of ansi-to-html.
 *
 * (c) 2013 Fabien Potencier
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SensioLabs\AnsiConverter\Theme;

/**
 * Hacker theme.
 *
 * @see http://ethanschoonover.com/solarized
 */
class HackerTheme extends Theme
{
    public function asArray()
    {
        return array(
            // normal
            'black' => '#000000',
            'red' => '#800000',
            'green' => '#008000',
            'yellow' => '#808000',
            'blue' => '#000080',
            'magenta' => '#800080',
            'cyan' => '#008080',
            'white' => '#808080',

            // bright
            'brblack' => '#606060',
            'brred' => '#FF0000',
            'brgreen' => '#00FF00',
            'bryellow' => '#FFFF00',
            'brblue' => '#0000FF',
            'brmagenta' => '#FF00FF',
            'brcyan' => '#00FFFF',
            'brwhite' => '#FFFFFF',
        );
    }
}

Release 1.1.1

Hello,

Is there any chance to see a 1.1.1 release including 3f08b01 or should I stick with dev-master ?

How to preserve new lines

My command prints a bunch of lines using writeln function, but the ansi-to-html converter does not make separate lines out of them.
Is there a way to achieve this?

carriage return issue

In convert() method, if detect \r, erase the entire line :

replace:
$text = preg_replace('#^.*\r(?!\n)#m', '', $text);

by:
$text = preg_replace('#^(.*)\r(?!\n)#m', '$1', $text);

Does not preserve carriage return

Console display :

$ ./app/console  project:ota:update
Check if new firmware is available...
Found embeded Firmware for Xxxxx on 0.2.6 (206)

But actualy Html display :

<span style="background-color: black;color: yellow;display: block;">Check if new firmware is available...</span><span style="background-color: black;color: white;display: block;"></span><span style="background-color: black;color: yellow;display: block;">Found embeded Firmware for Xxxxx (heater) on 0.2.6 (206)</span><span style="background-color: black; color: white"></span>

Html should be display :

<span style="background-color: black;color: yellow;">Check if new firmware is available...</span><br/><span style="background-color: black;color: yellow;">Found embeded Firmware for Xxxxx (heater) on 0.2.6 (206)</span>

my code :
In ContainerAwareCommand

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('<comment>Check if new firmware is available...</comment>');
        $output->writeln("<comment>Found Alfred embeded Firmware for $board  on $ver ($version)</comment>");
    }

In Controller

    public function scanAction()
    {
        $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true );

... Call my command ...

        // return the output
        $converter = new AnsiToHtmlConverter(); //new SolarizedTheme(), true);
        $content = $converter->convert($output->fetch());

        $this->addFlash('sonata_flash_success', "$content");
    }

With :

  • Debian Testing
  • Php 7.0
  • Symfony 2.8
  • Sonata Admin 3.0

typo in README.md

I thing in the README.md the following line :

$twig->addExtension(AnsiExtension($converter));

should be corriged to :

$twig->addExtension(new AnsiExtension($converter));

AnsiExtension is a class and not a function

Small bug in choosing intense colors

Here's the fix:

        foreach ($options as $option) {
            if ($option >= 30 && $option < 38) {
                $fg = $option - 30;

            } elseif ($option >= 40 && $option < 48) {
                $bg = $option - 40;
            } elseif ($option >= 90 && $option < 98) { // This needs to be added
                $fg = $option - 80; // This needs to be added
            } elseif (39 == $option) {

...
}

TwigExtension.

For one of my project, I had to create a twig extension.
Do you want a PR?

<?php

use SensioLabs\AnsiConverter\AnsiToHtmlConverter;

class AnsiExtension extends \Twig_Extension
{
    private $converter;

    public function __construct(AnsiToHtmlConverter $converter = null)
    {
        $this->converter = $converter ?: new AnsiToHtmlConverter();
    }

    public function getFilters()
    {
        return array(
            new \Twig_SimpleFilter('ansi_to_html', array($this, 'ansiToHtml'), array('is_safe' => array('html'))),
        );
    }

    public function ansiToHtml($string)
    {
        return $this->converter->convert($string);
    }

    public function getName()
    {
        return 'ansi';
    }
}

It would be nice to add a twig function ansi_css that will ouput the inline CSS.
But to do that, we need AnsiToHtmlConverter::getTheme

(?:\e\[(.*?)m|(\x08)) incorrect

string = '� �� ��[KGi0/0/0/8 admin-down admin-down '
Output after replacing = in-down admin-down (Gi0/0/0/8 is lost)

[31] => Array
(
[0] => color
[1] => KGi0/0/0/8 ad
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.