CR Carriage Return
Move the cursor to the left margin of the current line.
CR
- ECMA-48
- §8.3.15 CR – Carriage Return, p. 35
- DEC STD 070
- §5.4.4 Carriage Return, p. 5-58
- VT510
- 4.2 Control Characters
Move the cursor to the left margin of the line it is on. With no left margin set that is the first column. Nothing is erased, which is how a progress bar redraws itself in place.
With left and right margins enabled (CSI ? 69 h), the cursor goes to the left margin if it is at or right of it. A cursor already left of the left margin goes to the first column instead.
A carriage return cancels any pending wrap, as DEC STD 070 asks (§D.6.1, p. D-14) and xterm’s CarriageReturn does: the next character is written at the start of this line, not the next one.
Validation
CR-1: Back to the start
ABC
\r
X
|XBC__|
cursor 1,2
CR-2: Cancels a pending wrap
ABCDE # fills the line; a wrap is pending
\r
X
|XBCDE|
|_____|
cursor 1,2
CR-3: To the left margin
\e[?69h # allow left and right margins
\e[3;5s # margins at columns 3 and 5
\e[1;4H
\r
X
|__X__|
CR-4: Left of the left margin
\e[?69h # allow left and right margins
\e[3;5s # margins at columns 3 and 5
\e[1;2H
\r
X
|X____|