theZiz / aha

Ansi HTML Adapter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for 256 color and even True Color?

ryanerwin opened this issue Β· comments

Hello,

Curious if you might consider updating aha to include 256 color support, and ideally even true color support? For example, I have several scripts using Term::ExtendedColor to generate console colors...

Best,

Ryan

Seems easy to add https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
I will try to add this, when I find time :) You could help me a lot with an example file, which produces theses terminal colors with

cat file.txt

Best
Alex

Here you go. You can cat these files back to your terminal and you should see:
image

image

consolecolor.zip

Works for me, thanks! However Konsole shows a lot of \ in front of System colors. xterm works better. Seems to me like a escape code Konsole even doesn't understand. XD

Anyway, I will give it a try with these files ;)

FYI
Because of filtered access at work I use Wetty (a web terminal)
Both files shows very well in it.

once again I look into doing something fun and theZiz has been there already! :)

I do find myself not getting proper color output. These guys seem to do it right.

https://pypi.python.org/pypi/ansi2html/1.0.7

https://files.catbox.moe/h8o8v8.png

Can share source .ans files if you want.

How about adding support for the now ubiquitous "bright"/"light"/"high intensity" colors (escape codes 90–97 and 100–107)?

I think I overcame some of the issues... at least what I created works for me and lets me continue on a project that requires having color coded log file outpus which aha facilitates. See Issue #52.

I added support for 256 colors. The first example is working now, next step 24 bit 😎

@hftf I added support for bright intensity colors with 8 bit. I could use the same method for 90-97 and 100-107. Could you provide an example file for testing?

Hopefully added full support for 8 and 24 bit colors. Please test! πŸ˜ƒ

@theZiz Thanks. You may try out this example file: test2.txt

@hftf Awesome, thanks!

@hftf Okay, I gave it a try. While doing this I noticed that I had two errors in my sooner commits. First of all the 8 and 24 bit colours did not work with stylesheets (they do now) and secondly the highlighted is always done for BOTH, the foreground and background colour. I did not fix this as it would make the solution way more complex. Right now I am just applying a filter which decreases the contrast and increases the saturation, which makes all colour look more highlighted. However I cannot apply this filter only to the foreground or background colour. So I would need to define 16 new colours if I would like to implement it per colour type... πŸ™„

At least your example is working and I guess in the real world, it will look fine, too. If there is really a real world application which looks awful with this solution, I may think about a more correct implementation. πŸ˜›

While the values are not standardized, it seems less complex to me to implement them by just defining 16 new colors: See e.g. https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit for a table of existing values you can use.

I have two reasons why I decided for the way I went:

  1. I am more downwards compatible. My version is not defining new colors or needs the developer using his or her own stylesheet to add new colors. In the worst case, the new highlighted class is not known and just the not highlighted color used. Adding the highlighted class however is done quite fast and the developer does not have to decide which highlighted colors match best for his or her own stylesheet
  2. I would like to stay with color names if possible, so I would not just copy the one from the wiki but try to find fitting predefined colous – what I am too lazy to do right now
  3. (I know, I spoke about two reasons... 😜 ) The solution I went for is finished and I would like to keep it this way until someone shows me a real world example, where it is not working in that case, I will add a more proper way at least optionally. πŸ˜‰