Added terminal detection
This commit is contained in:
11
Color.go
11
Color.go
@ -2,7 +2,6 @@ package color
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Value is a type definition for the data type of a single color component.
|
||||
@ -20,16 +19,6 @@ func RGB(r Value, g Value, b Value) Color {
|
||||
return Color{r, g, b}
|
||||
}
|
||||
|
||||
// Fprint writes the text in the given color to the writer.
|
||||
func (c Color) Fprint(writer io.Writer, args ...any) {
|
||||
if !Terminal {
|
||||
fmt.Fprint(writer, args...)
|
||||
return
|
||||
}
|
||||
|
||||
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(args ...any) {
|
||||
if !Terminal {
|
||||
|
Reference in New Issue
Block a user