Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doesn't support spaces and multiple SGR attribute. #9

Open
DrYak opened this issue Feb 4, 2021 · 1 comment
Open

doesn't support spaces and multiple SGR attribute. #9

DrYak opened this issue Feb 4, 2021 · 1 comment

Comments

@DrYak
Copy link

DrYak commented Feb 4, 2021

The current version struggles with this terminal output:

It should look like this:
terminal.svg.gz

but there are two issues preventing this output:

multiple SGR attributes

Select Graphic Rendition (SGR) parameters do support "several attributes {...} in the same sequence, separated by semicolons".
e.g.: \x[32;1m for bold+green. But ansi-to-svg fails to recognize them.

workaround for multi-SGR

split them into multiple individual ANSI SGR escape sequence:

sed -r 's@(\x1b\[)([[:digit:]]+);([[:digit:]]+)(m)@\1\3\4\1\2\4@g' terminal.txt > sgr-fixed.txt

spaces

There are a few issues with the way spaces are handled:

  1. string of spaces between text are pasted verbatim in the output SVG. The trouble is that SVG, just like HTML (And markdown) doesn display multiple space but considers them as a single separator and and displays one blank them. Thus:
           72_UK                      78_UK                      92_UK                      93_UK                      76_SA                      77_EU                     
    
    gets renderered as: 72_UK 78_UK 92_UK 93_UK 76_SA 77_EU
  2. even if the SVG <text> boxes start at fixed X coordinates, the left-most text still has the leading space spaces left. Somewhat luckily the above bug cancels out this bug and thus it doesn't affect the output much (until one tries the workaround. then it need fixing).
    <text x="84.01" y="14.55">          72_UK
    
    should be:
    <text x="84.01" y="14.55">72_UK
    
    (but both render the same, until workaround is used).
  3. harmless cosmetic: there are useless spaces at the end of SVG </text> blocks:
    77_EU                     </text>
    
    could also be written
    77_EU</text>
    
    (but they are both synonymous and render the same).

workaround for space

One needs to:

  1. use non-breaking spaces (e.g.: \u00A0) in the SVG output for string of multiple space.
  2. remove leading spaces (because now the non-breaking spaces cause the text to shift around, even if the <text>block is already shifted using coordinates).
  3. (optionnally) remove trailing space at the end of a block.

sed command:

sed -r 's@ +(</text)@\1@g;s@> +([[:alnum:]])@>\1@g;s@  @\xC2\xA0\xC2\xA0@g;s@\xC2\xA0 @\xC2\xA0\xC2\xA0@g' terminal.svg > fixedspaces.svg
@ctrlcctrlv
Copy link

yeah this thing is broken as hell :\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants