Re:UTF-8 – "The most elegant hack"
by nitrogen on Sunday September 29, 2013 @04:12AM
(#6464511)
You can think of it as two separate instructions, CR to move horizontally to the beginning of the line, and LF to move down by one line.
[ Parent
| on HN ]
You can think of it that way until you say, try to take the first n characters of a string and wind up with your string terminated with an orphaned CR without its accompanying LF.
Outside of ANSI terminals, teletypes and and dot matrix printers, they really don't work like that any more. If they did you'd be able to substitute LFCR for CRLF, or use multiple LFs with a single CR to leave multiline gaps - and multiple CRs would be redundant. Try sending a CSV file with LFCR line-endings, or HTTP headers separated by CRCRCRCRLF... see if that works everywhere reliably. Also, CRLF would be an acceptable substitute everywhere for UNIX LF line-endings, but clearly it's not. Fact is, CRLF is a two-byte magic number in a lot of places.
Not really because a single CR or LF does not do a real CR or LF.
It used to, back in The Day, when you had hard-copy consoles or even dot matrix printers. I think sending CR (but not LF) and then printing accents over top of the original line was a way of printing some European languages with just ASCII.
$ man terminfo | grep cursor_down | head -1
cursor_down cud1 do down one line
$ tput cud1 | hexdump -C | cut -f 1-20 | head -1
00000000 0a |.|
$ man terminfo | grep carriage_return | head -1
carriage_return cr cr carriage return (P*)
$ tput cr | hexdump -C | cut -f 1-20 | head -1
00000000 0d |.|
If you ever write a bash script that does more advanced things with the terminal, you'll get familiar with tput, termcap and terminfo pretty quickly.