
Teaching an Almost 40-year Old Unix about Backspace - beefhash
https://virtuallyfun.com/2018/01/17/teaching_an_almost_40-year_old_unix_about_backspace/
======
Jaruzel
_What 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
> 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
That’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
As if Apple was not confusing enough already...

~~~
thisacctforreal
On 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
I 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.

------
mrguyorama
This 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

~~~
dboreham
The times they are a changin'

~~~
mrguyorama
You 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
All 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.

~~~
zokier
I'd point out the crucial detail that terminal handling arcana is not really
"low level" thing; from abstraction point of view it sits pretty much on the
same layer as DOM details or whatnot. You could know everything from low-level
kernel innards to latest front-end framework fluff and never encounter
terminal handling in any way. Text terminals are ultimately an evolutionary
dead end (or at least so it seems currently), almost all modern stuff diverges
from it instead of building on it.

------
int0x80
One 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
The 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
Thanks, it makes sense now. So with every `read' to the tty it starts a new
edit buffer, I pressume?

~~~
Tyr42
No 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
I 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.

------
aaroninsf
I 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...

~~~
acheron
^H jokes probably have a larger audience than +++NO CARRIER jokes.

~~~
dajt
+++ATH0

------
aap_
Now 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.

------
geocar
Using # as backspace and @ as kill has an advantage when dealing with a
teletype.

------
gumby
I 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...

------
snvzz
Maybe Netbsd will be taught next.

------
int0x80
which unix is he using and where is that src code? Is it (freely) available?

~~~
beefhash
This 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)

~~~
cat199
> 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)

