color.go
This file
Path
color.go
95 lines · 3.0 KiB · Go
Last changed by
docs: fix command and environment godoc examples (#1833)Hsnbefore adoption33f6a40
History of this fileTake it
Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 1–12why, one step back1package tea23import (4 "image/color"56 uv "github.com/charmbracelet/ultraviolet"7)89// backgroundColorMsg is a message that requests the terminal background color.10type backgroundColorMsg struct{}1112// RequestBackgroundColor is a command that requests the terminal background color.fix: skip capability queries when input is disabled (#1801)draw me an elephantbefore adoption8b10e22
line 13why, one step back13// Use [WithInput] to enable input, since the reply cannot be read otherwise.Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 14–21why, one step back14func RequestBackgroundColor() Msg {15 return backgroundColorMsg{}16}1718// foregroundColorMsg is a message that requests the terminal foreground color.19type foregroundColorMsg struct{}2021// RequestForegroundColor is a command that requests the terminal foreground color.fix: skip capability queries when input is disabled (#1801)draw me an elephantbefore adoption8b10e22
line 22why, one step back22// Use [WithInput] to enable input, since the reply cannot be read otherwise.Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 23–30why, one step back23func RequestForegroundColor() Msg {24 return foregroundColorMsg{}25}2627// cursorColorMsg is a message that requests the terminal cursor color.28type cursorColorMsg struct{}2930// RequestCursorColor is a command that requests the terminal cursor color.fix: skip capability queries when input is disabled (#1801)draw me an elephantbefore adoption8b10e22
line 31why, one step back31// Use [WithInput] to enable input, since the reply cannot be read otherwise.Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 32–54why, one step back32func RequestCursorColor() Msg {33 return cursorColorMsg{}34}3536// ForegroundColorMsg represents a foreground color message. This message is37// emitted when the program requests the terminal foreground color with the38// [RequestForegroundColor] Cmd.39type ForegroundColorMsg struct{ color.Color }4041// String returns the hex representation of the color.42func (e ForegroundColorMsg) String() string {43 return uv.ForegroundColorEvent(e).String()44}4546// IsDark returns whether the color is dark.47func (e ForegroundColorMsg) IsDark() bool {48 return uv.ForegroundColorEvent(e).IsDark()49}5051// BackgroundColorMsg represents a background color message. This message is52// emitted when the program requests the terminal background color with the53// [RequestBackgroundColor] Cmd.54//docs: fix command and environment godoc examples (#1833)Hsnbefore adoption33f6a40
line 55why, one step back55// This is commonly used in [Model.Init] to get the terminal background colorMerge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 56–59why, one step back56// for style definitions. For that you'll want to call57// [BackgroundColorMsg.IsDark] to determine if the color is dark or light. For58// example:59//docs: fix command and environment godoc examples (#1833)Hsnbefore adoption33f6a40
lines 60–61why, one step back60// func (m model) Init() Cmd {61// return RequestBackgroundColorMerge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 62–63why, one step back62// }63//docs: fix command and environment godoc examples (#1833)Hsnbefore adoption33f6a40
line 64why, one step back64// func (m model) Update(msg Msg) (Model, Cmd) {Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 65–68why, one step back65// switch msg := msg.(type) {66// case BackgroundColorMsg:67// m.styles = newStyles(msg.IsDark())68// }docs: fix command and environment godoc examples (#1833)Hsnbefore adoption33f6a40
line 69why, one step back69// return m, nilMerge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 70–95why, one step back70// }71type BackgroundColorMsg struct{ color.Color }7273// String returns the hex representation of the color.74func (e BackgroundColorMsg) String() string {75 return uv.BackgroundColorEvent(e).String()76}7778// IsDark returns whether the color is dark.79func (e BackgroundColorMsg) IsDark() bool {80 return uv.BackgroundColorEvent(e).IsDark()81}8283// CursorColorMsg represents a cursor color change message. This message is84// emitted when the program requests the terminal cursor color.85type CursorColorMsg struct{ color.Color }8687// String returns the hex representation of the color.88func (e CursorColorMsg) String() string {89 return uv.CursorColorEvent(e).String()90}9192// IsDark returns whether the color is dark.93func (e CursorColorMsg) IsDark() bool {94 return uv.CursorColorEvent(e).IsDark()95}