theZiz / aha

Ansi HTML Adapter
Other
907 stars 88 forks source link

Using filter: instead of 2 sets of colors is broken (v0.5.1) #74

Open daniel-pfeiffer opened 4 years ago

daniel-pfeiffer commented 4 years ago

Your filter can't distinguish between foreground and background colors. So you can't render bright fg with normal bg or vice-versa.

With my Perl One Liner pl I give an example for generating a table of all combinations and the numbers that create them. If you run that command snippet in a terminal, you get this output ansi-table.txt (which you can cat if you don't want to download & run pl). But if you hover it with your mouse, you see what aha -n makes of it: In the "fg;" column you still see the contrast between color-pairs. But in all following columns, with a bg-color added, they become the same.

On a lesser note, you create a rather redundant amount of <span> and style. E.g. in the above example, the fg stays the same for the rest of the line. So you could set it once in an outer <span>.

Similarly this alternates between red & green several times. You can see that I have adapted your output. I put the 1st color into an outer <span> and nest the other color, saving quite a bit of html.

Thirdly, in this last example you also see how replacing the styles with my predefined classes makes it even more compact and readable. Here I didn't need it, but html would allow, e.g. class='red bright-green-bg'.

theZiz commented 3 years ago

Thanks for your table, it made it easy to look into possible solutions. For now unfortunately I can just say: With the CSS I know (not a lot) I can't solve this problem with the filter approach. I would need to define 16 instead of 8 colors for foreground and background and that would break a lot. Furthermore I would not be able to use this approach in the 8 and 24 bit mode. However I am stating in code that the behavior is not correct, maybe I should also state this in the man-page.