The article nor the comment section mention curses or the terminfo database, which makes me sad.<p>Wanna read something about terminals and terminal control sequences? <a href="https://invisible-island.net/ncurses/terminfo.src.html" rel="nofollow">https://invisible-island.net/ncurses/terminfo.src.html</a><p>Disclaimer: i use a DEC VT520
Back in the 90s I played a MUD called Ancient Anguish. It's the type of MUD where inventory is dropped on logout. I learned they didn't filter for control sequences, and so I would rewrite the text on screen to do all sorts of nefarious things, like make people think they were ambushed and almost dead (thus possibly trying to quit to save EXP loss). I could also forge tells/yells to make them look like they came from someone else. It was funny to me at the time, lol.<p>edit: for fun i just checked out it's current status and it's still around, awesome. and rule #4 is now don't abuse control codes. hahaha, sorry guys. AFAIK they started filtering them soon after me and a cohort caused some chaos.
There is much more, though.<p>See here for an overview:<p><a href="https://github.com/albertz/wiki/blob/master/terminal-escape-codes.md" rel="nofollow">https://github.com/albertz/wiki/blob/master/terminal-escape-...</a><p>There are a couple of non-standard extensions, e.g. by iTerm:<p><a href="https://iterm2.com/documentation-escape-codes.html" rel="nofollow">https://iterm2.com/documentation-escape-codes.html</a> <a href="https://iterm2.com/documentation-images.html" rel="nofollow">https://iterm2.com/documentation-images.html</a><p>Some of them are pretty complicated to standardize. E.g. see this discussion on simple image support:<p><a href="https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/12" rel="nofollow">https://gitlab.freedesktop.org/terminal-wg/specifications/-/...</a>
To the 4 of you who actually care enough about this information to write something with it I offer you the following blatant self promotion:<p>oho <a href="https://github.com/masukomi/oho" rel="nofollow">https://github.com/masukomi/oho</a>
is the best ASNI->HTML converter out there.<p>useful if you want to take your colorful terminal output and share it on a web page, OR if you're really geeky you can write CLI tools with colored output, to summarize data then convert it to HTML, then to PDF and share it with your coworkers. (Chrome's command line interface is the best HTML to PDF converter I've found).
> The majority of these escape codes start with \x1b[<p>This is actually the 7-bit version for CSI. A less known variation is the 8-bit CSI which is simply \x9b and is the same as \x1b[ combined. So, for example \x9b33m does the same as \x1b[33m .<p>Unfortunately, there exist a couple of (8-bit) terminals that don't support this version.
I was playing with vttest today. Odd terminal emulator features.<p>Vttest: <a href="https://invisible-island.net/vttest/" rel="nofollow">https://invisible-island.net/vttest/</a>
Blatant plug: That time I accidentally discovered my text terminal had a graphics mode.<p><a href="https://hackensplat.com/falco-t310-unleashed/" rel="nofollow">https://hackensplat.com/falco-t310-unleashed/</a>
> colours are ordered by usefulness<p>And then I finally realized they’re RGB vectors and additive:<p>000: black<p>001: red<p>010: green<p>011: yellow<p>100: blue<p>101: magenta<p>110: cyan<p>111: white
For proper status lines, use SGR 53 for overlines.<p><a href="https://twitter.com/0xDEADBEEFCAFE/status/1256285362260934656" rel="nofollow">https://twitter.com/0xDEADBEEFCAFE/status/125628536226093465...</a>
You could color code chat messages and your name in Call of Duty 2 in the following way:<p>^1Red<p>Everything after the "^1" were red.<p>The game removed these color codes when it showed your name, but you could do ^^11Red to bypass that (it only removed color codes for one pass)
Seems to me it's bad practice to combine the text you want to show with the formatting (escape codes) in string literals. Everything is then immediately dependent on specific type of UI technology (terminal).
> 0 and 7 are less useful for text because one or the other will generally look nearly-unreadable depending on whether the user has a light or a dark background.<p>This really annoys me about the bright themes used by default in some distros - if you make the default background white instead of black then please also swap the "white" and "black" foreground colors. And make sure all the other ones are readable on the default background for that matter.
I'm a maintainer of chalk. I'm not the first to mention this, but this article is only really parroting the information found on the Wikipedia article for escape sequences, which in turn only really covers xterm-256color terminals.<p>To be quite honest, I feel as though terminal technology is the most antiquated thing still in wide use today. It's slow, there are so many competing standards and none of them are really that well standardized, and the libraries needed to be truly compatible (terminfo in particular, for which I've written several full parsers and boy what a mess that is) are clunky, outdated and also very slow.<p>This is a hard problem to solve, however. There are more CSI sequences than just \x1b for example, though that is by far the most common these days. Not treating output as text streams would be an interesting start but that would require rewriting pretty much all software ever to exist.<p>Meh. I've spent too much time working with escape sequences and thinking about this problem. I am young, but I'll probably die before TTYs do.
Mods: This needs a 2019 in the title (not that escape sequences have been changing rapidly in the recent times :) )<p>This article was a nice and concise introduction. I wish it had linked to some canonical sources of more comprehensive information though.<p>Also, the link to the Anki flash cards doesn’t work now.
recommended reading:<p><pre><code> - vt100.net
- xterm control sequences
- ECMA-48
</code></pre>
Note that CSI is actually part of C1 set, code 0x9B, (sent bytes depend on used encding).<p>Be avare that it is completely valid to have control characters such as carriage return in the middle of control sequence.
This brings back memories. In the beginning of my career (early 90's) i implemented an entire UI for a Personnel Information System in COBOL on a Mainframe (CDC Cyber 180/840A) using ANSI escape sequences.<p>Please don't judge me :-)