6 ms·
Teaching an Almost 40-year Old Unix about Backspace
- Jaruzel 9y agoWhat this does is first send a BS to move the cursor back by one, then send a space to rub out the previous character on screen and then send another BS to get to the previous cursor position. Fortunately, my terminal lives in a world where doing this is instantaneous. So much knowledge has been forgotten. This is exactly what DEL did in it's original incarnation. on early VT terminals it was effectively a macro that triggered BS+SPACE+BS. Depending on the VT configuration you specified, hitting the Delete key (the one up there above your Enter key) would either send a basic BS(8), or DEL(127). This behaviour also existed in many early terminal apps for BBS type dial-up.
- digi_owl 9y ago> the Delete key (the one up there above your Enter key) I would have said "to the right of", but then i am one of those dinosaurs that still use a desktop computer with a full width keyboard.
- praseodym 9y agoThat’s a different button: I think OP means the button that many people call ‘Backspace’ (it is labelled ‘delete’ on Apple keyboards though).
- digi_owl 9y agoAs if Apple was not confusing enough already...
- xxpor 9y agoMy HHKB2 actually has it as a Delete key also. I had to flip a dip switch to change it to BS.
- digi_owl 9y agoAnd Japan can rival USA in being fanatic about Apple computers...
- thisacctforreal 9y agoOn the flip side; if you had babyduck'd to Apple instead, then Windows would be the odd one out of the modern operating systems. https://en.m.wikipedia.org/wiki/Baby_duck_syndrome https://en.m.wikipedia.org/wiki/Baby_duck_syndrome
- digi_owl 9y agoI can see why you qualified that with "modern" as going back just a bit, i am hard pressed to find any computer other than Apple that labeled that key with Delete. Amiga 500 use the left pointing arrow. Atari ST actually labeled it Backspace.
- Jaruzel 9y ago> hitting the Delete key (the one up there above your Enter key) Yup I meant the 'Backspace' key that looks like this: <--- Not the 'Delete' key that says 'Delete' and is clustered with End/Home/Insert etc. Interestingly, on Windows machines, The backspace key sends ASCII 8, but can send ASCII 127 if you press control+backspace.
- mrguyorama 9y agoThis article caught me off guard, because the last one seemed to come from a place of knowledge. I thought a lot of how backspace worked was something that every programmer whose ever written a terminal program has experienced at least once. We faced this during a 300 level System Programming class while implementing a simple shell. Is this not something everyone with a CS background experiences? I guess you could miss it if you never go lower than javascript, or never try to do same line reprinting ie for text based progress bars
- beefhash 9y agoI did know about \r moving the cursor back to redraw an entire line, but I never looked into ^H or other cursor manipulation characters for some reason. Progress bars just kind of never came up in the things I do (which is mostly daemons and text manipulation), so I haven't had to.
- dboreham 9y agoThe times they are a changin'
- mrguyorama 9y agoYou say that, but I'm very young, and didn't start writing code until after Windows Vista was released, let alone taking college classes. I guess I'm having a hard time understanding those who don't take an intrinsic interest into the lower level stuff in computers
- delecti 9y agoAll fields are abstractions on top of abstractions. Do you think every coder learns quantum physics? Certainly not, but it's vitally important for all modern computers. At some point everyone must decide either that they've cleared away enough abstractions for their purposes, or that their purpose is clearing away those abstractions.
- 9y ago
- snvzz 9y agoMaybe Netbsd will be taught next.
- int0x80 9y agowhich unix is he using and where is that src code? Is it (freely) available?
- beefhash 9y agoThis is UNIX V7, aka Seventh Edition UNIX, from 1979. The source code can be found on: 1. any distribution tape, V7 ships with its own code, 2. online, e.g. on http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src Ancient UNIX (Seventh Edition, including 32V, and prior) are permissively licensed under a BSD-style license[1]. I hope that helps. [1] http://www.tuhs.org/Archive/Caldera-license.pdf http://www.tuhs.org/Archive/Caldera-license.pdf
- int0x80 9y agoIt does, thank you very much!
- cat199 9y ago> Ancient UNIX (Seventh Edition, including 32V, and prior) are permissively licensed under a BSD-style license[1]. Ancient UNIX (Seventh Edition, including 32V, and prior) are NOW permissively licensed under a BSD-style license[1]... lest anyone learning about these things lose track of the Unix wars, UCB vs USL, and what really happened to Unix (aka it was forced to call itself BSD)
- geocar 9y agoUsing # as backspace and @ as kill has an advantage when dealing with a teletype.
- int0x80 9y agoOne thing that I don't rn see is why when I have: printf(">"); read(0, ...); I can only delete (DEL) chars that I've written, but not the ">". Who takes care of that, given that is not using readline? I guess it has to be the N_TTY line disc but I'm not sure how it works given that I can manually place the cursor where ever I want differently.
- jclulow 9y agoThe line discipline in most UNIX-like kernels is generally pretty simple, and mostly open-loop. In cooked mode, the kernel is just accumulating bytes in an edit buffer; if you add one, it echoes it; if you remove one, it probably emits "\b \b". If the buffer is empty and you press delete, it does nothing. If you were to send cursor positioning sequences, instead of just ">", this would probably fall apart as the kernel's edit buffer and the terminal reality would be out of sync.
- int0x80 9y agoThanks, it makes sense now. So with every `read' to the tty it starts a new edit buffer, I pressume?
- Tyr42 9y agoNo I don't think it's the "Read" call, but rather your program doesn't see any input in stdin until an enter is pressed. (In cooked mode).
- int0x80 9y agoI think I didn't explain myself. What you say is true, but even if your program doesn't see any input, you can (the kernel n_tty line discipline) edit the input (delete it). So if I do print() read() print() read() the reads will only be able to edit what has been input since that particular syscall.
- deleted 9y ago[deleted]
- aaroninsf 9y agoI still on increasingly rare occasion default in droll mode to statements like, I'm sure this marriage will cras^H^H^H^Hthrive I think the audience for such pun-level "humor" is down to single digits...
- adamrezich 9y agoBethesda had a subtle visual joke in this vein a few years back when their E3 announcement had a faux dir readout (https://i.redd.it/jm4nxvx92z2x.png https://i.redd.it/jm4nxvx92z2x.png). In it, they had the new DOOM game listed as "DOOM4^H", as it was previously announced as "DOOM 4" but then the project got scrapped and reannounced as just "DOOM." I found the throwaway gag pretty amusing personally, but none of my friends caught it.
- acheron 9y ago^H jokes probably have a larger audience than +++NO CARRIER jokes.
- mikestew 9y agoI think the audience for such pun-level "humor" is down to single digits... Oh, I think the audience size (IOW, those that get the joke) is fine, but I think the number that actually know the "why" of the punchline is pretty low. How old would one have to be to have ever run into a problem of BS/DEL not rendering properly on the receiving terminal? (At least my age, and I run in the "masters" category at local races.)
- aaroninsf 9y agoWell, old enough to also respond knowingly to the comment mentioning the Rush album 2112, anyway. :)
- aap_ 9y agoNow nice that he linked to my simh installation instructions :) The best way to use ancient UNIX is to tell your terminal emulator backspace is BS and delete is DEL, then just use stty (you don't have to use caret notation btw, a literal BS/^U/whatever works too). And of course if you use a "real" terminal like an ADM-3A (of vi fame) you don't even have a backspace key and have to actually press Ctrl-H.
- gumby 9y agoI was frustrated by the #@ back on Multics and am shocked when it bites me today (usually when globbing). But to this point: > There is some debate on whether BS or DEL is the correct character for terminals to send when the user presses the backspace key These ASCII codes come from teletypes and BS really did just back up a space (I.e. you could over strike) just as LF really did advance the platen one line while not changing the column. DEL really did indicate that the previous character was to be ignored, more useful on paper tapes than printout. Wow, I haven’t thought about paper tape in years...