package color import ( "fmt" ) // Color represents an RGB color. type Color struct { R Value G Value B Value } // Print writes the text in the given color to standard output. func (c Color) Print(args ...any) { if !Terminal || !TrueColor { fmt.Print(args...) return } fmt.Printf("\x1b[38;2;%d;%d;%dm%s\x1b[0m", byte(c.R*255), byte(c.G*255), byte(c.B*255), fmt.Sprint(args...)) } // Printf formats according to a format specifier and writes the text in the given color to standard output. func (c Color) Printf(format string, args ...any) { if !Terminal || !TrueColor { fmt.Printf(format, args...) return } fmt.Printf("\x1b[38;2;%d;%d;%dm%s\x1b[0m", byte(c.R*255), byte(c.G*255), byte(c.B*255), fmt.Sprintf(format, args...)) } // Println writes the text in the given color to standard output and appends a newline. func (c Color) Println(args ...any) { if !Terminal || !TrueColor { fmt.Println(args...) return } fmt.Printf("\x1b[38;2;%d;%d;%dm%s\n\x1b[0m", byte(c.R*255), byte(c.G*255), byte(c.B*255), fmt.Sprint(args...)) }