Skip to main content
ansicode

OSC 12 — Set cursor colour (and query)

Override the terminal's cursor colour, or query the current value via the OSC reply.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b]12;#RRGGBB\x07 (set) \x1b]12;?\x07 (query)
\\033[\033]12;#RRGGBB\007
\\e[\e]12;#RRGGBB\a
ESC [ESC ] 12 ; COLOR BEL
hex1b 5d 31 32 3b ... 07

Description

OSC 12 sets the colour of the text cursor (the block / bar / underline drawn at the input position). The colour argument accepts the same syntaxes as OSC 10 / 11: `#RRGGBB`, `#RGB`, `rgb:RRRR/GGGG/BBBB`, or X11 colour names. Sending `?` instead of a colour (`\x1b]12;?\x07`) makes the terminal reply with the current cursor colour using the same syntax — used by themes and `:set background=...` autodetect tools to query the live palette. Reset the cursor colour back to the user's terminal default with OSC 112 (`\x1b]112\x07`). Distinct from cursor SHAPE (`\x1b[? q` — DECSCUSR) and cursor VISIBILITY (`\x1b[?25h/l`), which control glyph and on/off — OSC 12 only changes the colour.

Spec citation: xterm-ctlseqs (OSC 12 / 112)

Examples

bash
printf '\033]12;#f38ba8\007'   # set cursor to pink\nprintf '\033]12;?\007'         # query current cursor colour
python
import sys; sys.stdout.write('\x1b]12;#f38ba8\x07')
go
fmt.Print("\x1b]12;#f38ba8\x07")
javascript
process.stdout.write('\x1b]12;#f38ba8\x07')
c
printf("\x1b]12;#f38ba8\x07");

Terminal support

xterm
yes
Linux console (fbcon)
no
macOS Terminal.app
partial
iTerm2
yes
Windows Terminal
partial
cmd.exe / ConPTY
no
kitty
yes
alacritty
yes
WezTerm
yes
Ghostty
yes
GNOME Terminal
yes
Konsole
yes
tmux
no
GNU screen
no

Related sequences