This commit is contained in:
parent
b8b0fbb57e
commit
afc4092824
14 changed files with 153 additions and 48 deletions
14
Color.go
14
Color.go
|
@ -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...))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue