Improved interface
This commit is contained in:
28
Color.go
28
Color.go
@ -21,31 +21,41 @@ func RGB(r Value, g Value, b Value) Color {
|
||||
}
|
||||
|
||||
// Fprint writes the text in the given color to the writer.
|
||||
func (c Color) Fprint(writer io.Writer, text string) {
|
||||
func (c Color) Fprint(writer io.Writer, args ...any) {
|
||||
if !Terminal {
|
||||
fmt.Fprint(writer, text)
|
||||
fmt.Fprint(writer, args...)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintf(writer, format, byte(c.R*255), byte(c.G*255), byte(c.B*255), text)
|
||||
fmt.Fprintf(writer, "\x1b[38;2;%d;%d;%dm%s\x1b[0m", byte(c.R*255), byte(c.G*255), byte(c.B*255), fmt.Sprint(args...))
|
||||
}
|
||||
|
||||
// Print writes the text in the given color to standard output.
|
||||
func (c Color) Print(text string) {
|
||||
func (c Color) Print(args ...any) {
|
||||
if !Terminal {
|
||||
fmt.Print(text)
|
||||
fmt.Print(args...)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf(format, byte(c.R*255), byte(c.G*255), byte(c.B*255), text)
|
||||
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...))
|
||||
}
|
||||
|
||||
// Print writes the text in the given color to standard output.
|
||||
func (c Color) Printf(format string, args ...any) {
|
||||
if !Terminal {
|
||||
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(text string) {
|
||||
func (c Color) Println(args ...any) {
|
||||
if !Terminal {
|
||||
fmt.Println(text)
|
||||
fmt.Println(args...)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf(formatLine, byte(c.R*255), byte(c.G*255), byte(c.B*255), text)
|
||||
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...))
|
||||
}
|
||||
|
Reference in New Issue
Block a user