ANSI Art – Understanding Encoding Types

ansiansi-termlinux

I've found this website; it has zip files (links on the main page) with all the artworks. Some of them have an .ans extension and they look like ANSI escape codes used on Linux/Unix, but when I open one of them using cat in the XFce terminal it produces garbage (but in color). They don't look like the image gallery.

The first line of the main artwork from the link looks like this (copied from Emacs):

[0;1m[30mthere is no substitute [0;33mÜܲ[1;43m°±²²[40mÛ[43mÛ²±[0;33mÝ ßÜ[1;43m²²²[40mÛÛ²[40m[K

The file type is DOS, but they can be just created on Windows.

When searching for ANSI art I also found this website that has zip files containing only files with an .ans extension and they also don't render properly on Linux (gallery on page 2).

My questions are:

  • what type of encoding is this, for what computer?
  • do I need a special viewer to see it on Linux terminal?
  • do you know if this type of artwork was created for Linux/Unix terminals? I've only found ASCII art.
  • is it possible to convert it to be viewed on Linux terminals?

Best Answer

These are ANSI escape codes, but you’re running into three issues:

  • the character encoding, as you suspect — most of these files are in CP437, so you need to convert them:

    iconv -f CP437
    

    (use the -t option if you need to specify the target encoding; by default iconv will match the current locale’s character encoding);

  • the colour scheme — these files typically assume something similar to the CGA/EGA/VGA colour scheme used on PCs; terminal emulators generally allow you to choose a colour scheme (or redefine colours manually), for example GNOME Terminal has a “Linux console” built-in scheme which works well for ANSI art;

  • the screen size — most ANSI art assumes a screen width of 80 columns and expects to wrap around there.

Once you fix all that, you don’t need a special viewer; here’s a screenshot showing the output of aa-neurodancer.ans in GNOME Terminal, after converting the character encoding:

ANSI art showing a human head with spectacles

The bottom of the screenshot shows the file’s SAUCE record:

  • SAUCE version 00
  • title: “Neurodancer”
  • author: “Antsy Atheist”
  • date: August 13, 2018
  • file size: 0x1A65, 6757 bytes
  • data type: character
  • file type: ANSi
  • width: 80
  • height: 23
  • font: IBM VGA

(Ansilove can decode SAUCE records for you.)

Related Question