^[control-codes
live in libghostty-vt

C0 control characters

CR Carriage Return

View as Markdown

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
VT220
§4.2 Control Characters
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.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984Yes§4.2 Control Characters
VT510manual, 1st ed., 1993YesTable 4–1
xtermpatch 412, xterm-411aYes
libghostty-vt0f171f6Yes
kitty0.49.1, run in a VMPartlyfails CR-3 of the 4 cases that show it working
foot1.28.0, run in a VMPartlyfails CR-3 of the 4 cases that show it working
pyte0.8.2, run as a libraryPartlyfails CR-3 of the 4 cases that show it working
xterm.js headless6.0.0, run as a libraryPartlyfails CR-3 of the 4 cases that show it working
alacritty_terminal0.26.0, run as a libraryPartlyfails CR-3 of the 4 cases that show it working
rxvt-unicode9.31, run in a VMPartlyfails CR-3 of the 4 cases that show it working
VTE0.84.1, run as a libraryYespasses the 4 cases that show it working

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____|
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.