vendor/github.com/charmbracelet/x/ansi/background.go
61 lines · 1890 bytes
1package ansi
2
3import (
4 "image/color"
5)
6
7// SetForegroundColor returns a sequence that sets the default terminal
8// foreground color.
9//
10// OSC 10 ; color ST
11// OSC 10 ; color BEL
12//
13// Where color is the encoded color number.
14//
15// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
16func SetForegroundColor(c color.Color) string {
17 return "\x1b]10;" + colorToHexString(c) + "\x07"
18}
19
20// RequestForegroundColor is a sequence that requests the current default
21// terminal foreground color.
22//
23// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
24const RequestForegroundColor = "\x1b]10;?\x07"
25
26// SetBackgroundColor returns a sequence that sets the default terminal
27// background color.
28//
29// OSC 11 ; color ST
30// OSC 11 ; color BEL
31//
32// Where color is the encoded color number.
33//
34// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
35func SetBackgroundColor(c color.Color) string {
36 return "\x1b]11;" + colorToHexString(c) + "\x07"
37}
38
39// RequestBackgroundColor is a sequence that requests the current default
40// terminal background color.
41//
42// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
43const RequestBackgroundColor = "\x1b]11;?\x07"
44
45// SetCursorColor returns a sequence that sets the terminal cursor color.
46//
47// OSC 12 ; color ST
48// OSC 12 ; color BEL
49//
50// Where color is the encoded color number.
51//
52// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
53func SetCursorColor(c color.Color) string {
54 return "\x1b]12;" + colorToHexString(c) + "\x07"
55}
56
57// RequestCursorColor is a sequence that requests the current terminal cursor
58// color.
59//
60// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
61const RequestCursorColor = "\x1b]12;?\x07"