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 {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package ansi_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/go/color"
|
||||
@ -19,15 +18,6 @@ func TestPrintRaw(t *testing.T) {
|
||||
}
|
||||
|
||||
func testColors() {
|
||||
ansi.Black.Fprint(os.Stdout, "Black\n")
|
||||
ansi.White.Fprint(os.Stdout, "White\n")
|
||||
ansi.Red.Fprint(os.Stdout, "Red\n")
|
||||
ansi.Green.Fprint(os.Stdout, "Green\n")
|
||||
ansi.Blue.Fprint(os.Stdout, "Blue\n")
|
||||
ansi.Yellow.Fprint(os.Stdout, "Yellow\n")
|
||||
ansi.Magenta.Fprint(os.Stdout, "Magenta\n")
|
||||
ansi.Cyan.Fprint(os.Stdout, "Cyan\n")
|
||||
|
||||
ansi.Black.Print("Black\n")
|
||||
ansi.White.Print("White\n")
|
||||
ansi.Red.Print("Red\n")
|
||||
|
Reference in New Issue
Block a user