Added terminal detection
This commit is contained in:
11
ansi/Code.go
11
ansi/Code.go
@ -2,7 +2,6 @@ package ansi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"git.akyoto.dev/go/color"
|
||||
)
|
||||
@ -10,16 +9,6 @@ import (
|
||||
// Code represents an ANSI escape code.
|
||||
type Code int
|
||||
|
||||
// Fprint writes the text in the given color to the writer.
|
||||
func (code Code) Fprint(writer io.Writer, args ...any) {
|
||||
if !color.Terminal {
|
||||
fmt.Fprint(writer, args...)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintf(writer, "\x1b[%dm%s\x1b[0m", code, fmt.Sprint(args...))
|
||||
}
|
||||
|
||||
// Print writes the text in the given color to standard output.
|
||||
func (code Code) Print(args ...any) {
|
||||
if !color.Terminal {
|
||||
|
Reference in New Issue
Block a user