The TTY Demystified (2008)
linusakesson.net
linusakesson.net
What I love is how they come up with different names for different signals that kill/suspend processes:
`SIGHUP`, `SIGINT`, `SIGQUIT`, `SIGABRT`, `SIGKILL`, `SIGTERM` and `SIGSTOP`!
7 different combinations of SIG and a verb that means "terminate/kill/stop/close/quit/suspend", and it's not that confusing (once you get your head around it). Must have been quite a challenge!
E.g., "HUP" means hangup, and indeed, that's what you get when your modem hangs up accidentally! When handled by an application, it often is treated appropriately (e.g., the handler might trigger an autosave before quitting).
"INT" means "interrupt", and usage follows that sense -- it more likely than others to be ignored/repurposed (e.g. to quit back to some application prompt rather than killing the application entirely).
"ABRT" means "abort", and is typically used as a last-ditch means of killing the program when an internal error is detected.
"KILL" is more draconian than any other; there is no recovery possible.
etc.
"There's an important difference here: Writing to a TTY which is stopped due to flow control, or due to lack of kernel buffer space, will block your process, whereas writing to a TTY from a background job will cause a SIGTTOU to suspend the entire process group. I don't know why the designers of UNIX had to go all the way to invent SIGTTOU and SIGTTIN instead of relying on blocking I/O, but my best guess is that the TTY driver, being in charge of job control, was designed to monitor and manipulate whole jobs; never the individual processes within them."
Can anyone provide any more insight about this?
IMHO I think this all needs to be replaced with something sane. VT100 is obsolete, and we can now spare a few more BPS for a better terminal layer. Wasn't so long ago that if you left capslock on, something (getty?) on the Linux console would assume your terminal was one of those olde-worlde 6-bit ones, and stop using lowercase letters...
It seems that we're in the process of replacing it with web tech, which may or may not meet your definition of "something sane"...
There are many web systems being developed as business front-ends today that would suck less were they menu and form-driven terminal apps with a couple of web screens for reports. (or a websockets arrangement where the terminal could render certain things to an associated browser when appropriate)
Our administrative and call centre staff continue to use the original character mode interface to interact with the data and do their daily work. The software works and we have no reason to redevelop it anyway, but seriously, you should see the speed with which experienced staff move around the system. Editors can input hundreds of events an hour and call centre staff are amazingly efficient - they can practically use the thing blindfold.
There's a lot to be said for consistent keyboard controls and a distraction free interface in the workplace. Line of business applications from the last couple of decades, mostly mouse driven, are often tragically inefficient.
Something that would be useful but which I don't think exists at the moment is a multiplexor. Like GNU/screen, but properly sandboxed. When the user logs in they get a menu program running on "tab 0". This program would spawn perspectives on new tabs.
Actually, maybe these things have features that I wouldn't know of being only a curses person. I'd be interested to know more if you wrote up a blog post. Email cratuki at the google mail server.
More elaborate libraries let you overlap the windows and would optimally redraw them when you moved the windows. They simply let you avoid having to roll your own text user interface starting from curses and building from there. Open source equivalents never approached the comprehensiveness or polish of these commercial libraries, though the open source ones are pretty good. Now that the commercial libraries appear to have dropped off the face of the earth, the open source ones seem to be all that is left. CDK [1] and NDK++ [2] on Unix and DFLAT [3] on DOS are examples of the open source libraries. I just felt the commercial libraries were interesting pieces of software history that should be preserved.
I personally feel that the kind of high-speed manual data entry optimization that these libraries facilitated is likely on its way out with advances in machine learning and the self-service customer culture of ecommerce. Certainly nothing prevents someone from using a standard web browser to present a user interface that responds entirely from keypresses, should the need for a highly optimized data entry-oriented Javascript library become necessary (something I've looked for but haven't found either for sale or open source). You would need to come up with a way to buffer up all the keypresses locally on the browser and ensure they all make it to the server, but it's doable.
If someone really had a burning desire to have some kind of in-house application presented through a character terminal interface via PuTTY in today's world, then they can still fall back to curses I suppose. Though I sometimes wonder if it would be faster to just write something in Emacs Lisp and autostart that when the user logs in.
[1] http://invisible-island.net/cdk/cdk.html
[2] http://ndk-xx.sourceforge.net/
[3] http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/deve...
If anyone is curious how to do that (useful if you want your terminal application to handle escape key presses for example), this is the basics of it:
tcgetattr(master_controlling_tty, &term_settings);
cfmakeraw(&term_settings); /* set raw mode */
term_settings.c_cc[VMIN] = 1; /* minimum of 1 character per read */
term_settings.c_cc[VTIME] = 1; /* 1 decisecond timeout for read */
tcsetattr(master_controlling_tty, TCSANOW, &term_settings); /* write changes back to the tty */
Then if a read on your tty only returns the escape character, you know it was the escape key and not arrow keys or whatever.. unless there is some decent lag.. ;)It's fairly simple to do, but certainly hackish.
There are a lot of complexities introduced by the need to handle situations we may never again encounter. The challenge is to make everything simpler, not only in lines of code, but in abstractions.
There is a program (called IIRC vt100) on Plan 9 that is used to talk to TTYs and serial ports, but it is rarely used, and it is the only part of Plan 9 that incorporates TTY-related concepts. Nor are signals a part of Plan 9, having been replaced by something called notes, which are conceptually different and simpler in concept and implementation.
I remember delving into the documentation of the stty command on Linux a few times in the 1990s. How I wish I could have those hours back (so I could do something more fun or more productive with them).
But everybody learns what they need to learn, even if it is setting the backspace/del keys to something visualy complient.
Knowing a tty and VT commands you can do some realy simple clever stuff, like find certain people logged in and there tty and cat append information to there screens and if they have terminals with extra sub lines you can sends a string that will memorise the screen cursor position, reposition cursor to the lower lines and display your text and then restore the cursor position. A very easy and simple way to instantly alert logged on users in certain groups. Can do all that in shell script easily. So knowing how things work and there capabilities and even there history and background so you understand why they are the way they are and from that appreciete there limitations. Then you can start doing some realy fun things. Again, nice read as verifys what you know and will fill in some worthy blanks.
Color can be a powerful way to organize large amounts of information quickly. What's the Plan 9 way to do that?
http://jstn.cc/post/8692501831
http://jstn.cc/post/13476503553
http://jstn.cc/post/10831555077
http://www.fastcodesign.com/1665509/digital-archaeology-hack...
I've done it with an ADM-3A from the 70s too, it's just. Not. That. Tough.
http://imgur.com/bRnST here's me, years back, hacking on a VT 220
There's lots of original documentation for DEC VT series terminals here[1].
Them's fightin' words, boy.
DEC had a DE9 serial port connector whose pinout is not the same as the later IBM PC DE9 serial ports.
Original vi has what is called 'open mode', which is effectively a one-line window intended for printing terminals. Neither nvi nor vim provide this, but line mode (ex) is more efficient anyway.