11 ms·
ANSI escape codes (2019)
- tda 6y agoAfter reading this, I can confirm the title checks out
- labster 6y agoYes, this article is jam packed with good information that I'm sure is useful to some people, but I just run fish_config.
- watersb 6y agoI was playing with vttest today. Odd terminal emulator features. Vttest: https://invisible-island.net/vttest/ https://invisible-island.net/vttest/
- rbanffy 6y agoApple's Terminal.app is one of the very few that can pass all tests. Sadly, it doesn't do SGR 53 overlines. If anyone at Apple is listening, plese, do it.
- watersb 6y agoI haven't tried the escape codes for terminal window movement recently, but I used to use them for window tiling. Terminal.app used them just fine.
- mattowen_uk 6y agoI've (edited and) compiled VTTEST to run under Windows. The latest iteration of the Command Prompt does surprisingly well in the tests. Of course the new Windows Terminal does well too.
- tyingq 6y agoYou can also download the "vt100 torture test" file and "cat" it. http://www.inwap.com/pdp10/vt100test.txt http://www.inwap.com/pdp10/vt100test.txt
- curlypaul924 6y agoI really like vttest. I used to use it when I was still working on Console Telnet for Win32 (https://github.com/cout/consoletelnet https://github.com/cout/consoletelnet). It revealed a lot of bugs in how escape sequences were handled that I might never have noticed since they were obscure (yet important) corner cases.
- kyberias 6y agoSeems 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).
- iforgotpassword 6y agoEh, depends on context, for bash scripts that might be just fine. You need to have some styling information go along with it anyways, so instead of having some dedicated markup language and then having an output library that converts that to whatever your output uses, you could just declare those ansi escape codes your "markup language" and should you ever need to output it to something else, say a web page, I'm sure there's code around that does the conversion. But I guess to make it more readable you might want to put those commonly used sequences into some variables so you can do echo "${esc_red}ERROR${esc_reset}: All messed up"
- db48x 6y agoAt least call tput or something so that your script doesn't do anything wacky just because you SSH'd in this time instead of using your customary terminal.
- klodolph 6y agoFor advanced features, sure. But basic colors are nearly universal.
- db48x 6y agoUntil someone runs it in eshell, which is a shell but not a terminal emulator and you have to configure an override just for that special program so that it isn't dumping unreadable garbage into the buffer.
- klodolph 6y agoHonestly, since eshell is the only example I can think of, I’d say that it’s more than fair to consider this a flaw in eshell.
- 112233 6y agorecommended reading: - vt100.net - xterm control sequences - ECMA-48 Note that CSI is actually part of C1 set, code 0x9B, (sent bytes depend on used encding). Be avare that it is completely valid to have control characters such as carriage return in the middle of control sequence.
- kps 6y agoECMA-48 (equivalent to ANSI X3.64 and ISO 6429) is free: https://www.ecma-international.org/publications-and-standards/standards/ecma-48/ https://www.ecma-international.org/publications-and-standard... Some terminal emulated developers clearly didn't read it, though.
- 112233 6y agoIt is a good resource. To be fair to the emulator writers, though, it does in places read like a fantasy standard (e.g. JFY - what hardware has that?)
- rootw0rm 6y agoBack 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. 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.
- AnonHP 6y agoMods: This needs a 2019 in the title (not that escape sequences have been changing rapidly in the recent times :) ) This article was a nice and concise introduction. I wish it had linked to some canonical sources of more comprehensive information though. Also, the link to the Anki flash cards doesn’t work now.
- albertzeyer 6y agoThere is much more, though. See here for an overview: https://github.com/albertz/wiki/blob/master/terminal-escape-codes.md https://github.com/albertz/wiki/blob/master/terminal-escape-... There are a couple of non-standard extensions, e.g. by iTerm: https://iterm2.com/documentation-escape-codes.html https://iterm2.com/documentation-escape-codes.html https://iterm2.com/documentation-images.html https://iterm2.com/documentation-images.html Some of them are pretty complicated to standardize. E.g. see this discussion on simple image support: https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/12 https://gitlab.freedesktop.org/terminal-wg/specifications/-/...
- joveian 6y agoI've been learning kitty the past few days. It also has several extensions (image mode, more complete keyboard handling, and a few others): https://sw.kovidgoyal.net/kitty/protocol-extensions.html https://sw.kovidgoyal.net/kitty/protocol-extensions.html Here is an overview of image modes: https://github.com/kovidgoyal/kitty/issues/33 https://github.com/kovidgoyal/kitty/issues/33 The terminal hyperlink thing seems quite useful. Kitty has some magic where if you click a hyperlink over a direct ssh connection it shows you a menu that has some options like download or download/open in editor/reupload when done. I haven't checked the details yet how it determines that you are in an ssh session.
- billpg 6y agoBlatant plug: That time I accidentally discovered my text terminal had a graphics mode. https://hackensplat.com/falco-t310-unleashed/ https://hackensplat.com/falco-t310-unleashed/
- rbanffy 6y agoLooks like the Tektronix mode some terminals had back then. https://github.com/rbanffy/fun_with_tektronix https://github.com/rbanffy/fun_with_tektronix
- tyingq 6y agoXterm still has Tektronix emulation. You should see "Show Tek Window" in the middle button menu.
- rbanffy 6y agoI just suggested it be added to VTE. Not sure the maintainers will like it. https://gitlab.gnome.org/GNOME/vte/-/issues/328 https://gitlab.gnome.org/GNOME/vte/-/issues/328
- tyingq 6y agoHah! I saw your note about programmatically entering Tek mode from xterm. You can do: echo -e "\e[?38h" from the vt100 window to launch the Tek window. Then echo -e "\e\x03" from the Tek window to switch input back to the vt100 window. Edit: Hrm. I did try it out before posting, and it worked. So not sure why it isn't working for you.
- rbanffy 6y agoFunny. I tried that while writing it, but it didn't work. These are the character sequences the VT-300 series uses.
- rbanffy 6y agoFor proper status lines, use SGR 53 for overlines. https://twitter.com/0xDEADBEEFCAFE/status/1256285362260934656 https://twitter.com/0xDEADBEEFCAFE/status/125628536226093465...
- faeyanpiraat 6y agoYou could color code chat messages and your name in Call of Duty 2 in the following way: ^1Red Everything after the "^1" were red. 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)
- rangibaby 6y agoColoring names with escape codes sounds like a John Carmack feature
- mattowen_uk 6y agoYup, Quake had something similar that allowed players to have fancy looking names in multiplayer games.
- meddlepal 6y agoIndeed, this was one of those undocumented but everyone sort of knew features in Quake-engine based games. Everyone just learned it through asking usually in the multiplayer chat.
- ju-st 6y agoCoD 2 used a modified Quake engine :) https://en.wikipedia.org/wiki/IW_(game_engine) https://en.wikipedia.org/wiki/IW_(game_engine)
- Narishma 6y agoMakes sense since Call of Duty traces it's engine lineage to Quake 3.
- eqvinox 6y agoOn a Linux box, you can also just do man console_codes which is significantly more extensive than the posted link
- cesarb 6y agoFor those who aren't on a Linux box at the moment, the online version of that man page is at https://man7.org/linux/man-pages/man4/console_codes.4.html https://man7.org/linux/man-pages/man4/console_codes.4.html
- Anthony-G 6y agoThanks for that. I’ve mentally added it to my list of useful man pages not related to a specific command (`man ascii` and `man hier`). I see the `manpages` package provides a few more manuals describing computing concepts in Section 7, e.g., `cgroups`, `charsets`.
- blueflow 6y agoThe article nor the comment section mention curses or the terminfo database, which makes me sad. Wanna read something about terminals and terminal control sequences? https://invisible-island.net/ncurses/terminfo.src.html https://invisible-island.net/ncurses/terminfo.src.html Disclaimer: i use a DEC VT520
- account42 6y agoBecause just like the code page in locales, you should not need to care about terminfo if all you want to do is show some basic color. In $current_year it is OK to assume that the current terminal (if stdout/stderr is a TTY) can at least parse color escape sequences - if yours doesn't then create your own wrapper that strips them. Generally the way git does it should be considered best practice. If - Output is a TTY - The NO_COLOR environment variable is not defined - The TERM environment variable is not set to "dumb" then enable colors by default.
- blueflow 6y agoThe git approach here is not "not caring about terminfo", but delegating the caring (of the difficult parts at least) to another program, namely the pager. The default pager `less` depends on the information in TERM and the terminfo database, and it has to, since functions like toggling to the alternate screen buffer are not standardized per ansi.
- account42 6y agogit works without a pager too. I agree that you will need something like terminfo if you writing a TUI like a pager, but for most CLI programs you only need simple color output and maybe cursor movement on and erasing of the current line and for that terminfo is an unnecessary dependency.
- blueflow 6y agoLine editing is tricky enough that i would recommend a thing like the readline library, which in turn uses ncurses. Just for colored output alone, i agree.
- account42 6y ago> 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. 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.
- deleted 6y ago[deleted]
- dejj 6y ago> colours are ordered by usefulness And then I finally realized they’re RGB vectors and additive: 000: black 001: red 010: green 011: yellow 100: blue 101: magenta 110: cyan 111: white
- tasuki 6y agoOh wow, this is amazing!
- masukomi 6y agoTo the 4 of you who actually care enough about this information to write something with it I offer you the following blatant self promotion: oho https://github.com/masukomi/oho https://github.com/masukomi/oho is the best ASNI->HTML converter out there. 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).
- epistemex 6y ago> The majority of these escape codes start with \x1b[ 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 . Unfortunately, there exist a couple of (8-bit) terminals that don't support this version.
- rramadass 6y agoThis 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. Please don't judge me :-)
- mixmastamyk 6y agoI judge it awesome.
- rramadass 6y agoThanks, i learnt a lot from that experience (my first job, sole developer, figure out a solution and get things done etc.). It was on those old monochrome visual display terminals and instead of using system specific languages/toolkits i hit upon this solution and it worked out.
- aidenn0 6y agoiso-8859-1 (and by extension UTF-8) specify a single-character CSI. Does anyone know if any terminals will accept this?
- drummer 6y agoThis is very nicely explained in terms of calling functions. It all makes much more sense now.
- junon 6y agoI'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. 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. 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. 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.