Added terminal detection

This commit is contained in:
2024-03-12 00:25:20 +01:00
parent 393a9ebf17
commit 6a802c3ad8
12 changed files with 37 additions and 79 deletions

View File

@ -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 {