Skip to content

Comment on ANSI Escape Codes

Comments

Take this gist with a grain of salt, many of the things listed there are NOT standardized by ansi, and some are specific to 16-bit real mode terminal emulators on the IBM PC or compatibles. I suspect this gist actually refers to the ANSI.SYS terminal implementation of MS-DOS.

If you want to have reliable and accurate information on how to control your terminal, consult the documentation on your terminal emulator or the ncurses database. The ncurses database is vast but does not include most of the exotic features of specific terminals.

[tl;dr] dont rely on secondary sources like this, please consult primary documentation instead

Specifically, relevant primary and reputable sources might include the ECMA-48 standard[1] (supposedly identical to the withdrawn ANSI one), the manuals for the various DEC VT-series terminals[2], the XTerm documentation already mentioned here[3], the detailed description of the VT100 state machine including how it fills the holes in the ECMA/ANSI spec[4], and maybe some compatibility tables[5]. There’s also a lot of folk wisdom beyond that, apparently, but nobody seems to have really gathered it in a usable form.

There is a Terminals WG over at the XDG[6], but I don’t know if they have produced anything useful yet.

[1]: https://www.ecma-international.org/publications-and-standard... [2]: https://vt100.net/ [3]: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html [4]: https://vt100.net/emu/dec_ansi_parser [5]: https://terminalguide.namepad.de/ [6]: https://gitlab.freedesktop.org/terminal-wg

(ETA: another commenter also recommends https://bjh21.me.uk/all-escapes/all-escapes.xhtml)

Exactly, and those links you gave are invaluable. I have an overlapping list at: https://www.neilvandyke.org/racket/charterm/#%28part._.Refer...

FWIW, in a low-level cross-terminal API, I made up some concepts that seemed helpful (and there are also a few comments scattered in there, such as hints about why key mapping is less consistent than one would've guessed): https://www.neilvandyke.org/racket/charterm/#%28part._.Termi...

You can also emulate a VT terminal using MAME. I’d say that’s the next best thing if you don’t have functioning metal.

Excellent idea. I didn't think of that when I was working on that library.

When discussing the possibility of implementing double width or height on VTE, someone did exactly that to finally settle how things behave. IIRC the same approach was used to find out what’s the “correct” way to do sixel graphics.

MS-DOSisms like the BIOS int 10h mode switch you mentioned in another comment are included, but so are things like (xterm) 256 color codes, TrueColor, and alternate screen switching, which IIRC were not a thing in ANSI.SYS. (The color thing I'm very sure because VGA text modes only supported 16 colors, the alternate screen mode is only a guess, it's very popular in unixy terminal emulators, but seems mostly useless for DOS.)

I'm pretty sure these lean towards the VT series of DEC terminals when not standard, not the DOS terminal.

See Section "Set Mode", these are the real mode BIOS mode sets for interrupt 10h, subfunction AH=0[1].

The keyboard remapping function is also specific to ANSI.SYS[2].

[1] http://www.ctyme.com/intr/rb-0069.htm

[2] https://en.wikipedia.org/wiki/ANSI.SYS#Keyboard_remapping

These escape sequences were known as ANSI long before the invention of ANSI.SYS. I suspect the standardization may be for the syntax and not the specific commands.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.