fusesource / jansi

Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.
http://fusesource.github.io/jansi/
Apache License 2.0
1.12k stars 139 forks source link

HtmlAnsiOutputStream and other mysteries #71

Closed Mrodent closed 7 years ago

Mrodent commented 7 years ago

Hi, just discovered this library... it looks great.

But dare I say the minimal documentation is just a little TOO minimal? OK, it's not a big library, but for example, I'm wondering what HtmlAnsiOutputStream actually does... Having googled unsuccessfully I'm now contemplating examining the source code. Why is it called "HTML", for example? At the moment I have a project where currently I'm outputting to the console (and want colour), but in future will almost certainly be outputting to a browser ... so it makes sense to construct output in HTML markup and then convert using Jsoup and Jansi for terminal output.

But I currently have no idea whether HtmlAnsiOutputStream can help with this... a "Jansi 101" would be helpful ... or a tiny bit more Javadoc commentary perhaps?

And... for example, trying to use ansi().render( "@|red,bold blah blah|@")... where might I find a list of the available markup "words"... ?

I mean, I tried System.out.println( ansi().render("@|red,bold,italic Hello|@ @|green World|@") ); ... which worked But then I tried System.out.println( ansi().render("@|red,bold,italic,blink Hello|@ @|green World|@") ); ... which didn't:

Exception in thread "main" java.lang.IllegalArgumentException: No enum const.AnsiRenderer.Code.BLINK

gnodet commented 7 years ago

The HtmlAnsiOutputStream turns ansi escape sequences into html markup, but I'm not sure how useful is it. If it does not suit your needs but looks reusable in your case, you could provide some PR, else implement your own AnsiOutputStream.

For available markup "words", you can have a look at https://github.com/fusesource/jansi/blob/master/jansi/src/main/java/org/fusesource/jansi/AnsiRenderer.java#L130-L178

The markup words are converted to upper case and compared to the enum.