Source File
background.go
Belonging Package
github.com/charmbracelet/x/ansi
package ansiimport ()// HexColor is a [color.Color] that can be formatted as a hex string.type HexColor string// RGBA returns the RGBA values of the color.func ( HexColor) () (, , , uint32) {:= .color()if == nil {return 0, 0, 0, 0}return .RGBA()}// Hex returns the hex representation of the color. If the color is invalid, it// returns an empty string.func ( HexColor) () string {:= .color()if == nil {return ""}return .Hex()}// String returns the color as a hex string. If the color is nil, an empty// string is returned.func ( HexColor) () string {return .Hex()}// color returns the underlying color of the HexColor.func ( HexColor) () *colorful.Color {, := colorful.Hex(string())if != nil {return nil}return &}// XRGBColor is a [color.Color] that can be formatted as an XParseColor// rgb: string.//// See: https://linux.die.net/man/3/xparsecolortype XRGBColor struct {color.Color}// RGBA returns the RGBA values of the color.func ( XRGBColor) () (, , , uint32) {if .Color == nil {return 0, 0, 0, 0}return .Color.RGBA()}// String returns the color as an XParseColor rgb: string. If the color is nil,// an empty string is returned.func ( XRGBColor) () string {if .Color == nil {return ""}, , , := .Color.RGBA()// Get the lower 8 bitsreturn fmt.Sprintf("rgb:%04x/%04x/%04x", , , )}// XRGBAColor is a [color.Color] that can be formatted as an XParseColor// rgba: string.//// See: https://linux.die.net/man/3/xparsecolortype XRGBAColor struct {color.Color}// RGBA returns the RGBA values of the color.func ( XRGBAColor) () (, , , uint32) {if .Color == nil {return 0, 0, 0, 0}return .Color.RGBA()}// String returns the color as an XParseColor rgba: string. If the color is nil,// an empty string is returned.func ( XRGBAColor) () string {if .Color == nil {return ""}, , , := .RGBA()// Get the lower 8 bitsreturn fmt.Sprintf("rgba:%04x/%04x/%04x/%04x", , , , )}// SetForegroundColor returns a sequence that sets the default terminal// foreground color.//// OSC 10 ; color ST// OSC 10 ; color BEL//// Where color is the encoded color number. Most terminals support hex,// XParseColor rgb: and rgba: strings. You could use [HexColor], [XRGBColor],// or [XRGBAColor] to format the color.//// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commandsfunc ( string) string {return "\x1b]10;" + + "\x07"}// RequestForegroundColor is a sequence that requests the current default// terminal foreground color.//// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commandsconst RequestForegroundColor = "\x1b]10;?\x07"// ResetForegroundColor is a sequence that resets the default terminal// foreground color.//// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commandsconst ResetForegroundColor = "\x1b]110\x07"// SetBackgroundColor returns a sequence that sets the default terminal// background color.//// OSC 11 ; color ST// OSC 11 ; color BEL//// Where color is the encoded color number. Most terminals support hex,// XParseColor rgb: and rgba: strings. You could use [HexColor], [XRGBColor],// or [XRGBAColor] to format the color.//// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commandsfunc ( string) string {return "\x1b]11;" + + "\x07"}// RequestBackgroundColor is a sequence that requests the current default// terminal background color.//// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commandsconst RequestBackgroundColor = "\x1b]11;?\x07"// ResetBackgroundColor is a sequence that resets the default terminal// background color.//// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commandsconst ResetBackgroundColor = "\x1b]111\x07"// SetCursorColor returns a sequence that sets the terminal cursor color.//// OSC 12 ; color ST// OSC 12 ; color BEL//// Where color is the encoded color number. Most terminals support hex,// XParseColor rgb: and rgba: strings. You could use [HexColor], [XRGBColor],// or [XRGBAColor] to format the color.//// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commandsfunc ( string) string {return "\x1b]12;" + + "\x07"}// RequestCursorColor is a sequence that requests the current terminal cursor// color.//// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commandsconst RequestCursorColor = "\x1b]12;?\x07"// ResetCursorColor is a sequence that resets the terminal cursor color.//// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commandsconst ResetCursorColor = "\x1b]112\x07"
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64)