utf-8character-encodingcodepagesansi-escapeterminal-color

How do I convert DOS ANSI (CP 437) files to Unix ANSI with Unicode?


ANSI files from http://blocktronics.org/ seem to be using another ANSI encoding than the one supported in my VT100 terminal emulator.

If I view those files with tetraview, they look decent. But if I view them with less -r the block characters aren't working. If I use iconv -f 437 -t utf-8 | less -r, the block characters work, but the alignment of characters is still messed up. It works in tetraview, so there must be some kind of conversion going on.

I wrote a script to scrape the screen content of tetraview running in tmux, but it's a hack, and I'd like to do the conversion that tetraview does myself.


Solution

  • There are two issues involved:

    In dman-warrior.ANS there are two types of escape sequences used. The first one is used only once and is the first thing in the file. It is ESC[0m and it resets all graphics mode attributes. The second type is ESC[<value>C (e.g. ESC[24C) and it moves the cursor <value> characters forward (to the right). If the cursor cannot go any further, it stops. You can test it in your terminal using this shell command:

    printf '\x1b[10000CXYZ\n'
    

    It should look like this:

    |$ printf '\x1b[10000CXYZ\n'              |
    |                                        X|
    |YZ                                       |
    |$                                        |
    

    The image file has only a few lines (delimited by CRLF). Each is wrapped to the terminal width (80 columns), thus producing several screen lines.

    The image is OK up to the first screen line starting with ESC[<value>C escape sequence in the middle of a file line.

    The new screen line is missing the empty space which should have been skipped by the escape sequence.

    Possible solutions