Added HSL and HSV colors
All checks were successful
/ test (push) Successful in 15s

This commit is contained in:
Eduard Urbach 2025-03-11 14:24:41 +01:00
parent b8b0fbb57e
commit afc4092824
Signed by: eduard
GPG key ID: 49226B848C78F6C8
14 changed files with 153 additions and 48 deletions

View file

@ -4,11 +4,11 @@ import (
"fmt"
)
// Color represents an RGB color.
// Color represents an sRGB color.
type Color struct {
R Value
G Value
B Value
R byte
G byte
B byte
}
// Print writes the text in the given color to standard output.
@ -18,7 +18,7 @@ func (c Color) Print(args ...any) {
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...))
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\x1b[0m", c.R, c.G, c.B, fmt.Sprint(args...))
}
// Printf formats according to a format specifier and writes the text in the given color to standard output.
@ -28,7 +28,7 @@ func (c Color) Printf(format string, args ...any) {
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...))
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\x1b[0m", c.R, c.G, c.B, fmt.Sprintf(format, args...))
}
// Println writes the text in the given color to standard output and appends a newline.
@ -38,5 +38,5 @@ func (c Color) Println(args ...any) {
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...))
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\n\x1b[0m", c.R, c.G, c.B, fmt.Sprint(args...))
}