5 ms·
I was working on terminal code recently and had a hell of a time finding anything approaching an authoritative spec or reference docs. The best I found was this
by ntoskrnl 4y ago
I was working on terminal code recently and had a hell of a time finding anything approaching an authoritative spec or reference docs. The best I found was this: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
I'd recommend that over the wikipedia link in the article, since wikipedia seems to be missing some things.
- hnlmorg 4y agoYou couldn't find an authoritative spec because there isn't a universal standard. Lots of terminal emulators differ in different ways.
- metroholografix 4y agohttps://www.ecma-international.org/publications-and-standards/standards/ecma-48/ https://www.ecma-international.org/publications-and-standard...
- hnlmorg 4y agoNot all terminal emulators follow that completely. Most only include a subset and some include their own proprietary escape codes too (like iTerm and Terminology have codes for rendering images. tmux has an escape code for changing the session title). Then there's other specs not included in that doc even outside of the aforementioned proprietary codes. Like Sixel, conventions on non-POSIX terminals, etc. Also lets not forget the popular-but-not-standardised conventions like the hyperlink escape codes (which I personally think shouldn't exist in the first place....but that's another topic entirely). Even standard ASCII characters can differ from one platform to another. Backspace being a classic example: ISO 646 describe it as ^H whereas ASCII 1963 has it as ^? This mess of differing compatibilities is exactly why termcap is a thing. Being an author of a readline library, this is a topic quite close to my heart :)
- easrng 4y agohTerm and also IIRC kitty have image-rendering escape sequences too.
- hnlmorg 4y agoNot familiar with hTerm. Got a link to the project? Would be good to add support for that to my image rendering library: https://github.com/lmorg/murex/blob/c77b893a58a682735ad7502c1c8464a629f90515/config/defaults/profile_all.mx#L819 https://github.com/lmorg/murex/blob/c77b893a58a682735ad7502c...
- easrng 4y agoUpstream: https://chromium.googlesource.com/apps/libapps/+/HEAD/hterm https://chromium.googlesource.com/apps/libapps/+/HEAD/hterm Fork used by iSH: https://github.com/ish-app/libapps/tree/master/hterm https://github.com/ish-app/libapps/tree/master/hterm I looked at the docs (https://github.com/ish-app/libapps/blob/master/hterm/doc/ControlSequences.md#osc1337-iterm2-sequences-osc-1337 https://github.com/ish-app/libapps/blob/master/hterm/doc/Con...) and it appears to use the same protocol as iTerm. Here's an implementation: https://github.com/ish-app/libapps/blob/master/hterm/etc/hterm-show-file.sh https://github.com/ish-app/libapps/blob/master/hterm/etc/hte...
- hnlmorg 4y agoThank you
- Annatar 4y ago
- hnlmorg 4y ago> > ^? is the code for the [DEL] or [DELETE] key on physical terminals, that's why it's an ASCII standard. > When the PC bucket keyboards came, IBM in their usual idiocy simply put the [BACKSPACE] key where the [DELETE] key normally is, and what's worse, they made it not only move back one space but delete too. Thus came the sadness of everlasting redefining of deletion to be ^H when using a PC bucket keyboard. Indeed. And to confuse things even further, the [DEL] key on IBM keyboards sends the following ANSI escape sequence: [27 91 51 126] So we now have 3 different standards for deleting characters (and that's before you start looking at the escape sequences for deleting rows, nor supporting vi and/or emacs/readline bindings).
- duskwuff 4y agoThe relevant ECMA standards are full of crazy bullshit that, to the best of my knowledge, nobody has ever implemented in any hardware or software terminal, like control sequences to make lines of text run vertically (SPD), or to fully justify text (JFY), or to use a Fraktur font (SGR 20). They're also incomplete -- they go into very little detail explaining what various control sequences should do, especially in exceptional circumstances, and they don't discuss Unicode at all (as they haven't been updated since the early 1990s).
- jart 4y agoHi I'm one of the people cited by the article. Fraktur is awesome. I implemented it in my terminal. https://github.com/jart/cosmopolitan/blob/c6bbca55e9f977e386f619d08b343268f7ca6544/tool/build/lib/pty.c#L266 https://github.com/jart/cosmopolitan/blob/c6bbca55e9f977e386... Now that unicode makes it easy, there's no excuse not to have fraktur!
- duskwuff 4y agoWow, okay, guess I can cross that one off my list of "ECMA-48 features nobody implements". There's still plenty left on that list, though -- including at least one escape sequence I'm fairly certain was included as a joke (SPQR).
- deleted 4y ago[deleted]
- chris37879 4y agoI can think of a use case or 2. Thermal printers (for those wanting old timey unix line printing interfaces) or e-ink displays in console mode.
- duskwuff 4y agoThe joke in SPQR is the name -- https://en.wikipedia.org/wiki/SPQR https://en.wikipedia.org/wiki/SPQR The functionality is legitimate (although I doubt anyone uses it), but the name is pure silliness -- much like the PowerPC "eieio" instruction.
- Beltalowda 4y agoThat document is very good, but it mostly describes control sequences as interpreted by xterm, with some notes for other terminal emulators, too. Some of the more advances ones will have different sequences in other terminals (for example for the mouse). Most basic ones (i.e. ANSI stuff) works in pretty much all terminal emulators of the last few decades though. Either way, I wouldn't use it as an authoritative source uncritically.
- samatman 4y agoI don't know about authoritative but this is at least iconic if not definitive http://rtfm.etla.org/xterm/ctlseq.html http://rtfm.etla.org/xterm/ctlseq.html
- watersb 4y agoThis is a great table of control sequences, but the second author cited as maintainer from 1996 to 1999, Thomas Dickey, currently maintains a list at his invisible-island.net site. https://invisible-island.net/xterm/ctlseqs/ctlseqs.html https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
- Annatar 4y agoThomas Dickey is also the maintainer of the ncurses library.
- kevin_thibedeau 4y agoI'd add https://vt100.net/docs/vt100-ug/chapter3.html https://vt100.net/docs/vt100-ug/chapter3.html as it has details invisible-island doesn't go over as good as good a resource as it is. The other chapters are informative too. The VT510 manual is also useful since it was designed to be used with a PC keyboard so it covers newer escape codes that aren't on older DEC terminals https://vt100.net/docs/vt510-rm/chapter8 https://vt100.net/docs/vt510-rm/chapter8
- jart 4y agoHere's the reference I use for VT100 ANSI control sequences: https://github.com/jart/cosmopolitan/blob/c6bbca55e9f977e386f619d08b343268f7ca6544/tool/build/lib/pty.c#L42 https://github.com/jart/cosmopolitan/blob/c6bbca55e9f977e386... I created this reference because there wasn't one available before that could be easily copy/pasted into GNU C or Python string literals.