[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: write to same line on standard out?
- From: Doug Currie <doug.currie@...>
- Date: Wed, 14 Jul 2010 23:03:34 -0400
On Jul 14, 2010, at 10:38 PM, Luiz Henrique de Figueiredo wrote:
>> I just can't seem to find any reference to \r in PIL or the reference manual. I thought that it is a type of carriage return but I don't understand how it would keep from the screen from scrolling if it was
> \r is mentioned in http://www.lua.org/manual/5.1/manual.html#2.1 in the
> paragraph that starts "Literal strings..."
> The interpretation of \r after it is outpout is done by the terminal emulation
> program you are using and it's a standard interpretation that it moves the
> cursor to the beginning of the line.
Luiz is right, but I'd already traveled down memory lane, so here is some historical perspective...
Back in the days of real TTYs  there were two Baudot  control characters to position the paper(!). One was CR for Carriage Return; it moved the print head to the left side of the paper. The other was LF or Line Feed; it rolled the paper up one line but didn't do anything to the position of the print head. To go to the beginning of the next line, you had to send CR LF. HTTP still requires this two character sequence to terminate a line.
Sometime in the 60s people making glass TTYs  decided that CR LF was so common that to save transmission time (and typing) it should be possible to use just one control character for CR LF; some chose LF and called it newline ; C named it \n in strings. We won't speak of the others who made different choices. CR is named \r in C strings.
Wikipedia says "The first power carriage return was added to electric typewriters by Smith Corona in 1960. The key for this was usually labelled "carriage return" or "return".  Too bad it wasn't called "new line."