Linux console_codes man page, section 4<p><a href="https://man7.org/linux/man-pages/man4/console_codes.4.html" rel="nofollow">https://man7.org/linux/man-pages/man4/console_codes.4.html</a>
My first paid programming job was making a client for a remote monitoring solution for the water industry. I must have been 14 or 15. One of my father's acquaintances knew I had been messing around with programming, and he needed a shiny Windows 95 application for his customers.<p>It would dial the plant via modem, and I remember being given a list of "escape codes" that determined how the stream of bytes should be rendered on the screen. My program parsed (some of) these codes and displayed the text accordingly, I specifically remember implementing the "move cursor" and "reverse mode" codes...<p>Not until years after did I realise I had basically built a shitty terminal emulator using Visual Basic text fields.
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.<p>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.<p>[tl;dr] dont rely on secondary sources like this, please consult primary documentation instead
Playing around with BBSes as a teen, I'm super familiar with ANSI codes. I remember being fascinated by how they worked after opening up a .ANS file to see their contents.<p>One of my earliest programming projects was creating my own diary app which used ANSI codes to let you format the text. It also kept track of your cursor movements and encoded them so that you could do neat things like write text anywhere on the screen or overwrite existing text.
For those interested in learning more about terminal emulators and character graphics, checkout Nick Black's book <i>Hacking the Planet (with Notcurses): A Guide to TUIs and Character Graphics</i>[1].<p>While the overall focus of the book is on programming with Notcurses[2], the author shares a wealth of related info and history throughout its pages.<p>[1] <a href="https://nick-black.com/htp-notcurses.pdf" rel="nofollow">https://nick-black.com/htp-notcurses.pdf</a><p>[2] <a href="https://github.com/dankamongmen/notcurses#readme" rel="nofollow">https://github.com/dankamongmen/notcurses#readme</a>
I generally use xterm's ctlseqs.ms as a reference - <a href="https://www.invisible-island.net/xterm/ctlseqs/ctlseqs.html" rel="nofollow">https://www.invisible-island.net/xterm/ctlseqs/ctlseqs.html</a><p>There's also Ben Harris's concordance of escape sequences <a href="https://bjh21.me.uk/all-escapes/all-escapes.xhtml" rel="nofollow">https://bjh21.me.uk/all-escapes/all-escapes.xhtml</a> (Ben is a member of the PuTTY team)
I've always liked these. It's fun to use them directly to jazz up quick CLI scripts without bothering with dependencies etc.<p>A few months ago I put together a kind of interactive cheatsheet for working with them quickly: <a href="http://ansi-escape-artist.surge.sh/" rel="nofollow">http://ansi-escape-artist.surge.sh/</a>
Related: See also this page documenting escape sequences supported by xterm:<p><a href="https://invisible-island.net/xterm/ctlseqs/ctlseqs.html" rel="nofollow">https://invisible-island.net/xterm/ctlseqs/ctlseqs.html</a><p>EDIT: This is actually linked at the bottom of the article.
If someone wants to do this in Python, I made a lib for it: pip3 install ansi-escapes<p>It’s a port of sindresorhus’s ansi-escapes library. I find it way more convenient than looking up codes.<p><a href="https://github.com/shawwn/ansi-escapes-python" rel="nofollow">https://github.com/shawwn/ansi-escapes-python</a><p>It has some basic iTerm2 support too, so you can print out annotations in the console. Think of it like sticky notes.<p>See also ansi-styles, the lib that Chalk is based on. (Colors! You like colors? Are you a curmudgeony salt like me that refuses to use Rich for some reason? Use that.)<p>As with ansi-escapes, you can just pip install ansi-styles.<p><a href="https://github.com/shawwn/ansi-styles-python" rel="nofollow">https://github.com/shawwn/ansi-styles-python</a>
The 256 color palette was the most useful bit for me: not every terminal supports true color, and many terminals allow users to select color themes for the first 16 colors (e.g. "xterm -reverse"). So the upper 240 of the 256 color palette were the most reliable colors.
Something i do way to much is `watch telnet <static-ip> 22` because it will print a Terminal bell and then i know a embedded device with a short ssh/dhcp window is up.<p>This is for dropbear ssh have not tested it on openssh, yet.
Related from a few months back:<p>ANSI Escape Artist – webapp for generating terminal escape codes<p><a href="https://news.ycombinator.com/item?id=26609452" rel="nofollow">https://news.ycombinator.com/item?id=26609452</a>
Back in the day, during the dorm wars, we would all have syslogd writing to terms to keep track on our nefarious neighbors in realtime. Echoing ANSI escape codes strategically was a good way to erase those tracks.
XTERM docs cover most common terminal codes, including DEC.<p><a href="https://www.xfree86.org/current/ctlseqs.html" rel="nofollow">https://www.xfree86.org/current/ctlseqs.html</a>
this was posted why? considering comments here saying it's not reliable information and the number of comments on the gist itself from when it was initially posted months ago saying it needed forks to fix problems and clarify......